NVRAM Manager in AUTOSAR

1. Basic Working Principle :

Consider fig.1 shown below, in case of write data?(Blue arrow), SWC has data to write in NV memory, data is copied to RAM block then data is copied to NV Memory. Similar is the case while reading data?(Yellow arrow), first data is copied to RAM block? from NV Block then SWC read data from RAM block or RAM mirror.


Fig.1 Basic Working Mechanism of MemStack

NV Block and Block IDs

NV blocks are used to store NV data and present into NV memory. Each block is associated with block ID and this is maintained in NV Block descriptor table.e.g. if you have data related to vehicle speed e.g. max speed, min speed,? this data you can see on console of car, this data is stored in NV memory. There is a block dedicated to Vehicle Speed parameters and a block ID corresponding to a block. Similarly to store errors related to create a bock for vehicle error and assign a block ID using configuration tools.

2. Basic Storage Object and Block Management?:

To understand memory stack you should understand basic storage object used in memory stack and block management.?Basic storage object is smallest entity of memory block. Basic storeage objects are :?RAM block, ROM block, NV block and? Administrative block.

To store data into NV memory and? to handle data to be stored into NV memory, a concept used called?memory blocks,?e.g. if you have a data related to Vehicle Speed? (Vspeed), this Vspeed is to be stored in NV memory. Size of Vspeed is 2 bytes, so to store Vspeed in NV memory?blocks of memory is reserved in NV memory called NV blocks.?

Application (SWC) which uses VIN, uses RAM blocks to handle VIN.?Now what is use of RAM blocks if you already? have NV block?.?Application (SWCs) holds data into RAM block, at time of writing data in NV memory, data from RAM block is copied into NV block, at? time of data read, data from NV block is copied to RAM block.?RAM block is required as there is limitation of NV memory write cycle?(e.g. 10,000 write cycles), so data is held in RAM blocks and written to NV blocks when required, by doing so NV memory's life (write cycle) is maintained.?


Fig. 2 Basic Storage Objects

2.1 Basic Storage Objects :

Below are the basic storage objects

NV Block :?NV block is basic storage object and resides in NV Memory. NV block structure is shown in fig.2. NV Block made up of optional CRC, optional Header and NV memory.

RAM Block :?RAM block basic storage object resides in RAM. RAM blocks can be permanent or temporary. Each RAM block corresponds to a particular NV Block. Structure of RAM block is as per? fig.2. RAM block has optional CRC (is available if corresponding NV block is having a CRC) and Header block and RAM memory.

ROM Block :?Rom block in ROM. It do not have CRC or Header refer fig.2. ROM block contains default data. This data is used in case of error in NV block (this will be explained in error recovery section)

Administrative Block :?Administrative block resides in RAM and this block is mandatory. It is used to hold status of corresponding RAM block (discussed in Part -2 of NVRAM manager).


2.2 Block Management Types :

In above section we have discussed about basic storage object, in this section we will discuss about block management types. NVRAM block contains RAM block, ROM block, NV block and Administrative block. Combinations of these blocks can be configured to create different types of? NVRAM block. Below are the block management types supported by NvM :


1. Native Block :

The Native NVRAM block is the simplest block management type. It allows storage to/retrieval from NV memory with a minimum of overhead.

In case of native block, there will be 1 NV block created in NV memory. Then 1 RAM block will be created, as RAM block is required to provide data to application /run time. 1 ROM block to store default values and 1 Administrative block.

NV Block : 1

RAM Block : 1

ROM Block : 1 or 1

Administrative Block : 1


2. Redundant Block :

In addition to the Native NVRAM block, the Redundant NVRAM block provides enhanced fault tolerance, reliability and availability. It increases resistance against data corruption.

So if one NV block fails, we have still have one more block, from which data can be retrieved. This will help to keep data secure in NV memory.

In case of Redundant block there will be 2 NV blocks but 1 RAM block as application will require only a copy if valid data, so valid data NV block will be copied to RAM. ROM block will be required as 1 and 1 Administrative block.

