Every embedded system or more specifically an ECU in an automotive system have the requirement to store data permanently in Non-volatile memories either in the flash or EEPROM. It can be any data like vehicle speed, Headlight state and steering lock.
AUTOSAR memory stack is designed to handle the same. It provides Memory Management services to the Application layer via RTE and to the BSW also.
For example – An Application component want to store and read the Engine Control Data via RTE
In BSW a UDS diagnostic tool sending request to read data from memory via CAN. The request will route from CAN stack to Diagnostic Stack and then to Memory Stack in BSW without interfering with the Application component.
The whole Memory stack is divided into three layers each containing specific modules.
1.Memory Service Layer – It provides NVM services to the Application Layer via NVM Module.
2.Memory Hardware Abstraction Layer – It provides independence to the application and Service layer from the Memory devices either EEPROM or flash to maximise the reusability. It contains the Memif, Ea, Fee modules.
3.Memory Drivers – These are the low-level drivers for the microcontroller to write or read to flash or EEPROM inside the microcontroller.
Now let’s take a brief look at each Memory module present in the three layers we discussed
AUTOSAR Memory Stack Module Description -:
Non-Volatile Memory module (NVM) – NVM Module manages the data of EEPROM and flash. It allocates the particular block of memory and configures the characteristics of the individual data in the memory. For eg- How many retries need to be done if data read failed the first time. However, there are some particular concepts like Basic Storge concepts, Addressing scheme for the memory hardware abstraction, Block Management type and Scan order/priority scheme which we need to master before continuing with the configuration of the NVM Module.
Memif Module (Memif) – It provides independence to the NVM module by abstracting the Fee and EA modules. It provides segmentation to the NVM to the linear uniform address space.
Flash EEPROM Emulation Module (Fee) – It provides the upper layer with the 32-bit virtual liner space and uniform memory segmentation scheme. The virtual 32-bit address consists of a 16-bit block number and a 16-bit block offset.
This means we can get 2^16 = 65536 logical blocks inside the memory and each block will be 2^16 = 65536= 64KBytes.
In contrast, it handles the Addressing scheme, Memory Address calculation, erase/write cycles, Handling of “immediate” data to write instantaneously in the memory, Managing block consistency information
EEPROM Abstraction Module (EA) – It also provides the upper layer with the 32-bit virtual liner space and uniform memory segmentation scheme. The virtual 32-bit address consists of a 16-bit block number and a 16-bit block offset. The only difference between EEPROM and Flash is we can read/write 1 byte in the EEPROM but in the case of Flash Memory only sectors of memory can be written/erased. Similar to the Fee module, It handles the Addressing scheme, Memory Address calculation, erase/write cycles, Handling of “immediate” data to write instantaneously in the memory, Managing block consistency information
Flash Driver – It’s the MCAL driver which takes the responsibility to Read, Write and erase the flash memory. It handles all the hardware level registers or communication protocols if external Flash is used via SPI or I2C.
EEPROM Driver – It’s the MCAL driver which takes the responsibility to Read, Write and erase the EEPROM memory. It handles all the hardware level registers or communication protocols if external EEPROM is used via SPI or I2C.6