Vybhav Kadaba
/
EV-PRO-MW1001_dec12
MWARE-1930 fixed
Diff: src/admw_1001.c
- Revision:
- 13:97cb32670539
- Parent:
- 10:14954555be2a
- Child:
- 14:266ab283b086
--- a/src/admw_1001.c Wed Jul 24 08:51:31 2019 +0000 +++ b/src/admw_1001.c Thu Jul 25 06:38:45 2019 +0000 @@ -54,8 +54,8 @@ #include "admw1001/admw1001_host_comms.h" #include "crc16.h" -#define VERSIONID_MAJOR 1 -#define VERSIONID_MINOR 4 +#define VERSIONID_MAJOR 2 +#define VERSIONID_MINOR 0 uint32_t getDataCnt = 0; @@ -2697,3 +2697,149 @@ return ADMW_SUCCESS; } +ADMW_RESULT admw1001_getFirmwareStatus( + ADMW_DEVICE_HANDLE const hDevice, + bool * const bFirmwareStatus) +{ + bool bitCommand; + ADMW_RESULT eRet; + uint8_t pinreg = 0x1; + + ADMW_DEVICE_CONTEXT *pCtx = hDevice; + static uint8_t DataBuffer[SPI_BUFFER_SIZE] = {0}; + uint16_t nSize; + + //Construct Read Status command + DataBuffer[0] = 0x07; + DataBuffer[1] = 0x0E; //Packet ID + + DataBuffer[2] = 0x00; + DataBuffer[3] = 0x00; //Data words + + DataBuffer[4] = 0x53; + DataBuffer[5] = 0x00; //Command ID + + DataBuffer[6] = 0x00; + DataBuffer[7] = 0x00; + DataBuffer[8] = 0x00; + DataBuffer[9] = 0x00; //Address + + DataBuffer[10] = 0x53; + DataBuffer[11] = 0x00; + DataBuffer[12] = 0x00; + DataBuffer[13] = 0x00; //Checksum + + nSize = SFL_READ_STATUS_HDR_SIZE; + + do + { + // Get the SFL command irq pin to check if SFL is ready to receive commands + // Status pin is not checked since SFL is just booted, there should not be any issue with SFL + eRet = admw_GetGpioState( hDevice, ADMW_GPIO_PIN_DATAREADY, &bitCommand ); + if( eRet != ADMW_SUCCESS) { + return eRet; + } + + // Command IRQ pin should be low and Status IRQ pin should be high for SFL to be in good state and ready to recieve commands + // pinreg == '0x00' - Error occured in SFL + // pinreg == '0x01' - SFL is ready to recieve commands + // pinreg == '0x02' - Error occured in handling any commands in SFL + // pinreg == '0x03' - SFL not booted + + pinreg = (bitCommand); + + }while(pinreg != 0x0u); + + eRet = admw_SpiTransfer(pCtx->hSpi, DataBuffer, NULL, + nSize, false); + if (eRet) + { + return eRet; + } + + //wait for command irq line to go low after sending read status header + wait_ms( 100 ); + + do + { + // Get the SFL command irq pin to check if SFL is ready to receive commands + // Status pin is not checked since SFL is just booted, there should not be any issue with SFL + eRet = admw_GetGpioState( hDevice, ADMW_GPIO_PIN_DATAREADY, &bitCommand ); + if( eRet != ADMW_SUCCESS) { + return eRet; + } + + // Command IRQ pin should be low and Status IRQ pin should be high for SFL to be in good state and ready to recieve commands + // pinreg == '0x00' - Error occured in SFL + // pinreg == '0x01' - SFL is ready to recieve commands + // pinreg == '0x02' - Error occured in handling any commands in SFL + // pinreg == '0x03' - SFL not booted + + pinreg = (bitCommand); + + }while(pinreg != 0x0u); + + nSize = SFL_READ_STATUS_RESPONSE_SIZE; + + eRet = admw_SpiReceive(pCtx->hSpi, NULL, DataBuffer, + nSize, false); + + if (eRet) + { + return eRet; + } + + //Verifying the application version from the response to check if firmware is present or not + /* + Flash Memory description + ______________ + | Secure | 0x0000 0000 + | Flashloader | + |______________| 0x0000 3BFF + | Security |------------------ + | Page | 0x0000 3C00 + | | + |______________| 0x0000 3FFF + | |------------------ + | App Info | 0x0000 4000 + | Page | + |______________| 0x0000 4800 + | |------------------ + | Application | + | Image | Application resides only in this region + |______________|------------------ + | Reserved | 0x0003 FFF8 + | for | Reserved memory region + | Signature | 0x0003 FFFF + |______________|------------------ + + Application version is stored in the App Info Page, the app version is updated in this region everytime the new application firmware is downloaded. + Here we verify if Application version is present in the Read Status response + If the app version bytes value is 0xFFFFFFFF then there is no firmware else there exist a firmware + + Read Status Response: + ____________________________________________________________________________________________________________________________________ + | | | | | | + |uint16_t nFlashLoaderVersion | uint16_t nStatus | uint32_t nApplicationVersion | uint32_t nApplicationHash[8] | uint16_t nChecksum | + |_____________________________|__________________|______________________________|______________________________|_____________________| + + */ + + if( ((DataBuffer[4] == 0xFF) && + (DataBuffer[5] == 0xFF) && + (DataBuffer[6] == 0xFF) && + (DataBuffer[7] == 0xFF)) || + ((DataBuffer[4] == 0x00) && + (DataBuffer[5] == 0x00) && + (DataBuffer[6] == 0x00) && + (DataBuffer[7] == 0x00))) + { + *bFirmwareStatus = false; + } + else + { + *bFirmwareStatus = true; + } + + return eRet; +}