NV Block : 2

RAM Block : 1

ROM Block : 0 or 1

Administrative Block : 1


3. Data Set Block :

The Dataset NVRAM block is an array of equally sized data blocks (NV/ROM). The application can at one time access exactly one of these elements.?A specific dataset element is accessed by setting the corresponding index using the API NvM_SetDataIndex.

NV Block : 1...n

RAM Block : 1

ROM Block : 0 or n

Administrative Block : 1


4. Introduction :

NvM module is present in service layer of AUTOSAR and provides services to Software Components (SWCs) regarding? Non -Volatile (NV) data storage (e.g. read and write service) and maintenance. NvM module administrates NV data of EEPROM and FLASH EEPROM module.?NV RAM manager is only module, using which NV memory can be accessed.?

In order to configure memory stack you should understand functionality of NV RAM manager.

What does NV RAM do :

1. Provides Services to SWCs and BSW modules to read/write memory.

2. Performs Error detection of NV memory and? Error recovery( Implicit or Explicit).

3. Validation of RAM block data.

4. Provides multi-block read and write request.

5. Performs write verification.

  • In below section functionalities of? NVRAM manager are described.


5.? Functionalities of NvM Module :

This section describes important functionalities of NVRAM module.

5.1 RAM Block States :?

Depending on different API calls, status of RAM block is changed. NVRAM manager changes states of RAM blocks and these states are used while reading or writing. Status of each RAM block is stored in Administrative blocks. Three states of RAM block are :

1.Valid Unchanged?

2.Valid Changed?

3. Invalid Unchanged.

1. Valid Unchanged :

This state shows that content of RAM blocks are not changed they are same as NV memory. To enter into this state read/write for single block or multi block request has to be successful (i.e.?NvM_ReadBlock() / NvM_ReadAll() or NvM_WriteBlock() / NvM_WriteAll() state changes to Valid Unchanged ).

2. Valid Changed :?

This state shows that content of RAM block is changed.?

  • If NvM_SetRamBlockStatus called with TRUE for the block or
  • If Write all or write block request are ongoing or
  • If?NvM_RestoreBlockDefaults called for the block finishes successfully then state of RAM block is changed to Valid changed.
  • Read all or read block gives default data

3. Invalid Unchanged :

This implies that state of RAM block is invalid. After initialization state of RAM block is Invalid Unchanged.?To enter the INVALID / UNCHANGED state, at least one of the following must occur:

  • NvM_SetRamBlockStatus called with FALSE for the block
  • Read block/Read all/Write block/Write all operation is unsuccessful?
  • NvM_EraseNvBlock finished successfully for the block
  • NvM_InvalidateNvBlock finished successfully for the block

5.2 Read Block and Read All :

Read block and read all requests are Asynchronous request. Read block function reads a single block (i.e. particular NV block). Reads data from a NV block and updates temporary RAM block. NvM_ReadBlock() function is used for this purpose, NvM_ReadBlock() function will copy data from NV memory to temporary RAM block.

NvM_ReadPRAMBlock() function will copy data from NV block to permanent RAM block

Read all function will read all NV block at a time. NvM_ReadAll() reads data from NV block and loads into RAM block, if there is error while reading a block i.e. content of RAM block does not matches with NV block i.e. CRC error and Read from NV fails(Invalid Unchanged), default data is loaded into RAM block and if block is of redundant type then read from redundant block is performed and if this fails then default value is loaded to RAM block. NvM_ReadAll() function is used at time of initialization of ECU, and called by ECU state manager.

After read block or read all request, if request? is successful state of RAM block is changed to Valid Unchanged.?

5.2.2 Static ID check :?

When NV block is written to NV memory an ID i.e. static block ID is also written to NV memory. Static ID is stored into block header. This ID is checked against requested block ID. e.g if you have written a Block with ID 10 in memory, and when you requested to read block with ID 10, so requested ID is compared against stored block ID, to detect an error. If wrong block ID error is detected then error NVM_E_WRONG_BLOCK_ID is reported to DEM.?

