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 ) ) {