EEPROM

The EEPROM driver provides API to read and write to I2C based EEPROM devices present in the board. The driver takes care of all sequencing necessary to perform writes across pages and the application need not take care of the programming intricacies.

Features Supported

  • Read and write API from any offset

  • Provide API to return EEPROM attributes like size, page size etc

SysConfig Features

Note

It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.

  • Option to select EEPROM type based on board

  • Supported EEPROMs

  • AT24C

  • Option to set the I2C address of the EEPROM

Features NOT Supported

NA

Important Usage Guidelines

J20 header pins needs to be shorted for having the write protect disabled for the EEPROM

Example Usage

Include the below file to access the APIs

//! [include]
#include <board/eeprom.h>
//! [include]

EEPROM Read API

//! [read]
    status = EEPROM_read(handle, 0, buffer, 100);
    DebugP_assert(SystemP_SUCCESS == status);
//! [read]

EEPROM Write API

//! [write]
    status = EEPROM_write(handle, 0, buffer, 100);
    DebugP_assert(SystemP_SUCCESS == status);
//! [write]

API Reference

EEPROM driver implementation callbacks

typedef int32_t (*EEPROM_OpenFxn)(EEPROM_Config *config, const EEPROM_Params *params)

Driver implementation to open a specific EEPROM driver.

Typically this callback is hidden from the end application and is implemented when a new type of EEPROM device needs to be implemented.

Param config:

[IN] EEPROM configuration for the specific EEPROM device

Param params:

[IN] User controllable parameters when opening the EEPROM device

Return:

SystemP_SUCCESS on success, else failure

typedef void (*EEPROM_CloseFxn)(EEPROM_Config *config)

Driver implementation to close a specific EEPROM driver.

Typically this callback is hidden from the end application and is implemented when a new type of EEPROM device needs to be implemented.

Param config:

[IN] EEPROM configuration for the specific EEPROM device

Return:

SystemP_SUCCESS on success, else failure

typedef int32_t (*EEPROM_ReadFxn)(EEPROM_Config *config, uint32_t offset, uint8_t *buf, uint32_t len)

Driver implementation to read from EEPROM using a specific EEPROM driver.

Typically this callback is hidden from the end application and is implemented when a new type of EEPROM device needs to be implemented.

Param config:

[IN] EEPROM configuration for the specific EEPROM device

Param offset:

[IN] Offset in the EEPROM from where to start the read

Param buf:

[IN] Buffer into which to read the data into

Param len:

[IN] Length of the data to read, in bytes

Return:

SystemP_SUCCESS on success, else failure

typedef int32_t (*EEPROM_WriteFxn)(EEPROM_Config *config, uint32_t offset, const uint8_t *buf, uint32_t len)

Driver implementation to write to EEPROM using specific EEPROM driver.

Typically this callback is hidden from the end application and is implemented when a new type of EEPROM device needs to be implemented.

Param config:

[IN] EEPROM configuration for the specific EEPROM device

Param offset:

[IN] Offset in the EEPROM from where to start the write.

Param buf:

[IN] Buffer which has the data to write.

Param len:

[IN] Length of the data to write, in bytes

Return:

SystemP_SUCCESS on success, else failure

Defines

EEPROM_PAGE_SIZE

Max EEPROM page size used to allocate temp write buffer so that address (offset) and data can be done in single I2C operation.

EEPROM_WR_BUF_SIZE

Temp write buffer to hold address offset and data for page write operation - 2 bytes for offset and remaining for one page data.

Typedefs

typedef void *EEPROM_Handle

Handle to the EEPROM driver returned by EEPROM_open()

Functions

void EEPROM_Params_init(EEPROM_Params *params)

Set default parameters in the EEPROM_Params_s structure.

Call this API to set defaults and then override the fields as needed before calling EEPROM_open.

Parameters:

params – [OUT] Initialized parameters

EEPROM_Handle EEPROM_open(uint32_t instanceId, const EEPROM_Params *params)