Static ID check can be enabled using configuration parameter. If static ID check failed for RAM block, status of RAM block changed to Invalid Unchanged.


5.2.3 Read Retries :

Read Retries is performed when there is error while reading NV data. i.e. NVRAM manager will try to read NV data again, NV RAM manager will perform read retries as per the value of configuration parameter NVM_MAX_NUM_OF_READ_RETRIES. e.g. if read retry value is 2 then NvM will read block 2nd time if there is error in reading block 1st time.

After read retries if there is still error then NVRAM manager either read ROM block or read redundant NV Block (if configured).

Read retries will be performed under following condition :

1. If NVRAM manager detects? CRC error

2. If NVRAM manager detects Static Block ID check

5.3 Write Block and Write All:

Write block and write all requests are Asynchronous request. Write block functions writes a single block into NV memory. To write a block?NvM_WriteBlock() function is used. This function will copy data from temporary RAM block to ROM block.?NvM_WritePRAMBlock() will write data from Permanent RAM block to NV block.?

Write all will write all the blocks at a time.?NvM_WriteAll() function, will calculates CRC at a time of writing, if? CRC is matches and RAM block status is valid then the corresponding block will not be written into NV memory. For permanent RAM block : state can be changed by API NvM_SetRamBlockStatus() to VALID_CHANGED and can be written at time of NvM_WriteAll().

If Write Block and NvM_WriteAll? is successful then RAM block state changed to Valid Unchanged and during? Write Block and NvM_WriteAll request processing RAM block status is Valid Changed.

5.3.1 Write Protection :

If write protection is enabled, RAM block can be modified but NV block can not be modified. Write protection is performed by configuring parameter NvMBlockWriteProt = TRUE.?

NvM_SetBlockProtection() function can be use to enable/disable write protection (explicit mechanism), if NvMWriteBlockOnce is FALSE (regardless of value of NvMBlockWriteProt).

If NvMWriteBlockOnce is True then enabling/disabling is not possible using NvM_SetBlockProtection() function validation of RAM block

5.3.2 Write Verification :?

When a RAM Block is written to NV memory the NV block shall be immediately read back and compared with the original content in RAM Block. Write Verification can be configured using parameter?NvMWriteVerification. If the original content in RAM Block is not the same as read back then the production code error NVM_E_VERIFY_FAILED shall be reported to DEM. If write retries is configured and if? write verification fails then NVRAM manager will try to write data again. Write retries can be configured by parameter NvMMaxNumOfWriteRetries.? NVM_E_REQ_FAILED error will occur if? max number of retries tried.

5.4 Error Detection NVRAM Block Data Consistency check :

Error is detected by CRC comparison mechanism. The NvM module internally uses CRC generation routines (8/16/32 bit) to check and to generate CRC for NVRAM blocks as a configurable option. If CRC of RAM block and CRC of ROM block does not match then error occurs.? Data consistency is checked by using CRC calculation mechanism. Implicit way is to enable configuration parameter NvMBlockUseCrc and NvMCalcRamBlockCrc

1. CRC is calculated if NvM_SetRamBlockStatus() is called and NvMCalcRamBlockCrc == TRUE.

2. CRC will be calculated in backround by NvM_Main() function.

3. CRC is calculated after NvM_ReadBlock() is processed and NvMCalcRamBlockCrc == TRUE.

4. CRC is calculated when NvM_WriteBlock() and NvM_WriteAll() requests CRC calculation before writing into NV block.

5. CRC is calculated after NvM_RestoreBlockDefaults(), crc of RAM block is calculated.

6. CRC is calculated during NvM_ReadAll().

  • If CRC mismatch occurs then Integrity fail error occurs after CRC mismatch.

5.5 Error Recovery :

Error recovery shall? provided for read NV data or for Write NV data. Default values are loaded to RAM block from ROM block if there is error while reading data.

