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

Functions

e2p_device_spi_attribute_te2p_device_spi_get_attribute (hpm_eeprom_device_t *device)
 Get eeprom spi device attribute. More...
 
hpm_stat_t e2p_device_spi_register_param (hpm_eeprom_device_t *device, void *host_info, uint32_t dev_id)
 Register eeprom spi device parameter to device structure. More...
 
hpm_stat_t e2p_device_spi_init (hpm_eeprom_device_t *device)
 Initialize eeprom spi device, hw init(clock and pin) and spi master init. More...
 
hpm_stat_t e2p_device_spi_deinit (hpm_eeprom_device_t *device)
 De-initialize eeprom spi device. More...
 
static hpm_stat_t e2p_device_spi_page_read (hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data, bool is_cross_page)
 Read data from eeprom spi device from one page. More...
 
hpm_stat_t e2p_device_spi_read (hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
 Read data from eeprom spi device. More...
 
static hpm_stat_t e2p_device_spi_write_enable (hpm_eeprom_device_t *device, spi_control_config_t *control_config)
 Write Enable instruction to set the write enable latch (WEL) bit in the status register to a logic 1. More...
 
static bool e2p_device_spi_write_in_progress (hpm_eeprom_device_t *device, spi_control_config_t *control_config)
 Read data from eeprom spi device. More...
 
static hpm_stat_t e2p_device_spi_page_write (hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data, bool is_cross_page)
 Write data to eeprom spi device from one page. More...
 
hpm_stat_t e2p_device_spi_write (hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
 Write data to eeprom spi device. More...
 

Variables

static const e2p_device_spi_attribute_t supported_e2p_spi_device_list []
 eeprom spi supported device information list More...
 
static e2p_device_ops_t hpm_e2p_spi_device_ops
 eeprom spi device operations structure More...
 

Function Documentation

◆ e2p_device_spi_deinit()

hpm_stat_t e2p_device_spi_deinit ( hpm_eeprom_device_t device)

De-initialize eeprom spi device.

Parameters
[in]devicePointer to eeprom device structure
Return values
status_success

◆ e2p_device_spi_get_attribute()

e2p_device_spi_attribute_t* e2p_device_spi_get_attribute ( hpm_eeprom_device_t device)

Get eeprom spi device attribute.

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

◆ e2p_device_spi_init()

hpm_stat_t e2p_device_spi_init ( hpm_eeprom_device_t device)

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

Parameters
[in]devicePointer to eeprom device structure
Return values
status_successor status_fail if initialization fails or status_invalid_argument if configuration is invalid

◆ e2p_device_spi_page_read()

static hpm_stat_t e2p_device_spi_page_read ( hpm_eeprom_device_t device,
uint32_t  data_addr,
uint32_t  len,
uint8_t *  data,
bool  is_cross_page 
)
static

Read data from eeprom spi device from one page.

Parameters
[in]devicePointer to eeprom device structure
[in]data_addrData address to read from
[in]lenLength of data to read
[in]dataPointer to buffer to store read data
[in]is_cross_pageIndicate whether the read operation crosses a page boundary
Return values
status_successor status_fail if read operation fails or status_invalid_argument if configuration is invalid or status_spi_master_busy if spi bus is busy or status_timeout if spi transfer timeout
Note
if is_cross_page is true, the MSB address bit will be set in the instruction;
Reading the device via the SO pin requires the following sequence. After the C̅S̅ line is pulled low to select a device, the Read op-code is transmitted via the SI line followed by the byte address to be read. Upon completion, any data on the SI line will be ignored. The data (D7 - D0) at the specified address is then shifted out onto the SO line. If only one byte is to be read, the C̅S̅ line should be driven high after the data comes out. The read sequence can be continued since the byte address is automatically incremented and data will continue to be shifted out. When the highest address is reached, the address counter will roll over to the lowest address allowing the entire memory to be read in one continuous read cycle.

◆ e2p_device_spi_page_write()

static hpm_stat_t e2p_device_spi_page_write ( hpm_eeprom_device_t device,
uint32_t  data_addr,
uint32_t  len,
uint8_t *  data,
bool  is_cross_page 
)
static

Write data to eeprom spi device from one page.

Parameters
[in]devicePointer to eeprom device structure
[in]data_addrData address to write to
[in]lenLength of data to write
[in]dataPointer to buffer to store write data
[in]is_cross_pageIndicate whether the write operation crosses a page boundary
Return values
status_successor status_fail if read operation fails or status_invalid_argument if configuration is invalid or status_spi_master_busy if spi bus is busy or status_timeout if spi transfer timeout
Note
if is_cross_page is true, the MSB address bit will be set in the instruction;
In order to program the device, two separate instructions must be executed. First, the device must be write enabled via the Write Enable (WREN) instruction. Then a Write instruction may be executed. During an internal write cycle, all commands will be ignored except the RDSR instruction. A Write Instruction requires the following sequence. After the C̅S̅ line is pulled low to select the device, the Write op-code is transmitted via the SI line followed by the byte address and the data (D7 - D0) to be programmed. Programming will start after the C̅S̅ pin is brought high.

◆ e2p_device_spi_read()

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

Read data from eeprom spi device.

Parameters
[in]devicePointer to eeprom device structure
[in]data_addrData address to read from
[in]lenLength of data to read
[in]dataPointer to buffer to store read data
Return values
status_successor status_fail if read operation fails or status_invalid_argument if configuration is invalid or status_spi_master_busy if spi bus is busy or status_timeout if spi transfer timeout

◆ e2p_device_spi_register_param()

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

Register eeprom spi device parameter to device structure.

Parameters
[in]devicePointer to eeprom device structure
[in]host_infoPointer to eeprom spi host configuration structure
[in]dev_idEeprom device id
Return values
status_successor status_fail if dev_id is invalid

◆ e2p_device_spi_write()

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

Write data to eeprom spi 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 read operation fails or status_invalid_argument if configuration is invalid or status_spi_master_busy if spi bus is busy or status_timeout if spi transfer timeout
Note
This function will handle page splitting and borrow bits internally, and call e2p_device_spi_page_write; so the user does not need to worry about these details.

◆ e2p_device_spi_write_enable()

static hpm_stat_t e2p_device_spi_write_enable ( hpm_eeprom_device_t device,
spi_control_config_t control_config 
)
static

Write Enable instruction to set the write enable latch (WEL) bit in the status register to a logic 1.

Parameters
[in]devicePointer to eeprom device structure
[in]control_configPointer to spi control configuration structure
Return values
status_successor status_fail if read operation fails or status_invalid_argument if configuration is invalid or status_spi_master_busy if spi bus is busy or status_timeout if spi transfer timeout
Note
The device will power-up in the write disable state when VCC is applied. All programming instructions must therefore be preceded by a Write Enable instruction. After proceed a write enable instruction, ready and write enable status of the device can be read by the RDSR instruction.

◆ e2p_device_spi_write_in_progress()

static bool e2p_device_spi_write_in_progress ( hpm_eeprom_device_t device,
spi_control_config_t control_config 
)
static

Read data from eeprom spi device.

Parameters
[in]devicePointer to eeprom device structure
[in]control_configPointer to spi control configuration structure
Return values
trueWrite in progress; false Write cycle completed
Note
After Write instruction, the Ready/Busy status of the device can be determined by initiating a Read Status Register (RDSR) instruction. If Bit 0 = 1, the Write cycle is still in progress. If Bit 0 = 0, the Write cycle has ended.

Variable Documentation

◆ hpm_e2p_spi_device_ops

e2p_device_ops_t hpm_e2p_spi_device_ops
static
Initial value:
= {
}
hpm_stat_t e2p_device_spi_deinit(hpm_eeprom_device_t *device)
De-initialize eeprom spi device.
Definition: e2p_device_spi.c:130
hpm_stat_t e2p_device_spi_read(hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
Read data from eeprom spi device.
Definition: e2p_device_spi.c:195
hpm_stat_t e2p_device_spi_init(hpm_eeprom_device_t *device)
Initialize eeprom spi device, hw init(clock and pin) and spi master init.
Definition: e2p_device_spi.c:91
hpm_stat_t e2p_device_spi_write(hpm_eeprom_device_t *device, uint32_t data_addr, uint32_t len, uint8_t *data)
Write data to eeprom spi device.
Definition: e2p_device_spi.c:456

eeprom spi device operations structure

◆ supported_e2p_spi_device_list

const e2p_device_spi_attribute_t supported_e2p_spi_device_list[]
static
Initial value:
= {
{ .addr_bytes = 1, .page_size = 8, .timeout = 5, .max_freq = 5000000, .borrow_bits = 0 },
{ .addr_bytes = 1, .page_size = 8, .timeout = 5, .max_freq = 5000000, .borrow_bits = 1 },
{ .addr_bytes = 1, .page_size = 16, .timeout = 5, .max_freq = 20000000, .borrow_bits = 0 },
{ .addr_bytes = 1, .page_size = 16, .timeout = 5, .max_freq = 20000000, .borrow_bits = 1 },
{ .addr_bytes = 1, .page_size = 16, .timeout = 4, .max_freq = 5000000, .borrow_bits = 0 },
{ .addr_bytes = 1, .page_size = 16, .timeout = 4, .max_freq = 5000000, .borrow_bits = 1 },
{ .addr_bytes = 1, .page_size = 16, .timeout = 5, .max_freq = 10000000, .borrow_bits = 0 },
{ .addr_bytes = 1, .page_size = 16, .timeout = 5, .max_freq = 10000000, .borrow_bits = 1 },
{ .addr_bytes = 2, .page_size = 16, .timeout = 5, .max_freq = 10000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 32, .timeout = 5, .max_freq = 20000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 32, .timeout = 4, .max_freq = 5000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 32, .timeout = 5, .max_freq = 10000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 32, .timeout = 5, .max_freq = 5000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 64, .timeout = 5, .max_freq = 5000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 64, .timeout = 5, .max_freq = 10000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 64, .timeout = 5, .max_freq = 20000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 128, .timeout = 5, .max_freq = 10000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 128, .timeout = 5, .max_freq = 16000000, .borrow_bits = 0 },
{ .addr_bytes = 2, .page_size = 128, .timeout = 5, .max_freq = 20000000, .borrow_bits = 0 },
{ .addr_bytes = 3, .page_size = 256, .timeout = 5, .max_freq = 16000000, .borrow_bits = 0 },
{ .addr_bytes = 3, .page_size = 256, .timeout = 5, .max_freq = 10000000, .borrow_bits = 0 },
{ .addr_bytes = 3, .page_size = 256, .timeout = 10, .max_freq = 5000000, .borrow_bits = 0 },
{ .addr_bytes = 3, .page_size = 256, .timeout = 6, .max_freq = 20000000, .borrow_bits = 0 },
{ .addr_bytes = 3, .page_size = 512, .timeout = 5, .max_freq = 10000000, .borrow_bits = 0 },
}

eeprom spi supported device information list