Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r36a2fa774e2f5721c30261a40360d706bb4ea4bb -r4d27576bdd7843178d9b69ffff3584ee01ec24fe --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 36a2fa774e2f5721c30261a40360d706bb4ea4bb) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 4d27576bdd7843178d9b69ffff3584ee01ec24fe) @@ -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 HD_COMM_TIMEOUT_IN_MS 2000 #define MAX_COMM_CRC_FAILURES 5 @@ -87,6 +89,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 }; @@ -105,6 +111,15 @@ static U32 badCRCListIdx = 0; // where next bad message CRC time stamp will go in list static U32 badCRCListCount = 0; // # of bad CRCs in the list +#ifdef CAN_TEST +U08 dbgRcvdCANFrames[1024][8]; +U32 dbgRcvdCANFrameTS[1024]; +U32 dbgRcvdCANFrameIdx = 0; +U08 dbgXmitCANFrames[1024][8]; +U32 dbgXmitCANFrameTS[1024]; +U32 dbgXmitCANFrameIdx = 0; +#endif + // ********** private function prototypes ********** static void initUARTAndDMA( void ); @@ -222,6 +237,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() ) @@ -266,6 +290,18 @@ // if packet retrieved, add to buffer if ( result != 0 ) { +#ifdef CAN_TEST + if ( dbgRcvdCANFrameIdx >= 1000 ) + { + result = 99; // Break point here + } + else + { + dbgRcvdCANFrameTS[dbgRcvdCANFrameIdx] = getMSTimerCount(); + memcpy( &dbgRcvdCANFrames[dbgRcvdCANFrameIdx][0], data, 8); + dbgRcvdCANFrameIdx++; + } +#endif //#ifdef DEBUG_ENABLED // if ( srcCANBox == COMM_BUFFER_IN_CAN_PC ) // { @@ -503,7 +539,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 > 1000 ) + { + dataSize = 99; // Break point here + } + else + { + dbgXmitCANFrameTS[dbgXmitCANFrameIdx] = getMSTimerCount(); + memcpy( &dbgXmitCANFrames[dbgXmitCANFrameIdx][0], data, 8); + dbgXmitCANFrameIdx++; + } +#endif if ( 0 != canTransmit( canREG1, mBox, data ) ) { result = CAN_MESSAGE_PAYLOAD_SIZE;