Index: firmware/.settings/org.eclipse.core.resources.prefs =================================================================== diff -u -r567a9736641b877ac0028db7481daad2dc65305f -re8511af1e4e9d91cfd3378471869fb0246110870 --- firmware/.settings/org.eclipse.core.resources.prefs (.../org.eclipse.core.resources.prefs) (revision 567a9736641b877ac0028db7481daad2dc65305f) +++ firmware/.settings/org.eclipse.core.resources.prefs (.../org.eclipse.core.resources.prefs) (revision e8511af1e4e9d91cfd3378471869fb0246110870) @@ -8,6 +8,7 @@ encoding//Debug/App/Tasks/subdir_rules.mk=UTF-8 encoding//Debug/App/Tasks/subdir_vars.mk=UTF-8 encoding//Debug/makefile=UTF-8 +encoding//Debug/objects.mk=UTF-8 encoding//Debug/source/subdir_rules.mk=UTF-8 encoding//Debug/source/subdir_vars.mk=UTF-8 encoding//Debug/sources.mk=UTF-8 Index: firmware/App/Services/CommBuffers.c =================================================================== diff -u -r9e2779d825ea7e7b3445fa365f7bc2206fc0613a -re8511af1e4e9d91cfd3378471869fb0246110870 --- firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 9e2779d825ea7e7b3445fa365f7bc2206fc0613a) +++ firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision e8511af1e4e9d91cfd3378471869fb0246110870) @@ -38,18 +38,18 @@ if ( mailBox < NUM_OF_SW_UPDATE_MBOXES ) { + _disable_IRQ(); U32 currentFrameCount = SWUpdateBuffer[ mailBox ].SWUpdateFrameCount; - if ( currentFrameCount <= MAX_NUM_OF_CAN_BYTES ) + if ( ( currentFrameCount * CAN_MESSAGE_PAYLOAD_SIZE ) <= MAX_NUM_OF_CAN_BYTES ) { - _disable_IRQ(); U32 currentBufferIndex = currentFrameCount * len; memcpy( SWUpdateBuffer[ mailBox ].SWUpdateBuffer + currentBufferIndex, data, len ); SWUpdateBuffer[ mailBox ].SWUpdateFrameCount += 1; status = TRUE; - _enable_IRQ(); } + _enable_IRQ(); } return status; @@ -84,10 +84,12 @@ void clearCommBuffer( SW_UPDATE_CAN_MAIL_BOX_T mailBox ) { + _disable_IRQ(); if ( mailBox < NUM_OF_SW_UPDATE_MBOXES ) { memset( &SWUpdateBuffer[ mailBox ], 0x0, sizeof( SW_UPDATE_BUFFER_T ) ); } + _enable_IRQ(); } Index: firmware/App/Services/Download.c =================================================================== diff -u -r567a9736641b877ac0028db7481daad2dc65305f -re8511af1e4e9d91cfd3378471869fb0246110870 --- firmware/App/Services/Download.c (.../Download.c) (revision 567a9736641b877ac0028db7481daad2dc65305f) +++ firmware/App/Services/Download.c (.../Download.c) (revision e8511af1e4e9d91cfd3378471869fb0246110870) @@ -49,10 +49,9 @@ static SW_UPDATE_RCV_STATUS_T SWUpdateRCVStatus; static SW_UPDATE_CMD_T SWUpdateCommandState; static SW_UPDATE_CAN_MAIL_BOX_T thisStackMailBox; +static U32 sizeToWrite; static U32 REMOVETHEVAR = 0; -static U08 REMOVETESTBUFFER[ 256 ]; -static U32 sizeToWrite; static void processIncomingCmdMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ); static void processIncomingUpdateMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ); @@ -71,6 +70,7 @@ void execDownload( void ) { + // TODO make this a state machine processIncomingCmdMessage( SW_UPDATE_COMMAD ); processIncomingUpdateMessage( thisStackMailBox ); } @@ -96,19 +96,26 @@ clearCommBuffer( thisStackMailBox ); } +U08 getTempRemoveMSGID() +{ + return SWUpdateRCVStatus.msgID; +} + // ********** private functions ********** static void processIncomingCmdMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ) { SW_UPDATE_CMD_STATUS_T SWUpdateCmdStatus; - S32 numOfBytes = getNumberOfBytesInBuffer( mailBox ); - BOOL status = getCommBuffer( mailBox, (U08*)&SWUpdateCmdStatus, sizeof( SW_UPDATE_CMD_STATUS_T ) ); + S32 bytesInBuffer = getNumberOfBytesInBuffer( mailBox ); - if ( ( TRUE == status ) && ( numOfBytes >= CAN_MESSAGE_PAYLOAD_SIZE ) ) + if ( bytesInBuffer == CAN_MESSAGE_PAYLOAD_SIZE ) { SW_UPDATE_RESP_STATUS_T resp; + getCommBuffer( mailBox, (U08*)&SWUpdateCmdStatus, sizeof( SW_UPDATE_CMD_STATUS_T ) ); + + BOOL status = FALSE; BOOL hasCRCPassed = FALSE; ACK_NACK_STATUS_T ackStatus = NACK; U32 calcCRC = 0; @@ -154,7 +161,7 @@ getCommBuffer( mailBox, (U08*)&SWUpdateRCVStatus, NUM_OF_CAN_BYTES_FOR_UPDATE ); - calcCRC = crc32( calcCRC, SWUpdateRCVStatus.SWUpdateBuffer, MAX_CRC_CALC_DATA_SIZE ); + calcCRC = crc32( calcCRC, SWUpdateRCVStatus.SWUpdateBuffer, MAX_CRC_CALC_DATA_SIZE ); // TODO fix the CRC length hasCRCPassed = ( SWUpdateRCVStatus.msgCRC == calcCRC ? TRUE : FALSE ); // TODO remove @@ -227,56 +234,60 @@ { ACK_NACK_STATUS_T ackStatus = NACK; - //if ( FPGA_UPDATE_READY == getFPGAFlashState() ) + if ( SWUpdateRCVStatus.cyberIndex != SW_UPDATE_FINAL_MSG_INDEX ) { - if ( SWUpdateRCVStatus.cyberIndex != SW_UPDATE_FINAL_MSG_INDEX ) - { - U16 removeThis; - U08 index = 0; - U32 counter; - U08 test[8]; - sizeToWrite = SW_UPDATE_FLASH_BUFFER_SIZE; - BOOL done = FALSE; + U16 removeThis; + U08 index = 0; + U32 counter; + U08 test[8]; + sizeToWrite = SW_UPDATE_FLASH_BUFFER_SIZE; + BOOL done = FALSE; - for ( removeThis = 0; removeThis < SW_UPDATE_FLASH_BUFFER_SIZE; ++removeThis ) + /*for ( removeThis = 0; removeThis < SW_UPDATE_FLASH_BUFFER_SIZE; ++removeThis ) + { + test[ index ] = SWUpdateRCVStatus.SWUpdateBuffer[removeThis]; + if ( index == 7 ) { - test[ index ] = SWUpdateRCVStatus.SWUpdateBuffer[removeThis]; - if ( index == 7 ) - { - canTransmit( canREG1, (U32)SW_TEST, test ); // Transmit the FPGA back up to make sure we totally received what we sent - for ( counter = 0; counter < 6000; counter++ ) {} - index = 0; - } - else - { - index += 1; - } - - // TODO this is temporary until the ROTTING is removed from the APP - // SWUpdateRCVStatus.SWUpdateBuffer[ removeThis ] = 0xFF & ( SWUpdateRCVStatus.SWUpdateBuffer[removeThis] - 27 ); + canTransmit( canREG1, (U32)SW_TEST, test ); // Transmit the FPGA back up to make sure we totally received what we sent + for ( counter = 0; counter < 6000; counter++ ) {} + index = 0; } - // 3192290 - // 1596144 - if ( ( 1596144 - REMOVETHEVAR < SW_UPDATE_FLASH_BUFFER_SIZE ) && ( REMOVETHEVAR != 0 ) ) - { - sizeToWrite = 1596144 - REMOVETHEVAR; - REMOVETHEVAR += sizeToWrite; - done = TRUE; - } else { - REMOVETHEVAR += SW_UPDATE_FLASH_BUFFER_SIZE; + index += 1; } - memcpy( REMOVETESTBUFFER, SWUpdateRCVStatus.SWUpdateBuffer, sizeToWrite); - signalFPGAToWriteToFlash( SWUpdateRCVStatus.SWUpdateBuffer, sizeToWrite ); - if ( TRUE == done ) - { - signalFPGAToSelfConfigure(); - } + // TODO this is temporary until the ROTTING is removed from the APP + // SWUpdateRCVStatus.SWUpdateBuffer[ removeThis ] = 0xFF & ( SWUpdateRCVStatus.SWUpdateBuffer[removeThis] - 27 ); + }*/ + // 3192290 + // 1596144 + if ( ( 1596144 - REMOVETHEVAR < SW_UPDATE_FLASH_BUFFER_SIZE ) && ( REMOVETHEVAR != 0 ) ) + { + sizeToWrite = 1596144 - REMOVETHEVAR; + REMOVETHEVAR += sizeToWrite; + done = TRUE; } + else + { + REMOVETHEVAR += SW_UPDATE_FLASH_BUFFER_SIZE; + } + + signalFPGAToWriteToFlash( SWUpdateRCVStatus.SWUpdateBuffer, sizeToWrite ); + + if ( TRUE == done ) + { + signalFPGAToSelfConfigure(); + } } + else + { + SW_UPDATE_RESP_STATUS_T resp; + prepareResponseMessage( SWUpdateRCVStatus.msgID, ACK, &resp ); + sendAckNackStatusFromFirmware( (U08*)&resp ); + } + return ackStatus; } Index: firmware/App/Services/Download.h =================================================================== diff -u -ra5cbf07811efee3c038a550f251d3daefff2bf63 -re8511af1e4e9d91cfd3378471869fb0246110870 --- firmware/App/Services/Download.h (.../Download.h) (revision a5cbf07811efee3c038a550f251d3daefff2bf63) +++ firmware/App/Services/Download.h (.../Download.h) (revision e8511af1e4e9d91cfd3378471869fb0246110870) @@ -20,4 +20,6 @@ void sendFPGAAckNackStatus( ACK_NACK_STATUS_T ackNackStatus ); +U08 getTempRemoveMSGID(); + #endif Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r567a9736641b877ac0028db7481daad2dc65305f -re8511af1e4e9d91cfd3378471869fb0246110870 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 567a9736641b877ac0028db7481daad2dc65305f) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision e8511af1e4e9d91cfd3378471869fb0246110870) @@ -14,6 +14,7 @@ #include "Download.h" #include "FPGA.h" #include "Timers.h" +#include "SystemComm.h" #include "Utilities.h" #define QUEUE_MAX_SIZE 20 ///< Max queue size. @@ -155,8 +156,8 @@ static U32 TESTREMOVE = 0; // TODO remove static U32 countRemove = 0; // TODO remove -static U32 nonzeroCounter = 0; // TODO remove -static U16 nonZeroCount[10000]; // TODO remove +static U16 tempFlashStatus; +static U08 tempACkStatus = 0; static const U08 STACK_FPGA_ID[ NUM_OF_FW_STACKS ] = { 0x5A, 0x61, 0xFF }; // TODO update with the real FPGA IDs static const U16 DISABLE_UPDATE_REG_CMD = 5; // TODO what is this value? 0? @@ -194,7 +195,7 @@ static void resetFPGACommFlags( void ); static void enqueue( FPGA_JOBS_T job ); static void dequeue( void ); -static U08 peekFromQueue( void ); +static FPGA_JOBS_T peekFromQueue( void ); static BOOL isQueueFull( void ); static FPGA_STATE_T handleFPGAIdleState( void ); @@ -216,14 +217,31 @@ enqueue( FPGA_READ_HEADER ); enqueue( FPGA_READ_UPDATE_REG ); - enqueue( FPGA_READ_MULTI_BOOT_STATUS ); fpgaState = FPGA_IDLE_STATE; fpgaUpdateRegisterStatus = 0; } void execFPGA( void ) { + if ( TRUE == fpgaFlashStatus.hasUpdateRegsBeenRqstd ) + { + processFPGAFlashRegistersRead(); + } + + // TODO test code remove + U08 data[8]; + data[0] = getTempRemoveMSGID(); + data[1] = (U08)fpgaState; + data[2] = GET_LSB_OF_WORD( fpgaFlashStatus.fifoRemainingCount ); + data[3] = GET_MSB_OF_WORD( fpgaFlashStatus.fifoRemainingCount ); + data[4] = GET_LSB_OF_WORD( tempFlashStatus ); + data[5] = GET_MSB_OF_WORD( tempFlashStatus ); + data[6] = tempACkStatus; + data[7] = 0; + broadcastDataTestRemove(data); + // TODO test code remove + switch( fpgaState ) { case FPGA_IDLE_STATE: @@ -262,11 +280,6 @@ else if ( FPGA_COMM_READ_IN_PROGRESS == fpgaJobsQStatus.fpgaCommRead ) { fpgaJobsQStatus.fpgaCommRead = FPGA_COMM_READ_RESP_RECEIVED; - - if ( TRUE == fpgaFlashStatus.hasUpdateRegsBeenRqstd ) - { - processFPGAFlashRegistersRead(); - } } } @@ -312,11 +325,11 @@ { memset( fpgaDataToWriteBuffer, 0x0, SW_UPDATE_FLASH_BUFFER_SIZE ); - enqueue( FPGA_FLASH_WRITE_DATA ); - fpgaDataLenToWrite = len; memcpy( fpgaDataToWriteBuffer, data, len ); + enqueue( FPGA_FLASH_WRITE_DATA ); + fpgaFlashStatus.fpgaFlashState = FPGA_UPDATE_BUSY; } } @@ -473,6 +486,8 @@ U16 fifoStatus = MAKE_WORD_OF_BYTES( fpgaReadResponseBuffer[ FPGA_FLASH_STATUS_INDEX + sizeof( U16 ) ], fpgaReadResponseBuffer[ FPGA_FLASH_STATUS_INDEX + sizeof( U16 ) - 1 ] ); + tempFlashStatus = flashStatus; // TODO remove + fpgaFlashStatus.fpgaFlashState = FPGA_UPDATE_NOT_READY; fpgaFlashStatus.fifoRemainingCount = FPGA_FIFO_SIZE_BYTES - ( FPGA_FIFO_COUNT_MASK & fifoStatus ); fpgaFlashStatus.hasUpdateRegsBeenRqstd = FALSE; @@ -496,15 +511,14 @@ fpgaFlashStatus.fpgaFlashState = FPGA_UPDATE_FIFO_FULL; } - nonZeroCount[nonzeroCounter] = fpgaFlashStatus.fifoRemainingCount; - nonzeroCounter = INC_WRAP( nonzeroCounter, 0, 10000 - 1 ); - // TODO remove + /* if ( fpgaFlashStatus.fifoRemainingCount < FPGA_FIFO_SIZE_BYTES ) { BOOL dara = FALSE; } // TODO remove + */ } } } @@ -646,14 +660,14 @@ _enable_IRQ(); } -static U08 peekFromQueue( void ) +static FPGA_JOBS_T peekFromQueue( void ) { _disable_IRQ(); - U08 frontIndex = fpgaJobsQStatus.fpgaJobFrontIndex; - U08 frontIndexUpdate = INC_WRAP( frontIndex, 0, QUEUE_MAX_SIZE - 1 ); + U08 frontIndex = fpgaJobsQStatus.fpgaJobFrontIndex; + FPGA_JOBS_T nextJob = (FPGA_JOBS_T)fpgaJobsQStatus.fpgaJobsQueue[ frontIndex ]; _enable_IRQ(); - return frontIndexUpdate; + return nextJob; } static BOOL isQueueFull( void ) @@ -672,8 +686,6 @@ { FPGA_STATE_T state = FPGA_IDLE_STATE; - requestFlashRegistersStatus(); - if ( fpgaJobsQStatus.fpgaJobsQueueCount > 0 ) { BOOL isDequeueAllowed = TRUE; @@ -691,13 +703,10 @@ } } - // TODo remove - if ( ( FPGA_FLASH_WRITE_DATA == fpgaJobsQStatus.fpgaCurrentJob ) && ( fpgaFlashStatus.fifoRemainingCount < SW_UPDATE_FLASH_BUFFER_SIZE ) ) - { - nonZeroCount[ nonzeroCounter ] = fpgaFlashStatus.fifoRemainingCount; - nonzeroCounter++; - } + requestFlashRegistersStatus(); + // TODo remove + tempACkStatus = NACK; if ( FPGA_SELF_CONFIGURE == fpgaJobsQStatus.fpgaCurrentJob ) { BOOL test = FALSE; @@ -775,6 +784,7 @@ { fpgaFlashStatus.fpgaFlashState = FPGA_UPDATE_READY; sendFPGAAckNackStatus( ACK ); + tempACkStatus = ACK; TESTREMOVE += fpgaDataLenToWrite;// TODO REMOVE countRemove += 1;// TODO REMOVE Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r9e2779d825ea7e7b3445fa365f7bc2206fc0613a -re8511af1e4e9d91cfd3378471869fb0246110870 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 9e2779d825ea7e7b3445fa365f7bc2206fc0613a) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision e8511af1e4e9d91cfd3378471869fb0246110870) @@ -64,3 +64,10 @@ return status; } +BOOL broadcastDataTestRemove( U08* data ) +{ + canTransmit( canREG1, (U32)SW_TEST, data ); + + return TRUE; +} + Index: firmware/App/Services/SystemComm.h =================================================================== diff -u -r9e2779d825ea7e7b3445fa365f7bc2206fc0613a -re8511af1e4e9d91cfd3378471869fb0246110870 --- firmware/App/Services/SystemComm.h (.../SystemComm.h) (revision 9e2779d825ea7e7b3445fa365f7bc2206fc0613a) +++ firmware/App/Services/SystemComm.h (.../SystemComm.h) (revision e8511af1e4e9d91cfd3378471869fb0246110870) @@ -16,4 +16,6 @@ BOOL sendAckNackStatusFromFirmware( U08* data ); +BOOL broadcastDataTestRemove( U08* data ); + #endif