Index: firmware/App/Drivers/NVDriver.c =================================================================== diff -u -rf525d2be1e7038cacbe2bb34b8db3505cf26a350 -r63c3a65e681810f037718377c6ed5a28c897d0ca --- firmware/App/Drivers/NVDriver.c (.../NVDriver.c) (revision f525d2be1e7038cacbe2bb34b8db3505cf26a350) +++ firmware/App/Drivers/NVDriver.c (.../NVDriver.c) (revision 63c3a65e681810f037718377c6ed5a28c897d0ca) @@ -25,12 +25,22 @@ // ********** private definitions ********** // The clock frequency comes from HCLK_FREQ and it has to be rounded up to the nearest number -#define ROUNDED_HCLK_FREQ FLOAT_TO_INT_WITH_ROUND(HCLK_FREQ) ///< Rounded HCLK for EERPOM clock. -#define BANK7_SECTOR_0_31_ENABLE_BIT_MASK 0x0000000F ///< Bank7 sector 0 t0 31 enable mask. -#define BANK7_SECTOR_32_63_ENABLE_BIT_MASK 0x00000000 ///< Bank7 sector 32 to 63 enable mask. +#define ROUNDED_HCLK_FREQ FLOAT_TO_INT_WITH_ROUND(HCLK_FREQ) ///< Rounded HCLK for EERPOM clock. +#define BANK7_SECTOR_0_31_ENABLE_BIT_MASK 0x0000000F ///< Bank7 sector 0 t0 31 enable mask. +#define BANK7_SECTOR_32_63_ENABLE_BIT_MASK 0x00000000 ///< Bank7 sector 32 to 63 enable mask. -static BOOL getSectorStartAddress( U32* recordFlashAddress ); +// ********** private function prototypes ********** +static BOOL isSectorStartAddress( U32* recordFlashAddress ); + +/*********************************************************************//** + * @brief + * The initNVDriver function initializes the Non Volatile Memory Driver module. + * It configures and enables flash bank 7 and its EEPROM sectors. + * @details \b Inputs: none + * @details \b Outputs: none + * @return none + *************************************************************************/ void initNVDriver( void ) { // Initialize and activate flash bank 7 @@ -39,46 +49,97 @@ Fapi_enableEepromBankSectors( BANK7_SECTOR_0_31_ENABLE_BIT_MASK, BANK7_SECTOR_32_63_ENABLE_BIT_MASK ); } +/*********************************************************************//** + * @brief + * The eraseSector function erases a flash sector at the specified address. + * It validates the address and issues an erase command if valid. + * @details \b Inputs: none + * @details \b Outputs: none + * @param recordFlashAddress Flash address of the sector to erase + * @return none + *************************************************************************/ void eraseSector( U32* recordFlashAddress ) { - BOOL isFlashAddressValid = getSectorStartAddress( recordFlashAddress ); + BOOL isFlashAddressValid = isSectorStartAddress( recordFlashAddress ); if ( TRUE == isFlashAddressValid) { Fapi_issueAsyncCommandWithAddress( Fapi_EraseSector, recordFlashAddress ); } } +/*********************************************************************//** + * @brief + * The writeSector function programs data to a flash sector at the specified address. + * It validates the address and buffer before issuing the programming command. + * @details \b Inputs: none + * @details \b Outputs: none + * @param recordFlashAddress Flash address where data will be written + * @param bufferAddress Pointer to the data buffer to be written + * @param bufferSize Size of the buffer to be written + * @return none + *************************************************************************/ void writeSector( U32* recordFlashAddress, U08* bufferAddress, U32 bufferSize ) { // Create a copy only for validation U32 sectorStartAddress = *recordFlashAddress; - BOOL isFlashAddressValid = getSectorStartAddress( §orStartAddress ); + BOOL isFlashAddressValid = isSectorStartAddress( §orStartAddress ); if ( ( TRUE == isFlashAddressValid ) && ( NULL != bufferAddress ) && ( bufferSize > 0 ) ) { Fapi_issueProgrammingCommand( recordFlashAddress, bufferAddress, bufferSize, 0x00, 0, Fapi_DataOnly ); } } +/*********************************************************************//** + * @brief + * The readSector function reads data from a flash sector at the specified address. + * It validates the address and buffer before performing the read operation. + * @details \b Inputs: none + * @details \b Outputs: none + * @param recordFlashAddress Flash address to read from + * @param bufferAddress Pointer to the buffer where data will be stored + * @param bufferSize Size of the data to be read + * @return none + *************************************************************************/ void readSector( U32* recordFlashAddress, U32* bufferAddress, U32 bufferSize ) { // Create a copy only for validation U32 sectorStartAddress = *recordFlashAddress; - BOOL isFlashAddressValid = getSectorStartAddress( §orStartAddress ); + BOOL isFlashAddressValid = isSectorStartAddress( §orStartAddress ); if ( ( TRUE == isFlashAddressValid ) && ( NULL != bufferAddress ) && ( bufferSize > 0 ) ) { Fapi_doMarginRead( recordFlashAddress, bufferAddress, bufferSize, Fapi_NormalRead ); } } +/*********************************************************************//** + * @brief + * The isFlashReady function checks whether the flash FSM is ready. + * It returns the readiness status of the flash state machine. + * @details \b Inputs: none + * @details \b Outputs: none + * @return value indicating flash ready status (TRUE if ready, FALSE otherwise) + *************************************************************************/ BOOL isFlashReady( void ) { - return (Fapi_Status_FsmReady == FAPI_CHECK_FSM_READY_BUSY); + return ( Fapi_Status_FsmReady == FAPI_CHECK_FSM_READY_BUSY ); } -static BOOL getSectorStartAddress( U32* recordFlashAddress ) +/*********************************************************************//** + * @brief + * The isSectorStartAddress function validates and aligns a flash address + * to a sector start. It checks if the address falls within defined + * sectors and updates it accordingly. + * @details \b Inputs: none + * @details \b Outputs: none + * @param recordFlashAddress Pointer to the flash address to validate + * and update + * @return isFlashAddressValid indicating address validity (TRUE if valid, FALSE + * otherwise) + *************************************************************************/ +static BOOL isSectorStartAddress( U32* recordFlashAddress ) { BOOL isFlashAddressValid = TRUE; @@ -115,6 +176,5 @@ return isFlashAddressValid; } - /**@}*/