Index: firmware/App/Services/Download.c =================================================================== diff -u -r292265111b911fa79c52bb4589911dfb60c921bf -rfc9a9244cf4288ff0623c3e02455ac565bf60cdd --- firmware/App/Services/Download.c (.../Download.c) (revision 292265111b911fa79c52bb4589911dfb60c921bf) +++ firmware/App/Services/Download.c (.../Download.c) (revision fc9a9244cf4288ff0623c3e02455ac565bf60cdd) @@ -19,10 +19,10 @@ // ********** private definitions ********** -#define SW_UPDATE_FINAL_MSG_INDEX 0xFFFF ///< Software update final message index. +#define SW_UPDATE_FINAL_MSG_INDEX 0xFFFF // TODO remove ///< Software update final message index. #define SHIFT_BITS_TO_GET_TARGET 4 ///< Shift bits by 4 to get the update target. -static const U32 NUM_OF_CAN_BYTES_FOR_UPDATE = SW_UPDATE_FLASH_BUFFER_SIZE + CAN_MESSAGE_PAYLOAD_SIZE; ///< Number of CAN bytes for update. +static const U32 NUM_OF_CAN_BYTES_FOR_UPDATE = SW_UPDATE_FLASH_BUFFER_SIZE + CAN_MESSAGE_FRAME_SIZE; ///< Number of CAN bytes for update. // ********** private data ********** @@ -171,10 +171,7 @@ *************************************************************************/ static void handleIncomingCmdMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ) { - // Peek into the number of bytes received for the command buffer - S32 bytesInBuffer = getNumberOfBytesInBuffer( mailBox ); - - if ( bytesInBuffer == CAN_MESSAGE_PAYLOAD_SIZE ) + if ( TRUE == isMessageComplete( mailBox ) ) { // If the command buffer has been received, get it from the comm buffer and process it SW_UPDATE_CMD_STATUS_T SWUpdateCmdStatus; @@ -221,32 +218,32 @@ *************************************************************************/ static void handleIncomingUpdateMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ) { - // Peek into the comm buffer to see if the entire data has been received - S32 bytesInBuffer = getNumberOfBytesInBuffer( mailBox ); - - if ( ( bytesInBuffer == NUM_OF_CAN_BYTES_FOR_UPDATE ) && ( MODE_UPDATE == getCurrentOpMode() ) ) + if ( ( TRUE == isMessageComplete( mailBox ) ) && ( MODE_UPDATE == getCurrentOpMode() ) ) { U08 bufferWithNoCRC[ SW_UPDATE_FLASH_BUFFER_SIZE + sizeof( U32 ) ]; U32 calcCRC = 0; BOOL hasCRCPassed = FALSE; ACK_NACK_STATUS_T ackStatus = NACK; U08 msgID = 0; + U16 payloadLength = 0; getCommBuffer( mailBox, (U08*)&SWUpdateRCVStatus, NUM_OF_CAN_BYTES_FOR_UPDATE ); + payloadLength = SWUpdateRCVStatus.updatePayloadLen; + // Create a local buffer and copy the header into the buffer excluding the CRC so only 4 bytes of ID, Destination, and payload length memcpy( bufferWithNoCRC, (U08*)&SWUpdateRCVStatus, sizeof( U32 ) ); // Copy the entire update buffer that is going either to firmware or FPGA into the local buffer. - memcpy( &bufferWithNoCRC[ sizeof( U32 ) ], SWUpdateRCVStatus.SWUpdateBuffer, sizeof( SWUpdateRCVStatus.SWUpdateBuffer ) ); + memcpy( &bufferWithNoCRC[ sizeof( U32 ) ], SWUpdateRCVStatus.SWUpdateBuffer, payloadLength ); // Calculate the CRC of the local copied buffer and compare it against the message CRC - calcCRC = crc32( calcCRC, bufferWithNoCRC, sizeof( bufferWithNoCRC ) ); + calcCRC = crc32( calcCRC, bufferWithNoCRC, sizeof( U32 ) + payloadLength ); hasCRCPassed = ( SWUpdateRCVStatus.msgCRC == calcCRC ? TRUE : FALSE ); msgID = SWUpdateRCVStatus.msgID; if ( FALSE == hasCRCPassed ) { - BOOL test = TRUE; + BOOL test = TRUE; // TODO remove } @@ -270,8 +267,8 @@ } prepareAndSendFWResponseMessage( msgID, ackStatus ); - clearCommBuffer( mailBox ); // TODo does this need to be here? How about resync? - clearSWUpdateBuffer(); // TODO uncomment + clearCommBuffer( mailBox ); + clearSWUpdateBuffer(); } }