Write retries is type of error recovery if there is error while writing data i.e. content of RAM block are not same as what is written.

Recovery of RAM data with ROM Data (Implicit) :

Implicit recovery provided while startup ( at time of NvM_ReadAll() )under condition

1. ROM block is configured and

2. CRC mismatch of RAM block and ROM block and

3. Read attempt from NV fails.

Recovery of RAM data with ROM Data (Explicit) :

Explicit recoveryry is performed by calling APIs NvM_RestoreBlockDefaults() or NvM_RestorePRAMBlockDefaults(). These APIs are called by application SWC if application detects error at run time.

5.6 Initialization and Shutdown of NVRAM Module :

NvM is initialised by ECU state manager by calling NvM_Init() function, but this function does not contains initialization of RAM Blocks. Ram blocks are initialized by function NvM_ReadAll(). NvMReadAll()? will copy data from NV block to RAM block and initializes them. Shutdown is performed by calling Nvm_WriteAll(), this function will write data from RAM block to NV block.

5.7 Resistance to SW Change :

In this section we will discuss about two configuration parameters : NvMDynamicConfiguration and NvMResistantToChangedSw.

Consider you have already configured 4 NV BLOCKs, data is written to them. Now you have changed the block size of one of the block or new block is added, due to which IDs of other blocks got changed this will leads to wrong data read at time of read all process.

for such case you can have an option not to initialize RAM block with NV block data this can be done by setting parameter NvMDynamicConfiguration = TRUE and change of configuration has to notified by?configuration parameter NvmCompiledConfigID.?

What is?NvmCompiledConfigID ? this is a configuration parameter, stored in separate NV block and at startup value of?NvmCompiledConfigID is compared with value stored in NV block, if value compared is different then default values are loaded to RAM block and at write all new values are written to NV block, so in next startup cycle new values will be available to RAM block if?

NvMResistantToChangedSw?parameter set to TRUE and?

NvMResistantToChangedSw?parameter set to false then default values are loaded to RAM block irrespective of validity of RAM block.

In short :

1. Consider NV blocks contains old data and?NvMDynamicConfiguration = TRUE.?

2. Configuration is changed.

3. At read all?NvmCompiledConfigID comparison shows configuration is changed.

4. If?NvMResistantToChangedSw?parameter set to?TRUE, then content from NV blocks will be loaded to RAM block which will cause inconstancy (as data from old blocks will get written into new blocks).

5. If?NvMResistantToChangedSw?parameter set to?FALSE, then at time of? Read All, defaults values will be loaded to RAM block.

So if you are going to change configuration better to set?NvMResistantToChangedSw?parameter to?FALSE.


5.8 Job End and Job Error Notification?:

When read data from NVM is finished or write data from NVM is finished with status ok, the underlying memory abstraction to signal end of job without error.?NvM_JobEndNotification() is getting called. Similarly? NvM_JobErrorNotification() is getting called if read data from NVM is aborted with error or write data from NVM is aborted with error.

5.9 Immediate Data :

You can configure block to store data immediately i.e. when NvM_Write is requested data should be written in NV memory immediately, then you can enable configuration? parameter immediate write ON.?

Generally if immediate data is disabled, and NV data write will be done at when write all is in processing i.e. at shutdown time. Till then if data is changed it will be stored in RAM blocks, and? write all will call single block write and writes data into NV memory if data is changed.


6. NV data accessing :

NVRAM Basic working principle and basic storage objects i.e. RAM Block, ROM Block and NV Block? and NV data is read from ROM block to RAM block and while writing data is copied to NV block from RAM block. Application SWC reads or Writes RAM block to read NV data and to write NV data respectively.

Also there is?RAM block and RAM Mirror, difference between them will be get clear in this section. There is data transfer between NV block and application SWC using RAM block, this data transfer is either?explicit or implicit.

In implicit data from RAM block is copied to NV Block and from NV block to RAM block, once application SWC request for Read or write data. While in case of explicit communication NV module need to use APIs to read/write data from RAM block,?once application SWC request for Read or write data

