EtherCAT Slave
 
Loading...
Searching...
No Matches
Non-Volatile Memory (NVM)

Introduction

This page shall focus on the customer implementation of NVM (Non Volatile Memory) interface. The demo implementation is specifically designed for the TI reference design. However, it’s important to note that customization is required for the customer to adapt it to their specific needs. In other words, the customer must either create their own implementation or tailor the existing demo implementation to suit their requirements.

NVM Layer Architecture

Implementation Details

The application shall make use of the public functions related to the non-volatile memory interface from the header file nvm.h.

The application shall be able to specify the type of non-volatile memory used to store/retrieve the data, which is provided as an enumeration.

typedef enum NVM_type {
NVM_TYPE_EEPROM = 0,
NVM_TYPE_FLASH,
NVM_TYPE_END_NUM
} NVM_type_t;

The application can write data to the non-volatile memory in two modes.

  1. Blocking mode
    • The blocking API NVM_APP_write shall be used which directly triggers the TI drivers to write data into the non-volatile memory.
  2. Non blocking mode
    • The non blocking API NVM_APP_writeAsync shall be used which triggers the thread to write data into the non-volatile memory.

In the non blocking mode before calling the API NVM_APP_writeAsync it is necessary to call the APIs NVM_APP_init which shall start the write task NVM_APP_writeTask with the specified priority and a semaphore for it,

uint32_t NVM_APP_init(const OSAL_TASK_Priority_t priority);

and NVM_APP_registerCallback to register the callback function to get the status of the async write process.

uint32_t NVM_APP_registerCallback(NVM_APP_writeCallback_t callback)

The callback function type shall be as specified below.

typedef void(*NVM_APP_writeCallback_t)(uint32_t status);

The write task NVM_APP_writeTask created for the non blocking NVM data write shall trigger the registered callback with the write status as a argument provided in the form of an enumeration specified below.

typedef enum NVM_err {
NVM_ERR_SUCCESS = 0,
NVM_ERR_FAIL,
NVM_ERR_BUSY,
NVM_ERR_REJECT,
NVM_ERR_INVALID,
NVM_ERR_END_ENUM
} NVM_err_t;

As a contradictory, the API NVM_APP_close kills the write task NVM_APP_writeTask and the semaphore which were being created by the API NVM_APP_init

uint32_t NVM_APP_close(void);

The APIs NVM_APP_write and NVM_APP_writeAsync shall have same set of parameters.

uint32_t NVM_APP_write(
const NVM_type_t type,
const uint32_t id,
const uint32_t offset,
const uint32_t length,
const void * const pData);
uint32_t NVM_APP_writeAsync(
const NVM_type_t type,
const uint32_t id,
const uint32_t offset,
const uint32_t length,
const void * const pData);

The parameter type can be NVM_TYPE_EEPROM or NVM_TYPE_FLASH depending on the implementation.
The parameter id can be CONFIG_EEPROM0 or CONFIG_FLASH0 or similar depending on the sysconfig adaptations.

SysConfig - EEPROM
SysConfig - Flash

The parameter offset shall be the data offset to write the data block into the non-volatile memory. For example, as per the AM64x/AM243x EVM User's Guide, the first 259 bytes of addressable EEPROM memory are pre-programmed with board identification information. In this case the offset shall be at least 259.

AM64x/AM243x EVM User's Guide

The parameter length shall the length of the data block and pData shall be the pointer to the data block to be written into the non-volatile memory.
Note:The API NVM_APP_writeAsync does NOT copy the data to another buffer, therefore please ensure that the buffer is not destroyed after calling this API.

Below is the sample implementation of the API NVM_APP_write in a application.

#define EEPROM_DATA_OFFSET (0x200U)
uint32_t buffer_length = 0x10;
// Allocate a memory block for the buffer used to store the data to be written into NVM.
buffer = OSAL_MEMORY_calloc(buffer_length,sizeof(uint8_t));
// Fill the allocated memory with valid data to be written into NVM.
NVM_APP_write(NVM_TYPE_EEPROM,
CONFIG_EEPROM0,
EEPROM_DATA_OFFSET,
buffer_length,
buffer);

Below is the sample implementation of the API NVM_APP_read in a application.

#define EEPROM_DATA_OFFSET (0x200U)
uint32_t buffer_length = 0x10;
// Allocate a memory block for the buffer used to store the data read from the NVM.
buffer = OSAL_MEMORY_calloc(buffer_length,sizeof(uint8_t));
NVM_APP_read(NVM_TYPE_EEPROM,
CONFIG_EEPROM0,
EEPROM_DATA_OFFSET,
buffer_length,
buffer);

Below is the sample implementation of the API NVM_APP_writeAsync in a application.

// Callback function to be attached to get the status of async NVM write.
// Hint: Use the registered callback to free the data buffer.
void myWriteAsyncCallback(uint32_t status)
{
if (status != NVM_ERR_SUCCESS)
{
// handle the error status
}
// free any allocated buffers etc..
}
#define EEPROM_DATA_OFFSET (0x200U)
uint32_t buffer_length = 0x10;
// Allocate a memory block for the buffer used to store the data to be written into NVM.
buffer = OSAL_MEMORY_calloc(buffer_length,sizeof(uint8_t));
NVM_err_t error;
error = NVM_APP_init(OSAL_TASK_Prio_Normal);
if (error != NVM_ERR_SUCCESS)
{
// handle the errors
}
error = NVM_APP_registerCallback(myWriteAsyncCallback);
if (error != NVM_ERR_SUCCESS)
{
// handle the errors
}
// Fill the allocated memory with valid data to be written into NVM.
error = NVM_APP_writeAsync(NVM_TYPE_EEPROM,
CONFIG_EEPROM0,
EEPROM_DATA_OFFSET,
buffer_length,
buffer);
if (error != NVM_ERR_SUCCESS)
{
// handle the busy or error state
}