Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r48278ac6fa3738a97349ed7f3278773daf1d8004 -r8dfdaca983c36456b0e067a20ef6c003da3758ac --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 48278ac6fa3738a97349ed7f3278773daf1d8004) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 8dfdaca983c36456b0e067a20ef6c003da3758ac) @@ -277,7 +277,7 @@ filterDialInFlowReadings( dipFlow ); - // don't start enforcing checks until out of init/POST mode + // don't start enforcing checks until out of init/POST mode if ( getCurrentOperationMode() != MODE_INIT ) { checkDialInPumpDirection(); Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -r6788d3f0fe41ee36ac7e9d4bd8e0f407f9fc2c4b -r8dfdaca983c36456b0e067a20ef6c003da3758ac --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 6788d3f0fe41ee36ac7e9d4bd8e0f407f9fc2c4b) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 8dfdaca983c36456b0e067a20ef6c003da3758ac) @@ -145,8 +145,8 @@ static void publishDialOutFlowData( void ); -//static void checkDialOutPumpDirection( void ); -//static void checkDialOutPumpMCCurrent( void ); +static void checkDialOutPumpDirection( void ); +static void checkDialOutPumpMCCurrent( void ); static DATA_GET_PROTOTYPE( U32, getPublishDialOutDataInterval ); @@ -328,7 +328,12 @@ dialOutPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpRPM)) * DOP_SPEED_ADC_TO_RPM_FACTOR; dialOutPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpmA)) * DOP_CURRENT_ADC_TO_MA_FACTOR; - // TODO - checks + // don't start enforcing checks until out of init/POST mode + if ( getCurrentOperationMode() != MODE_INIT ) + { + checkDialOutPumpDirection(); + checkDialOutPumpMCCurrent(); + } publishDialOutFlowData(); } @@ -622,6 +627,86 @@ } /************************************************************************* + * @brief + * The checkDialOutPumpDirection function checks the set direction vs. \n + * the direction implied by the sign of the measured MC speed. + * @details + * Inputs : adcDialOutPumpMCSpeedRPM, dialOutPumpDirectionSet, dialOutPumpState + * Outputs : none + * @param none + * @return none + *************************************************************************/ +static void checkDialOutPumpDirection( void ) +{ + MOTOR_DIR_T dopMCDir; + + if ( DIAL_OUT_PUMP_CONTROL_TO_TARGET_STATE == dialOutPumpState ) + { + // check set direction vs. direction from sign of motor controller speed + dopMCDir = ( getMeasuredDialOutPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); + if ( dialOutPumpDirectionSet != dopMCDir ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DIAL_OUT_PUMP_MC_DIRECTION_CHECK, (U32)dialOutPumpDirectionSet, (U32)dopMCDir ) + } + } +} + +/************************************************************************* + * @brief + * The checkDialOutPumpMCCurrent function checks the measured MC current vs. \n + * the set state of the dialOut pump (stopped or running). + * @details + * Inputs : dialOutPumpState, dopCurrErrorDurationCtr, adcDialOutPumpMCCurrentmA + * Outputs : none + * @param none + * @return none + *************************************************************************/ +static void checkDialOutPumpMCCurrent( void ) +{ + F32 dopCurr; + + // dialIn pump should be off + if ( DIAL_OUT_PUMP_OFF_STATE == dialOutPumpState ) + { + dopCurr = fabs( getMeasuredDialOutPumpMCCurrent() ); + if ( dopCurr > DOP_MAX_CURR_WHEN_STOPPED_MA ) + { + dopCurrErrorDurationCtr += TASK_PRIORITY_INTERVAL; + if ( dopCurrErrorDurationCtr > DOP_MAX_CURR_ERROR_DURATION_MS ) + { +#ifndef DISABLE_MOTOR_CURRENT_ERRORS + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DIAL_OUT_PUMP_MC_CURRENT_CHECK, getMeasuredDialOutPumpMCCurrent() ); +#endif + } + } + else + { + dopCurrErrorDurationCtr = 0; + } + } + // dialOut pump should be running + else + { + dopCurr = fabs( getMeasuredDialOutPumpMCCurrent() ); + if ( ( dopCurr < DOP_MIN_CURR_WHEN_RUNNING_MA ) || ( dopCurr > DOP_MAX_CURR_WHEN_RUNNING_MA ) ) + { + dopCurrErrorDurationCtr += TASK_PRIORITY_INTERVAL; + if ( dopCurrErrorDurationCtr > DOP_MAX_CURR_ERROR_DURATION_MS ) + { +#ifndef DISABLE_MOTOR_CURRENT_ERRORS + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DIAL_OUT_PUMP_MC_CURRENT_CHECK, getMeasuredDialOutPumpMCCurrent() ); +#endif + } + } + else + { + dopCurrErrorDurationCtr = 0; + } + } +} + + +/************************************************************************* * GET SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r48278ac6fa3738a97349ed7f3278773daf1d8004 -r8dfdaca983c36456b0e067a20ef6c003da3758ac --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 48278ac6fa3738a97349ed7f3278773daf1d8004) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 8dfdaca983c36456b0e067a20ef6c003da3758ac) @@ -42,6 +42,8 @@ #define SCI1_RECEIVE_DMA_REQUEST 30 #define SCI1_TRANSMIT_DMA_REQUEST 31 +#define CAN_XMIT_PACKET_TIMEOUT_MS 200 ///< if transmitted CAN frame does not cause a transmit complete interrupt within this time, re-send or move on + #define UI_COMM_TIMEOUT_IN_MS 5000 #define DG_COMM_TIMEOUT_IN_MS 2000 @@ -90,6 +92,10 @@ COMM_BUFFER_IN_UART_PC }; +static U08 lastCANPacketSent[ CAN_MESSAGE_PAYLOAD_SIZE ]; +static CAN_MESSAGE_BOX_T lastCANPacketSentChannel = 0; +static U32 lastCANPacketSentTimeStamp = 0; + static U08 pcXmitPacket[ PC_MESSAGE_PACKET_SIZE ] = { 0, 0, 0, 0, 0, 0, 0, 0 }; static U08 pcRecvPacket[ PC_MESSAGE_PACKET_SIZE ] = { 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -311,6 +317,15 @@ { transmitNextCANPacket(); } + else + { // generally, transmitter should not be busy at time of this function call - check timeout just in case so we don't get stuck waiting forever + if ( TRUE == didTimeout( lastCANPacketSentTimeStamp, CAN_XMIT_PACKET_TIMEOUT_MS ) ) + { + // TODO - depending on why we timed out, we may need to reset CAN controller??? + // assume last packet was not successfully transmitted. TODO - Re-send last packet? Or should we move on? + canTransmit( canREG1, lastCANPacketSentChannel, lastCANPacketSent ); + } + } // if UART transmitter is idle, start transmitting any pending packets if ( FALSE == isSCI1DMATransmitInProgress() ) @@ -320,18 +335,18 @@ #ifdef CAN_TEST if ( dbgRcvdCANFrameIdx >= 2000 ) { - U32 i = dbgCANOutIdx; - char debugStr[ 150 ]; - - dbgCANOutIdx++; - if ( dbgCANOutIdx < 2000 ) - { - sprintf( debugStr, "%8d %4d %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X %8d %4d %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", - dbgRcvdCANFrameTS[i], dbgRcvdCANFrameCh[i], dbgRcvdCANFrames[i][0], dbgRcvdCANFrames[i][1], dbgRcvdCANFrames[i][2], dbgRcvdCANFrames[i][3], dbgRcvdCANFrames[i][4], dbgRcvdCANFrames[i][5], dbgRcvdCANFrames[i][6], dbgRcvdCANFrames[i][7], - dbgXmitCANFrameTS[i], dbgXmitCANFrameCh[i], dbgXmitCANFrames[i][0], dbgXmitCANFrames[i][1], dbgXmitCANFrames[i][2], dbgXmitCANFrames[i][3], dbgXmitCANFrames[i][4], dbgXmitCANFrames[i][5], dbgXmitCANFrames[i][6], dbgXmitCANFrames[i][7]); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); +// U32 i = dbgCANOutIdx; +// char debugStr[ 150 ]; +// +// dbgCANOutIdx++; +// if ( dbgCANOutIdx < 2000 ) +// { +// sprintf( debugStr, "%8d %4d %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X %8d %4d %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", +// dbgRcvdCANFrameTS[i], dbgRcvdCANFrameCh[i], dbgRcvdCANFrames[i][0], dbgRcvdCANFrames[i][1], dbgRcvdCANFrames[i][2], dbgRcvdCANFrames[i][3], dbgRcvdCANFrames[i][4], dbgRcvdCANFrames[i][5], dbgRcvdCANFrames[i][6], dbgRcvdCANFrames[i][7], +// dbgXmitCANFrameTS[i], dbgXmitCANFrameCh[i], dbgXmitCANFrames[i][0], dbgXmitCANFrames[i][1], dbgXmitCANFrames[i][2], dbgXmitCANFrames[i][3], dbgXmitCANFrames[i][4], dbgXmitCANFrames[i][5], dbgXmitCANFrames[i][6], dbgXmitCANFrames[i][7]); +// sendDebugData( (U08*)debugStr, strlen(debugStr) ); // printf(debugStr); - } +// } } #endif } @@ -355,6 +370,7 @@ { U32 bytesXmitted = transmitNextCANPacket(); + // if nothing more to send, signal that transmitter is available if ( 0 == bytesXmitted ) { signalCANXmitsCompleted(); @@ -622,19 +638,24 @@ // if there's another CAN packet to send, send it if ( dataSize == CAN_MESSAGE_PAYLOAD_SIZE ) { + // we're transmitting another packet - signal transmitter is busy signalCANXmitsInitiated(); + // remember packet data being transmitted here in case transmission fails and we need to re-send + memcpy( lastCANPacketSent, data, CAN_MESSAGE_PAYLOAD_SIZE ); + lastCANPacketSentChannel = mBox; + lastCANPacketSentTimeStamp = getMSTimerCount(); #ifdef CAN_TEST - if ( dbgXmitCANFrameIdx > 2000 ) - { - dataSize = 99; // Break point here - } - else - { - dbgXmitCANFrameTS[dbgXmitCANFrameIdx] = getMSTimerCount(); - dbgXmitCANFrameCh[dbgXmitCANFrameIdx] = mBox; - memcpy( &dbgXmitCANFrames[dbgXmitCANFrameIdx][0], data, 8); - dbgXmitCANFrameIdx++; - } +// if ( dbgXmitCANFrameIdx > 2000 ) +// { +// dataSize = 99; // Break point here +// } +// else +// { +// dbgXmitCANFrameTS[dbgXmitCANFrameIdx] = getMSTimerCount(); +// dbgXmitCANFrameCh[dbgXmitCANFrameIdx] = mBox; +// memcpy( &dbgXmitCANFrames[dbgXmitCANFrameIdx][0], data, 8); +// dbgXmitCANFrameIdx++; +// } #endif if ( 0 != canTransmit( canREG1, mBox, data ) ) { Fisheye: Tag 8dfdaca983c36456b0e067a20ef6c003da3758ac refers to a dead (removed) revision in file `firmware/App/Services/Timers.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 8dfdaca983c36456b0e067a20ef6c003da3758ac refers to a dead (removed) revision in file `firmware/App/Services/Timers.h'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 8dfdaca983c36456b0e067a20ef6c003da3758ac refers to a dead (removed) revision in file `firmware/App/Services/Utilities.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 8dfdaca983c36456b0e067a20ef6c003da3758ac refers to a dead (removed) revision in file `firmware/App/Services/Utilities.h'. Fisheye: No comparison available. Pass `N' to diff?