6.1 Implicit data transfer between NV block and RAM block :

In implicit communication? RAM block is used. Application SWC and NV block exchanges data using RAM block. RAM block can be permanent or temporary.?Permanent RAM blocks are associated with one application SWC and permanent RAM block can be accessed by respective SWC only. Temporary ram blocks are created at run time i.e section of RAM is used.


Fig.4 Implicit Synchronization

6.1.1 Write Block Request? :

Write Operation : Application SWC fills RAM block and content of RAM blocks are copied into NV block. Application SWC has to follow below rules while write request.

1. Application? fills RAM block using APIs?NvM_WriteBlock()/NvM_WritePRAMBlock().

2. Now request is transferred to NvM Module and till then??application SWC should not modify RAM block?(to maintain data consistency).

3. By polling method or by call-back notification (job end notification) application SWC gets status of request (write operation successful or failed), then after application can use RAM block again.

6.1.2 Read Block Request :?

Read operation : NV blocks updates RAM block and application SWC reads RAM block. Application SWC has to follow below rules while read request.

1. To read NV data, application SWC need to? provide RAM block.

2. Use API?NvM_ReadBlock() or NvM_ReadPRAMBlock()?to read data from NV.

3. Status of read request can be read by polling mechanism or call back notification, till then application SWC should not read/write RAM block.

4. After success of request, application SWC can use RAM block data (Ram block contains data from NV block).

6.2 Explicit data transfer between NV block and RAM block :

Explicit synchronization?RAM mirror?is used to transfer data between RAM block and NV Block.? Application writes/reads data to /from RAM Mirror using? NV Block reads/writes RAM mirror and copies data to/from NV Block.?

Explicit mechanism can be?configured per block by parameter NvMBlockUseSyncMechanism.?

NvMBlockUseSyncMechanism == TRUE.

Drawback of this method is extra RAM mirror is required of size of max RAM block. Advantage is RAM block can be controlled efficiently and data consistency is maintained better way. Only 1 RAM mirror is present irrespective of number of RAM blocks ( at 1 RAM has to be configured).


Fig.5 Explicit Synchronization

6.2.1 Write Data

Application SWC writes data to ram block then data is copied to RAM mirror and NV block reads data from RAM mirror. Application has to follow below points while write request:

1. Application SWC to use API?NvM_WriteBlock() or NvM_WritePRAMBlock()?to fill RAM block with data.

2. NvM calls routine?NvMWriteRamBlockToNvM()?to read data from RAM block. Once this routine is called application SWC has to provide consistent?

3. Application SWC can read/write RAM block as data is copied to RAM Mirror.

4. Status of write operation can be read by polling mechanism or by call back function.

6.2.2 Read Data

Application SWC readsNV data from RAM mirror (i.e.copies data from RAM mirror to RAM blcok) and RAM mirror is updated by NV block. Application has to follow below rules while read request:

1. Application SWC to use API?NvM_ReadBlock() or NvM_ReadPRAMBlock()?to read data from RAM block.

2. Application SWC to provide RAM block to be filled with data.

3. NvM module calls?NvMReadRamBlockFromNvM()?function, application SWC can copy data to RAM block from RAM mirror.

4.? Status of read operation can be read by polling mechanism or by call back function.

7. NvM Accessing by RTE:

To access NvM interfaces are provided by NVRAM manager are client server or NvDataInterface. Normal SWC can use client server interface and NvData interface is used with NvBlock SWC. Please refer image below.


Fig.6 Accessing NVRAM Manager

Fig. 6 shows Application SWC uses client server interface to access NVRAM manager, i.e. uses service ports provided by NVRAM manager. Also There is one more type NvBlock SWC, which can be accessed by multiple SWC using sender receiver and NvBlock SWC uses NVservice ports to use services provided by NVRAM manager. SWC can use Permanent RAM block or Temporary RAM bock and based on synchronization mechanism either ram mirror is used or not.

So ways to access NVRAM using SWC are :

