2.3 EEPROM Off-chip Device Driver
2.3.1 Introduction
The MCC Melody EEPROM Library provides an API interface to support basic EEPROM read and write functionality. The library supports the on-chip EEPROM and various off-chip EEPROM devices that can be connected by their required communication protocol. Its configurable settings include:
- EEPROM Device Type (On-chip/Off-chip)
- Communication protocol settings (for Off-chip EEPROM)
- EEPROM size/density
2.3.1.1 How to use the EEPROM Off-chip Driver
2.3.1.1.1 I2C EEPROM Use Cases
The MCC Melody EEPROM Library supports a selection of I2C EEPROM devices with the following features:
- I2C Dependency:
- A selection of I2C peripherals for sending and receiving data.
- Selectable I2C Clock frequencies provided by the MCU.
- Allows user-selectable EEPROM configurations:
- A selection of EEPROM sizes and Page write buffer sizes to choose from based on the table below.
- Customizable I2C address based on the EEPROM's physical address pins.
EEPROM Word Address Construction:
EEPROM SIZE | WORD ADDR LEN | DEVICE ID | A2 | A1 | A0 | R/W | WORD ADDR MSB | WORD ADDR LSB |
---|---|---|---|---|---|---|---|---|
2Kbit | 8 | 0xA | - | - | - | R/W | - | A7-A0 |
4Kbit | 9 | 0xA | - | - | A8 | R/W | - | A7-A0 |
8Kbit | 10 | 0xA | - | A9 | A8 | R/W | - | A7-A0 |
16Kbit | 11 | 0xA | A10 | A9 | A8 | R/W | - | A7-A0 |
32Kbit | 12 | 0xA | - | - | - | R/W | A11-A8 | A7-A0 |
64Kbit | 13 | 0xA | - | - | - | R/W | A12-A8 | A7-A0 |
128Kbit | 14 | 0xA | - | - | - | R/W | A13-A8 | A7-A0 |
256Kbit | 15 | 0xA | - | - | - | R/W | A14-A8 | A7-A0 |
512Kbit | 16 | 0xA | - | - | - | R/W | A15-A8 | A7-A0 |
1Mbit | 17 | 0xA | - | - | A16 | R/W | A15-A8 | A7-A0 |
2Mbit | 18 | 0xA | - | A17 | A16 | R/W | A15-A8 | A7-A0 |
2.3.2 Module Documentation
2.3.2.1 EEPROM
This file contains API prototypes for the EEPROM driver.
2.3.2.1.1 Module description
This file contains API prototypes for the EEPROM driver.
Data structures
struct eeprom_interface
Creates an instance of the EEPROM interface for the devices.
struct EEPROM_DEVICE_CONTEXT
Contains the EEPROM driver context used in the API routines.
Enumerations
enum EEPROM_STATUS { EEPROM_NO_ERROR = 0U, EEPROM_ERROR = 1U, EEPROM_I2C_TIMEOUT = 3U, EEPROM_INVALID_PARAMETER = 104U, EEPROM_NULL_ERROR = 105U, EEPROM_COM_ERROR = 106U }
Enumeration of the EEPROM driver status codes.
Functions
static void EEPROM_UpdateWriteData (uint16_t dataLength, uint16_t pageCounter)
Updates the write operation parameters.
static uint8_t EEPROM_WordAddressLowGet (uint32_t address)
Gets the lower byte of the word address from the target memory address.
static uint8_t EEPROM_WordAddressHighGet (uint32_t address)
Gets the upper byte of the word address from the target memory address.
static uint8_t EEPROM_DeviceAddressGet (uint32_t address)
Gets the device address of the EEPROM.
static void EEPROM_Tasks (void)
Performs the read and write operations of the driver.
static void EEPROM_Close (void)
Resets the EEPROM status.
bool EEPROM_ByteWrite (uint32_t address, uint8_t *data)
Writes a byte of data to a specified address in the EEPROM device.
bool EEPROM_ByteRead (uint32_t address, uint8_t *data)
Reads a byte of data from a specified address in the EEPROM device.
bool EEPROM_IsBusy (void)
Checks if the EEPROM device is busy.
bool EEPROM_SequentialWrite (uint32_t address, uint8_t *data, size_t dataLength)
Writes n-bytes of data to a specified start address in the EEPROM device.
bool EEPROM_SequentialRead (uint32_t address, uint8_t *data, size_t dataLength)
Reads n-bytes of data from a specified start address in the EEPROM device.
bool EEPROM_PageWrite (uint32_t address, uint8_t *data)
Writes the data to an entire page of the EEPROM device.
bool EEPROM_PageRead (uint32_t address, uint8_t *data)
Reads the data of an entire page of the EEPROM device.
EEPROM_STATUS_t EEPROM_ErrorGet (void)
Checks the type of the error encountered in the EEPROM operation.
2.3.2.1.2 Function Documentation
EEPROM_ByteRead()
bool EEPROM_ByteRead (uint32_t address, uint8_t * data)
Reads a byte of data from a specified address in the EEPROM device.
|
|
EEPROM_ByteWrite()
bool EEPROM_ByteWrite (uint32_t address, uint8_t * data)
Writes a byte of data to a specified address in the EEPROM device.
|
|
EEPROM_Close()
static void EEPROM_Close (void )[static]
Resets the EEPROM status.
|
None. |
EEPROM_DeviceAddressGet()
static uint8_t EEPROM_DeviceAddressGet (uint32_t address)[static]
Gets the device address of the EEPROM.
|
The 8-bit device address. |
EEPROM_ErrorGet()
EEPROM_STATUS_t EEPROM_ErrorGet (void )
Checks the type of the error encountered in the EEPROM operation.
|
EEPROM status code. |
EEPROM_IsBusy()
bool EEPROM_IsBusy (void )
Checks if the EEPROM device is busy.
|
|
EEPROM_PageRead()
bool EEPROM_PageRead (uint32_t address, uint8_t * data)
Reads the data of an entire page of the EEPROM device.
|
|
EEPROM_PageWrite()
bool EEPROM_PageWrite (uint32_t address, uint8_t * data)
Writes the data to an entire page of the EEPROM device.
|
|
EEPROM_SequentialRead()
bool EEPROM_SequentialRead (uint32_t address, uint8_t * data, size_t dataLength)
Reads n-bytes of data from a specified start address in the EEPROM device.
|
|
EEPROM_SequentialWrite()
bool EEPROM_SequentialWrite (uint32_t address, uint8_t * data, size_t dataLength)
Writes n-bytes of data to a specified start address in the EEPROM device.
|
|
EEPROM_Tasks()
static void EEPROM_Tasks (void )[static]
Performs the read and write operations of the driver.
|
None. |
EEPROM_UpdateWriteData()
static void EEPROM_UpdateWriteData (uint16_t dataLength, uint16_t pageCounter)[static]
Updates the write operation parameters.
|
None. |
EEPROM_WordAddressHighGet()
static uint8_t EEPROM_WordAddressHighGet (uint32_t address)[static]
Gets the upper byte of the word address from the target memory address.
|
The upper byte of the word address. |
EEPROM_WordAddressLowGet()
static uint8_t EEPROM_WordAddressLowGet (uint32_t address)[static]
Gets the lower byte of the word address from the target memory address.
|
The lower byte of the word address. |
2.3.2.1.3 Enumeration Type Documentation
EEPROM_STATUS
enum EEPROM_STATUS
Enumeration of the EEPROM driver status codes.
EEPROM_NO_ERROR |
EEPROM_ERROR |
EEPROM_I2C_TIMEOUT |
EEPROM_INVALID_PARAMETER |
EEPROM_NULL_ERROR |
EEPROM_COM_ERROR |
2.3.2.2 EEPROM_I2C
This file contains constants and API declarations for the EEPROM device.
2.3.2.2.1 Module description
This file contains constants and API declarations for the EEPROM device.
To ensure that the C driver runs properly, do not modify the I2C API prototypes. Refer to eeprom_i2c.c to configure the I2C interface implementation.
Functions
uint8_t EEPROM_I2C_Write (uint8_t deviceAddress, uint8_t *data, size_t writeLength)
Writes the data to the EEPROM via the I2C bus.
uint8_t EEPROM_I2C_Read (uint8_t deviceAddress, uint8_t *eepromAddress, size_t addressLength, uint8_t *readData, size_t readLength)
Reads the data from the EEPROM via the I2C bus.
bool EEPROM_AckPoll (uint8_t deviceAddress)
Checks if the data sent was acknowledged by the EEPROM device.
Variables
static const i2c_host_interface_t * EEPROM_I2C = &I2C1
An instance of the I2C Host driver interface for the EEPROM device.
2.3.2.2.2 Function Documentation
EEPROM_AckPoll()
bool EEPROM_AckPoll (uint8_t deviceAddress)
Checks if the data sent was acknowledged by the EEPROM device.
Initialize the I2C Host and the EEPROM device. |
|
|
EEPROM_I2C_Read()
uint8_t EEPROM_I2C_Read (uint8_t deviceAddress, uint8_t * eepromAddress, size_t addressLength, uint8_t * readData, size_t readLength)
Reads the data from the EEPROM via the I2C bus.
Initialize the I2C Host and the EEPROM device. |
|
EEPROM I2C status code. |
EEPROM_I2C_Write()
uint8_t EEPROM_I2C_Write (uint8_t deviceAddress, uint8_t * data, size_t writeLength)
Writes the data to the EEPROM via the I2C bus.
Initialize the I2C Host and the EEPROM device. |
|
EEPROM I2C status code. |
2.3.2.2.3 Variable Documentation
EEPROM_I2C
* EEPROM_I2C = &I2C1[static]
An instance of the I2C Host driver interface for the EEPROM device.
2.3.3 Class Documentation
2.3.3.1 EEPROM_DEVICE_CONTEXT Struct Reference
Contains the EEPROM driver context used in the API routines.
2.3.3.1.1 Detailed Description
Contains the EEPROM driver context used in the API routines.
#include <eeprom_i2c_types.h>
Public Attributes
bool busy
uint32_t startAddress
uint8_t deviceAddress
uint8_t wordAddress [EEPROM_I2C_WORD_LEN_BYTES]
uint8_t dataBuffer [EEPROM_I2C_PAGESIZE]
uint8_t * writePtr
size_t writeLength
bool firstWrite
uint8_t * readPtr
size_t readLength
bool switchToRead
2.3.3.1.2 Member Data Documentation
The documentation for this struct was generated from the following file:
source/source-files/
busy
bool EEPROM_DEVICE_CONTEXT::busy
Sets the software busy flag.
dataBuffer
uint8_t EEPROM_DEVICE_CONTEXT::dataBuffer[EEPROM_I2C_PAGESIZE]
Holds the data address buffer for the read and write operation.
deviceAddress
uint8_t EEPROM_DEVICE_CONTEXT::deviceAddress
Sets the I2C address of the device.
errorState
EEPROM_STATUS_t EEPROM_DEVICE_CONTEXT::errorState
Sets the error state of the operation.
firstWrite
bool EEPROM_DEVICE_CONTEXT::firstWrite
Sets the write operation flag.
readLength
size_t EEPROM_DEVICE_CONTEXT::readLength
Sets the read buffer length for the read operation.
readPtr
uint8_t* EEPROM_DEVICE_CONTEXT::readPtr
Pointer to read buffer for the read operation.
startAddress
uint32_t EEPROM_DEVICE_CONTEXT::startAddress
Sets the starting word address of the device.
switchToRead
bool EEPROM_DEVICE_CONTEXT::switchToRead
Sets the operation from Write to Read mode.
wordAddress
uint8_t EEPROM_DEVICE_CONTEXT::wordAddress[EEPROM_I2C_WORD_LEN_BYTES]
Holds the word address buffer for the device operation.
writeLength
size_t EEPROM_DEVICE_CONTEXT::writeLength
Sets the write buffer length for the write operation.
writePtr
uint8_t* EEPROM_DEVICE_CONTEXT::writePtr
Pointer to write buffer for the write operation.
2.3.3.2 eeprom_interface Struct Reference
Creates an instance of the EEPROM interface for the devices.
2.3.3.2.1 Detailed Description
Defines the EEPROM interface.
#include <eeprom_interface.h>
Public Attributes
bool(* SequentialWrite )(uint32_t address, uint8_t *data, size_t dataLength)
bool(* SequentialRead )(uint32_t address, uint8_t *data, size_t dataLength)
bool(* PageWrite )(uint32_t address, uint8_t *data)
bool(* PageRead )(uint32_t address, uint8_t *data)
bool(* ByteWrite )(uint32_t address, uint8_t *data)
bool(* ByteRead )(uint32_t address, uint8_t *data)
bool(* IsBusy )(void)
2.3.3.2.2 Member Data Documentation
The documentation for this struct was generated from the following file:
source/source-files/
ByteRead
bool(* EEPROM_INTERFACE::ByteRead) (uint32_t address, uint8_t *data)
ByteWrite
bool(* EEPROM_INTERFACE::ByteWrite) (uint32_t address, uint8_t *data)
IsBusy
bool(* EEPROM_INTERFACE::IsBusy) (void)
PageRead
bool(* EEPROM_INTERFACE::PageRead) (uint32_t address, uint8_t *data)
PageWrite
bool(* EEPROM_INTERFACE::PageWrite) (uint32_t address, uint8_t *data)
SequentialRead
bool(* EEPROM_INTERFACE::SequentialRead) (uint32_t address, uint8_t *data, size_t dataLength)
SequentialWrite
bool(* EEPROM_INTERFACE::SequentialWrite) (uint32_t address, uint8_t *data, size_t dataLength)
2.3.4 File Documentation
2.3.4.1 source/source-files/eeprom.c File Reference
Contains API definitions for the EEPROM driver.
#include "../../eeprom-lib/eeprom.h" #include "../../eeprom-lib/eeprom_interface.h" #include "../../eeprom-lib/eeprom_i2c_config.h" #include "../../eeprom-lib/eeprom_i2c_types.h" #include "../../eeprom-lib/eeprom_i2c.h" #include <stdlib.h>
2.3.4.1.1 Functions
static void EEPROM_UpdateWriteData (uint16_t dataLength, uint16_t pageCounter)
Updates the write operation parameters.
static uint8_t EEPROM_WordAddressLowGet (uint32_t address)
Gets the lower byte of the word address from the target memory address.
static uint8_t EEPROM_WordAddressHighGet (uint32_t address)
Gets the upper byte of the word address from the target memory address.
static uint8_t EEPROM_DeviceAddressGet (uint32_t address)
Gets the device address of the EEPROM.
static void EEPROM_Tasks (void)
Performs the read and write operations of the driver.
static void EEPROM_Close (void)
Resets the EEPROM status.
bool EEPROM_SequentialWrite (uint32_t address, uint8_t *data, size_t dataLength)
Writes n-bytes of data to a specified start address in the EEPROM device.
bool EEPROM_SequentialRead (uint32_t address, uint8_t *data, size_t dataLength)
Reads n-bytes of data from a specified start address in the EEPROM device.
bool EEPROM_PageWrite (uint32_t address, uint8_t *data)
Writes the data to an entire page of the EEPROM device.
bool EEPROM_PageRead (uint32_t address, uint8_t *data)
Reads the data of an entire page of the EEPROM device.
bool EEPROM_ByteWrite (uint32_t address, uint8_t *data)
Writes a byte of data to a specified address in the EEPROM device.
bool EEPROM_ByteRead (uint32_t address, uint8_t *data)
Reads a byte of data from a specified address in the EEPROM device.
EEPROM_STATUS_t EEPROM_ErrorGet (void)
Checks the type of the error encountered in the EEPROM operation.
bool EEPROM_IsBusy (void)
Checks if the EEPROM device is busy.
2.3.4.1.2 Macros
#define MIN(a, b) ((a) < (b) ? (a) : (b))
2.3.4.1.3 Variables
static size_t null = 0
static EEPROM_DEVICE_CONTEXT_t eepromStatus = {0}
2.3.4.1.4 Detailed Description
Contains API definitions for the EEPROM driver.
EEPROM generated driver source file.
2.3.4.1.5 Macro Definition Documentation
MIN
#define MIN( a, b) ((a) < (b) ? (a) : (b))
Computes the minimum of a and b.
2.3.4.1.6 Variable Documentation
eeprom_interface
const EEPROM_INTERFACE_t eeprom_interface
Initial value:
= { .SequentialWrite = EEPROM_SequentialWrite, .SequentialRead = EEPROM_SequentialRead, .PageWrite = EEPROM_PageWrite, .PageRead = EEPROM_PageRead, .ByteWrite = EEPROM_ByteWrite, .ByteRead = EEPROM_ByteRead, .IsBusy = EEPROM_IsBusy }
eepromStatus
EEPROM_DEVICE_CONTEXT_t eepromStatus = {0}[static]
null
size_t null = 0[static]
2.3.4.2 source/source-files/eeprom.h File Reference
#include "eeprom_interface.h"
2.3.4.2.1 Functions
bool EEPROM_ByteWrite (uint32_t address, uint8_t *data)
Writes a byte of data to a specified address in the EEPROM device.
bool EEPROM_ByteRead (uint32_t address, uint8_t *data)
Reads a byte of data from a specified address in the EEPROM device.
bool EEPROM_IsBusy (void)
Checks if the EEPROM device is busy.
bool EEPROM_SequentialWrite (uint32_t address, uint8_t *data, size_t dataLength)
Writes n-bytes of data to a specified start address in the EEPROM device.
bool EEPROM_SequentialRead (uint32_t address, uint8_t *data, size_t dataLength)
Reads n-bytes of data from a specified start address in the EEPROM device.
bool EEPROM_PageWrite (uint32_t address, uint8_t *data)
Writes the data to an entire page of the EEPROM device.
bool EEPROM_PageRead (uint32_t address, uint8_t *data)
Reads the data of an entire page of the EEPROM device.
EEPROM_STATUS_t EEPROM_ErrorGet (void)
Checks the type of the error encountered in the EEPROM operation.
2.3.4.2.2 Variables
2.3.4.2.3 Detailed Description
EEPROM generated driver header file.
2.3.4.2.4 Variable Documentation
eeprom_interface
const EEPROM_INTERFACE_t eeprom_interface
2.3.4.3 source/source-files/eeprom_i2c.c File Reference
This file contains API definitions for the EEPROM interface. This file can be modified to support other I2C drivers.
#include "../../eeprom-lib/eeprom_i2c_types.h" #include "../../eeprom-lib/eeprom_i2c_config.h" #include "../../eeprom-lib/eeprom_i2c.h" #include "../../i2c_host/i2c1.h"
2.3.4.3.1 Functions
uint8_t EEPROM_I2C_Write (uint8_t deviceAddress, uint8_t *data, size_t writeLength)
Writes the data to the EEPROM via the I2C bus.
uint8_t EEPROM_I2C_Read (uint8_t deviceAddress, uint8_t *eepromAddress, size_t addressLength, uint8_t *readData, size_t readLength)
Reads the data from the EEPROM via the I2C bus.
bool EEPROM_AckPoll (uint8_t deviceAddress)
Checks if the data sent was acknowledged by the EEPROM device.
2.3.4.3.2 Macros
#define EEPROM_I2C_ERROR (1U)
#define EEPROM_I2C_NO_ERROR (0U)
2.3.4.3.3 Variables
static const i2c_host_interface_t * EEPROM_I2C = &I2C1
An instance of the I2C Host driver interface for the EEPROM device.
2.3.4.3.4 Detailed Description
This file contains API definitions for the EEPROM interface. This file can be modified to support other I2C drivers.
EEPROM generated driver I2C interface source file.
2.3.4.3.5 Macro Definition Documentation
EEPROM_I2C_ERROR
#define EEPROM_I2C_ERROR (1U)
EEPROM_I2C_NO_ERROR
#define EEPROM_I2C_NO_ERROR (0U)
2.3.4.4 source/source-files/eeprom_i2c.h File Reference
#include <stddef.h>
2.3.4.4.1 Functions
uint8_t EEPROM_I2C_Write (uint8_t deviceAddress, uint8_t *data, size_t writeLength)
Writes the data to the EEPROM via the I2C bus.
uint8_t EEPROM_I2C_Read (uint8_t deviceAddress, uint8_t *eepromAddress, size_t addressLength, uint8_t *readData, size_t readLength)
Reads the data from the EEPROM via the I2C bus.
bool EEPROM_AckPoll (uint8_t deviceAddress)
Checks if the data sent was acknowledged by the EEPROM device.
2.3.4.4.2 Macros
EEPROM I2C Status Codes
I2C interface status codes.
#define EEPROM_I2C_NO_ERROR (0U)
#define EEPROM_I2C_ERROR (1U)
2.3.4.4.3 Detailed Description
EEPROM generated driver I2C interface header file.
2.3.4.4.4 Macro Definition Documentation
EEPROM_I2C_ERROR
#define EEPROM_I2C_ERROR (1U)
EEPROM_I2C_NO_ERROR
#define EEPROM_I2C_NO_ERROR (0U)
2.3.4.5 source/source-files/eeprom_i2c_config.h File Reference
This file contains device-specific constants for the EEPROM driver.
2.3.4.5.1 Macros
EEPROM device macros
EEPROM device size specification.
#define EEPROM_I2C_DEVICE_ADDR (0x54U)
#define EEPROM_I2C_WORD_LEN_BYTES (2U)
#define EEPROM_I2C_WORD_LEN_BIT (18U)
#define EEPROM_I2C_SIZE (262144U)
#define EEPROM_I2C_PAGESIZE (256U)
#define EEPROM_I2C_PAGES EEPROM_I2C_SIZE / EEPROM_I2C_PAGESIZE
2.3.4.5.2 Detailed Description
This file contains device-specific constants for the EEPROM driver.
EEPROM generated driver configuration header file.
2.3.4.5.3 Macro Definition Documentation
EEPROM_I2C_DEVICE_ADDR
#define EEPROM_I2C_DEVICE_ADDR (0x54U)
EEPROM_I2C_PAGES
#define EEPROM_I2C_PAGES EEPROM_I2C_SIZE / EEPROM_I2C_PAGESIZE
EEPROM_I2C_PAGESIZE
#define EEPROM_I2C_PAGESIZE (256U)
EEPROM_I2C_SIZE
#define EEPROM_I2C_SIZE (262144U)
EEPROM_I2C_WORD_LEN_BIT
#define EEPROM_I2C_WORD_LEN_BIT (18U)
EEPROM_I2C_WORD_LEN_BYTES
#define EEPROM_I2C_WORD_LEN_BYTES (2U)
2.3.4.6 source/source-files/eeprom_i2c_types.h File Reference
This file contains type definitions for the EEPROM driver.
#include "eeprom_i2c_config.h" #include "stdint.h" #include "stdbool.h" #include "stdlib.h"
2.3.4.6.1 Data structures
struct EEPROM_DEVICE_CONTEXT
Contains the EEPROM driver context used in the API routines.
2.3.4.6.2 Typedefs
typedef enum EEPROM_STATUS EEPROM_STATUS_t
typedef struct EEPROM_DEVICE_CONTEXT EEPROM_DEVICE_CONTEXT_t
2.3.4.6.3 Enumerations
enum EEPROM_STATUS { EEPROM_NO_ERROR = 0U, EEPROM_ERROR = 1U, EEPROM_I2C_TIMEOUT = 3U, EEPROM_INVALID_PARAMETER = 104U, EEPROM_NULL_ERROR = 105U, EEPROM_COM_ERROR = 106U }
Enumeration of the EEPROM driver status codes.
2.3.4.6.4 Detailed Description
This file contains type definitions for the EEPROM driver.
EEPROM generated driver data types header file.
2.3.4.6.5 Typedef Documentation
EEPROM_DEVICE_CONTEXT_t
typedef struct EEPROM_DEVICE_CONTEXT EEPROM_DEVICE_CONTEXT_t
EEPROM_STATUS_t
typedef enum EEPROM_STATUS EEPROM_STATUS_t
2.3.4.7 source/source-files/eeprom_interface.h File Reference
#include "eeprom_i2c_types.h"
2.3.4.7.1 Data structures
struct EEPROM_INTERFACE
Defines the EEPROM interface.
2.3.4.7.2 Typedefs
typedef struct EEPROM_INTERFACE EEPROM_INTERFACE_t
2.3.4.7.3 Typedef Documentation
EEPROM_INTERFACE_t
typedef struct EEPROM_INTERFACE EEPROM_INTERFACE_t