In this article the topic of discussion is the ECU Abstraction Layer and the MCAL Layer with respect to the Memory Services (MemStack) in AUTOSAR.
ECU Abstraction Layer for Memory Services consists of modules like Memory Interface (MemIf), Flash EEPROM Emulation(Fee) and EA(EEPROM Abstraction), External Flash Driver and External EEPROM driver.
MCAL Layer consists of the Internal Flash Driver and the Internal EEPROM Driver.
Memory Interface (MemIf) is responsible for abstracting the upper layer from the lower layer Flash and EEPROM modules and provide a uniform address space.
Concept of Flash EEPROM Emulation :
EEPROM and Flash memories are both non-volatile memories and are composed of an array of memory cells with each cell holding one or more bits of information.
EEPROM can be programmed and erased on a byte or a word boundary and this can be done on individual cells without disturbing the other values.
Flash Memories can be programmed on a word or double-word boundary with larger sizes also available but the erase can only happen on a sector boundary where a sector size is mostly in Kilobytes. Data in Flash is written terms of Pages (smallest number of bytes that has to be written at once) and erased in terms of Sectors(smallest number of bytes that has to be erased at once).
Flash memory can be used to store data which is typically stored in EEPROM using Flash EEPROM Emulation in which a record based file system is implemented in the flash memory.
A record in this file system is a set of variables consisting of the status of the block (record + data), identifier for the block and the length of data.
Generic Flash Memory Block
When a block is written in flash memory it consists of the record and data.
Flash EEPROM Emulation requires at least two flash sectors for it to be functionally active. Only one sector of the two is the active sector and the other is inactive. Data is continuously written in the active sector till sector limits are reached. If the block with the same identifier is to be written with the updated data then it is written to the next free address space and the address space where it was written previously is made invalid.
Flash Memory Sector
When the active sector is full or the space available in the active sector is less than the block to be written in the sector, re-organization of block happens. Re-organization means the data from the active sector is copied to the other erased sector, the currently active sector is erased and the other sector becomes the active sector. During re-organization only the latest entry for the block is copied to the new sector. This process repeats when the currently active sector becomes full.
Flash EEPROM Emulation module in AUTOSAR is responsible to provide the upper layer with a 32-bit virtual linear address space with uniform segmentation.
Fee module manages the alignment of blocks based on the configuration of virtual page size (multiple of physical page size). Blocks are a multiple of virtual page size and virtual page size is a multiple of physical page size. Virtual page size cannot be less than the physical page size. Data to be written, read or erased in flash memory is managed using the concept of Flash EEPROM Emulation.
The Flash Driver is responsible for providing basic read, write and erase functionality to the upper layers asynchronously.