1. Application SWC uses temporary RAM block with or without RAM mirror

2. Application SWC uses permanent RAM blocks with or without RAM mirror

3. NV SWC with RAM mirror only

A.? Client-server interface :

A client/server interface provides a number of operations that can be invoked on a server by a client. In case of services provided by NvM to the Application, NvM acts as server and Application acts as client. Also notifications to be provided to the Applications from NvM can be implemented using same; role of client and server is exchanged in this case.

B. NvDataInterface :

A non-volatile data interface defines a number of VariableDataPrototypes to be exchanged between non-volatile block components and atomic software components. These VariableDataPrototypes can be mapped to complete RAM block or elements of RAM block implemented inside non-volatile block components.

C.? Service Ports :

Below are the some service ports (with operations/services) provided by NVRAM manager. SWC can use one of them to access provided service by service to port.

1 NvM_Admin :

NvM_Admin provides service for setting/resetting the write protection for a NV Block. To perform operations related to write protection Application SWC can use SetBlockProtection() API . SetBlockProtection() operation provided by NvM_Admin service port.

2 NvM_Mirror :

If ram mirror is configured then application need to copy data to/from RAM Mirror, for that call-back functions are used (?WriteRamBlockToNvM and ReadRamBlockFromNvM ) and these functions are provided by NvM_Mirror service port.

3 NvM_NotifyInitBlock :

Callback is? called by NvM module when default data need to be restored in RAM blok.??InitBlock() is the callback called by NvM module when initialization of RAM block is completed i.e. after loading default data to RAM block.?InitBlock() is called as there is no rom block is present to load default value.

4 NvM_NotifyJobfinished :

This service port provides call-back which is called when NvM job is finished ( i.e. after Read Block or Write Block operation is finished )

5 NvM_Service :

This is important service port. This service port provides many operations to Application SWC.

These operations/APIs are :

1.?EraseBlock()

2. ReadBlock()

3. WriteBlock()

4. RestoreBlockDefaults()

5. GetDataIndex()

6. GetErrorStatus()

7. InvalidateNVBlock()

8. ReadPRAMBlock()

9. WritePRAMBlock()

8. Important Configuration Parameters:


To configure NVRAM manager you should never forget these important parameters :

1. Block Id.

2. Block Length.

3. Is block should be processed at Read all or write all time.

4.?RAM block?(Temporary / Permanent).

5.?CRC calculation.

6.?Write Protection.

7. Resistance to change SW.

8. Job end notification.

9. Enable?Synchronization?( i.e explicit synchronization)

10. If enabled synchronization then get and set ram mirror callbacks.

11. To provide default values, use of?ROM block.

12.?Block type ( Native or redundant or Data set ).

要查看或添加评论,请登录

Upendra Kumar的更多文章

  • Debugging SPI communication issues

    Debugging SPI communication issues

    Case 1: Master can't able to produce clock and data? ? Root Causes: Master mode not enabled in control register. SPI…

    1 条评论
  • Understanding Data Watchpoints in Embedded Debugging

    Understanding Data Watchpoints in Embedded Debugging

    In embedded systems debugging, Data Watchpoints are a powerful tool for tracking variable modifications in real-time…

  • System Basis Chips (SBCs)

    System Basis Chips (SBCs)

    What is an SBC? SBC (System Basis Chip) is an integrated chip used in automotive Electronic Control Units (ECUs). It…

  • AUTOSAR DCM Module

    AUTOSAR DCM Module

    1. AUTOSAR DCM Module : In case of vehicle diagnostics, diagnostic tester tool sends a diagnostic request to ECU and…

    1 条评论
  • Autosar Com Stack

    Autosar Com Stack

    1. SWC (Software Component) ?The SWC is an application-level module that generates or receives data, which needs to be…

  • Memory Organization

    Memory Organization

    1. 32-bit Address Space: - The ARM processor uses a 32-bit address, meaning it can address up to 4 GB of memory.

    1 条评论

社区洞察

其他会员也浏览了