Open EEPROM driver.

Make sure the SOC peripheral driver is open’ed before calling this API. Drivers_open function generated by SysCfg opens the underlying SOC peripheral driver, e.g I2C.

Global variables EEPROM_Config gEepromConfig[] and uint32_t gEepromConfigNum is instantiated by SysCfg to describe the EEPROM configuration based on user selection in SysCfg.

Parameters:
  • instanceId – [IN] Index within EEPROM_Config gEepromConfig[] denoting the EEPROM driver to open

  • params – [IN] Open parameters

Returns:

Handle to EEPROM driver which should be used in subsequent API call Else returns NULL in case of failure

void EEPROM_close(EEPROM_Handle handle)

Open EEPROM driver.

Parameters:

handle – [IN] EEPROM driver handle from EEPROM_open

int32_t EEPROM_read(EEPROM_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len)

Read data from EEPROM.

Parameters:
  • handle – [IN] EEPROM driver handle from EEPROM_open

  • offset – [IN] Offset in the EEPROM from where to start the read

  • buf – [IN] Buffer into which to read the data into

  • len – [IN] Length of the data to read, in bytes

Returns:

SystemP_SUCCESS on success, else failure

int32_t EEPROM_write(EEPROM_Handle handle, uint32_t offset, const uint8_t *buf, uint32_t len)

Write to EEPROM.

Make sure the block is erased before writing

Parameters:
  • handle – [IN] EEPROM driver handle from EEPROM_open

  • offset – [IN] Offset in the EEPROM from where to start the write.

  • buf – [IN] Buffer which has the data to write.

  • len – [IN] Length of the data to write, in bytes

Returns:

SystemP_SUCCESS on success, else failure

const EEPROM_Attrs *EEPROM_getAttrs(uint32_t instanceId)

Return EEPROM attributes.

Parameters:

instanceId – [IN] EEPROM instance ID

Returns:

EEPROM_Attrs, else NULL if instanceId is invalid

struct EEPROM_Params_s
#include <eeprom.h>

Parameters passed during EEPROM_open()

Forward declaration of EEPROM_Params_s.

Public Members

uint32_t driverInstance

Underlying peripheral driver instance that is used by the EEPROM driver

uint32_t i2cAddress

EEPROM I2C address

struct EEPROM_Fxns
#include <eeprom.h>

Driver implementation callbacks.

Public Members

EEPROM_OpenFxn openFxn

EEPROM driver implementation specific callback

EEPROM_CloseFxn closeFxn

EEPROM driver implementation specific callback

EEPROM_ReadFxn readFxn

EEPROM driver implementation specific callback

EEPROM_WriteFxn writeFxn

EEPROM driver implementation specific callback

struct EEPROM_Attrs
#include <eeprom.h>

EEPROM device attributes, these are filled by SysCfg based on the device that is selected.

Public Members

uint32_t size

Size of EEPROM in bytes

uint32_t pageCount

Number of pages

uint32_t pageSize

Size of each page, in bytes

struct EEPROM_Config_s
#include <eeprom.h>

EEPROM driver configuration, these are filled by SysCfg based on the device that is selected.

Forward declaration of EEPROM_Config_s.

Public Members

EEPROM_Attrs *attrs

EEPROM device attributes

EEPROM_Fxns *fxns

EEPROM device implementation functions

void *object

EEPROM driver object, used to maintain driver implementation state

struct EEPROM_Object
#include <eeprom.h>

EEPROM driver object - not to be used by application.

Public Members

I2C_Handle i2cHandle

I2C driver handle

uint32_t driverInstance

Underlying peripheral driver instance that is used by the EEPROM driver

uint32_t i2cAddress

EEPROM I2C address

uint8_t pageWrBuf[EEPROM_WR_BUF_SIZE]

EEPROM page write buffer

void *lock

Mutex to protect EEPROM access.

SemaphoreP_Object lockObj

Mutex object.