As number of write cycles to embedded non volatile memory is limited and write operation to non volatile memory needs more run time, it is necessary to reduce the number write operations by deferring the write into non-volatile memory to the later point.
In a typical ECU application, several modules/use-cases does not require immediate write to NVRAM. For these modules the write operation could be delayed until shutdown phase.
Concept of operation
In a nutshell,
- At ECU startup NVRAM block content is loaded to RAM block.
- During up phase (normal operation), application will access(read/write) the RAM block.
- At shutdown phase the content of RAM block is transferred to NVRAM block.
Application (SW-C) developer perspective
All necessary configurations and RTE interfaces shall made available by basis software configuration.
When application is required to store “user data” to NVRAM, but write to NVRAM could be deferred until shutdown, then here is the typical steps.
- Get reference to the RAM block using RTE generated API.
- Modify the elements of this RAM block as required.
- Mark the block status as modified using RTE API. (NvM_SetRamBlockStatus)
Application developer responsibility ends here. The data from RAM block will be transfered to NVRAM block at shutdown.
Note: In case power to ECU is removed before transferring data to NVRAM, the data is lost/corrupt.
BSW engineer perspective
NvM_ReadAll shall be called by ECU state manger during start-up. The NvM module shall copy each NVRAM block (if configured) to RAM. NvM_WriteAll shall be called by the ECU state manager at shutdown.
Only ECU state manger is allowed to call this API. This is to ensure RAM block content are not being modified by SW-C. At shutdown call to NvM_WriteAll is placed and polling is used to assert the completion of job , before continuing the shutdown sequence.
Key configuration to note
The NvRAM block shall have the WriteAll flag configured.
Example code
Assume that there is a block named SpeedLimiter with two uint8 data fields 1. defaultLimit, maxLimit. The pseudo-code of function implementation is available in my github repository here.