HPM SDK
HPMicro Software Development Kit
e2p_device_i2c.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "e2p_device_i2c.h"

Functions

e2p_device_i2c_attribute_te2p_device_i2c_get_attribute (hpm_eeprom_device_t *device)
 Get eeprom i2c device attribute. More...
 
hpm_stat_t e2p_device_i2c_register_param (hpm_eeprom_device_t *device, void *host_info, uint32_t dev_id)
 Register eeprom i2c device parameter to device structure. More...
 
hpm_stat_t e2p_device_i2c_init (hpm_eeprom_device_t *device)
 Initialize eeprom i2c device, hw init(clock and pin) and i2c master init. More...
 
hpm_stat_t e2p_device_i2c_deinit (hpm_eeprom_device_t *device)
 Deinitialize eeprom i2c device. More...
 
static uint32_t e2p_device_i2c_calculate_max_addr (uint8_t borrow_bits, uint32_t addr_bytes)
 Calculate the max address of eeprom device, depending on borrow_bits and addr_bytes. More...
 
hpm_stat_t e2p_device_i2c_page_read (hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
 Read data from eeprom i2c device. More...
 
hpm_stat_t e2p_device_i2c_read (hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
 Read data from eeprom i2c device. More...
 
static bool e2p_device_i2c_write_in_progress (hpm_eeprom_device_t *device)
 Check if eeprom i2c device write cycle is in progress. More...
 
static hpm_stat_t e2p_device_i2c_page_write (hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
 Write data to eeprom i2c device, page write, not consider borrow_bits. More...
 
hpm_stat_t e2p_device_i2c_write (hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
 Write data to eeprom i2c device. More...
 

Variables

static const e2p_device_i2c_attribute_t supported_e2p_i2c_device_list []
 eeprom i2c supported device information list More...
 
static const uint32_t eeprom_common_size [] = {0x100, 0x10000}
 
static e2p_device_ops_t hpm_e2p_i2c_device_ops
 eeprom i2c device operations structure More...
 

Function Documentation

◆ e2p_device_i2c_calculate_max_addr()

static uint32_t e2p_device_i2c_calculate_max_addr ( uint8_t  borrow_bits,
uint32_t  addr_bytes 
)
static

Calculate the max address of eeprom device, depending on borrow_bits and addr_bytes.

Parameters
[in]borrow_bitsNumber of borrow bits
[in]addr_bytesNumber of address bytes
Return values
max_addrMaximum address of eeprom device

◆ e2p_device_i2c_deinit()

hpm_stat_t e2p_device_i2c_deinit ( hpm_eeprom_device_t device)

Deinitialize eeprom i2c device.

De-initialize eeprom i2c device.

◆ e2p_device_i2c_get_attribute()

e2p_device_i2c_attribute_t* e2p_device_i2c_get_attribute ( hpm_eeprom_device_t device)

Get eeprom i2c device attribute.

Parameters
[in]devicePointer to eeprom device structure
Return values
Pointerto eeprom i2c device attribute structure

◆ e2p_device_i2c_init()

hpm_stat_t e2p_device_i2c_init ( hpm_eeprom_device_t device)

Initialize eeprom i2c device, hw init(clock and pin) and i2c master init.

Parameters
[in]devicePointer to eeprom device structure
Return values
status_success,orstatus_fail if initialization fails

◆ e2p_device_i2c_page_read()

hpm_stat_t e2p_device_i2c_page_read ( hpm_eeprom_device_t device,
uint32_t  data_addr,
uint32_t  len,
uint8_t *  data 
)

Read data from eeprom i2c device.

Parameters
[in]devicePointer to eeprom device structure
[in]data_addrData address to read from
[in]lenLength of data to read
[out]dataPointer to buffer to store read data
Return values
status_successor status_fail if reading fails or status_invalid_argument if invalid argument is detected or status_timeout if timeout occurs during reading or status_i2c_no_addr_hit if no acknowledge from slave device

◆ e2p_device_i2c_page_write()

static hpm_stat_t e2p_device_i2c_page_write ( hpm_eeprom_device_t device,
uint32_t  data_addr,
uint32_t  len,
uint8_t *  data 
)
static

Write data to eeprom i2c device, page write, not consider borrow_bits.

Parameters
[in]devicePointer to eeprom device structure
[in]data_addrData address to write to
[in]lenLength of data to write
[in]dataPointer to buffer containing data to write
Return values
status_successor status_fail if writing fails or status_timeout if timeout occurs during writing or status_i2c_no_addr_hit if no acknowledge from slave device or status_invalid_argument if invalid argument is detected

◆ e2p_device_i2c_read()

hpm_stat_t e2p_device_i2c_read ( hpm_eeprom_device_t device,
uint32_t  data_addr,
uint32_t  len,
uint8_t *  data 
)

Read data from eeprom i2c device.

Parameters
[in]devicePointer to eeprom device structure
[in]data_addrData address to read from
[in]lenLength of data to read
[out]dataPointer to buffer to store read data
Return values
status_successor status_fail if reading fails or status_invalid_argument if invalid argument is detected or status_timeout if timeout occurs during reading or status_i2c_no_addr_hit if no acknowledge from slave device
Note
This function will handle page splitting and borrow bits internally, and call e2p_device_i2c_page_read; so the user does not need to worry about these details.

◆ e2p_device_i2c_register_param()

hpm_stat_t e2p_device_i2c_register_param ( hpm_eeprom_device_t device,
void *  host_info,
uint32_t  dev_id 
)

Register eeprom i2c device parameter to device structure.

Parameters
[in]devicePointer to eeprom device structure
[in]host_infoPointer to eeprom i2c host configuration structure
[in]dev_idEeprom device id
Return values
status_success,orstatus_fail if dev_id is invalid

◆ e2p_device_i2c_write()

hpm_stat_t e2p_device_i2c_write ( hpm_eeprom_device_t device,
uint32_t  data_addr,
uint32_t  len,
uint8_t *  data 
)

Write data to eeprom i2c device.

Parameters
[in]devicePointer to eeprom device structure
[in]data_addrData address to write to
[in]lenLength of data to write
[in]dataPointer to buffer containing data to write
Return values
status_successor status_fail if writing fails or status_timeout if timeout occurs during writing or status_i2c_no_addr_hit if no acknowledge from slave device or status_invalid_argument if invalid argument is detected
Note
This function will handle page splitting and borrow bits internally, and call e2p_device_i2c_page_write; so the user does not need to worry about these details.

◆ e2p_device_i2c_write_in_progress()

static bool e2p_device_i2c_write_in_progress ( hpm_eeprom_device_t device)
static

Check if eeprom i2c device write cycle is in progress.

Parameters
[in]devicePointer to eeprom device structure
Return values
trueif write cycle is in progress, false otherwise
Note
Once the internally-timed write cycle has started and the EEPROM inputs are disabled, acknowledge polling can be initiated. This involves sending a start condition followed by the device addressword. The read/write bit is representative of the operation desired. Only if the internal write cycle has completed will the EEPROM respond with a zero, allowing the read or write sequence to continue.

Variable Documentation

◆ eeprom_common_size

const uint32_t eeprom_common_size[] = {0x100, 0x10000}
static

◆ hpm_e2p_i2c_device_ops

e2p_device_ops_t hpm_e2p_i2c_device_ops
static
Initial value:
= {
}
hpm_stat_t e2p_device_i2c_deinit(hpm_eeprom_device_t *device)
Deinitialize eeprom i2c device.
Definition: e2p_device_i2c.c:111
hpm_stat_t e2p_device_i2c_write(hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
Write data to eeprom i2c device.
Definition: e2p_device_i2c.c:403
hpm_stat_t e2p_device_i2c_init(hpm_eeprom_device_t *device)
Initialize eeprom i2c device, hw init(clock and pin) and i2c master init.
Definition: e2p_device_i2c.c:89
hpm_stat_t e2p_device_i2c_read(hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
Read data from eeprom i2c device.
Definition: e2p_device_i2c.c:201

eeprom i2c device operations structure

◆ supported_e2p_i2c_device_list

const e2p_device_i2c_attribute_t supported_e2p_i2c_device_list[]
static
Initial value:
= {
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 8, .timeout = 5, .borrow_bits = 0 },
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 16, .timeout = 4, .borrow_bits = 0 },
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 16, .timeout = 4, .borrow_bits = 1 },
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 16, .timeout = 4, .borrow_bits = 2 },
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 16, .timeout = 4, .borrow_bits = 3 },
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 16, .timeout = 5, .borrow_bits = 0 },
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 16, .timeout = 5, .borrow_bits = 1 },
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 16, .timeout = 5, .borrow_bits = 2 },
{ .dev_addr = 0x50, .addr_bytes = 1, .page_size = 16, .timeout = 5, .borrow_bits = 3 },
{ .dev_addr = 0x50, .addr_bytes = 2, .page_size = 32, .timeout = 4, .borrow_bits = 0 },
{ .dev_addr = 0x50, .addr_bytes = 2, .page_size = 32, .timeout = 10, .borrow_bits = 0 },
{ .dev_addr = 0x50, .addr_bytes = 2, .page_size = 32, .timeout = 5, .borrow_bits = 0 },
{ .dev_addr = 0x50, .addr_bytes = 2, .page_size = 64, .timeout = 5, .borrow_bits = 0 },
{ .dev_addr = 0x50, .addr_bytes = 2, .page_size = 128, .timeout = 5, .borrow_bits = 0 },
{ .dev_addr = 0x50, .addr_bytes = 2, .page_size = 256, .timeout = 5, .borrow_bits = 1 },
{ .dev_addr = 0x50, .addr_bytes = 2, .page_size = 256, .timeout = 10, .borrow_bits = 2 },
}

eeprom i2c supported device information list