The API NvM_WriteBlock is used to persist user data into a Non volatile memory for use-cases which requires that data must be written immediately on request. EEPROM and (D)FLASH emulation are examples for non volatile memory.
For correct and consistent operation, The communication between application(SW-C) and NvM must follow a defined sequence of steps.
- Application gets the reference to a RAM block corresponding to a NVRAM block. Typically each block is organized as C structure. Rte provides a interface function to get a reference to this RAM block.
- Application update RAM variables as required and prevent any further update to this RAM block.
- Application issues NvM_WriteBlock using RTE interface corresponding block. This function returns E_OK when write request is placed to job queue, otherwise an error value is returned.
- Once write request is accepted, application must prevent any update to the RAM structure.
- It is the responsibility of application to poll the status of the write job using API NvM_GetErrorStatus. Notable status are NVM_REQ_PENDING ( means write in progress ), NVM_REQ_OK (write job completed successfully) and any other error reporting failure.
- The application must continue to poll the job status until the API NvM_GetErrorStatus returns NVM_REQ_OK or an error.
An example
Assume that there is a block named SpeedLimiter. It has two uint8 data fields 1. defaultLimit, maxLimit. Also assume that that SW-C runable is called cyclically. The pseudocode for state-machine based implementation available in my github repository here.