This module contains APIs to program and use the I2C LLD module. The APIs can be used by other drivers to get access to I2C and also by application to initiate transaction operations.
The I2C LLD header file should be included in an application as follows:
Files | |
file | i2c_lld.h |
I2C LLD Driver API/interface file. | |
Data Structures | |
struct | I2CLLD_Transaction |
I2C Transaction. More... | |
struct | I2CLLD_Message |
I2C Message. More... | |
struct | I2C_ExtendedParams |
Data structure used with I2C_lld_write(), I2C_lld_writeIntr(), I2C_lld_read(), I2C_lld_readIntr() More... | |
struct | I2C_Memory_ExtendedParams |
Data structure used with I2C_lld_mem_write(), I2C_lld_mem_writeIntr(), I2C_lld_mem_read(), I2C_lld_mem_readIntr() More... | |
struct | I2CLLD_targetTransaction |
I2C Target Transaction. More... | |
struct | I2CLLD_Object |
I2C Driver Object. More... | |
Functions | |
int32_t | I2C_lld_init (I2CLLD_Handle handle) |
This API Initializes the I2C instance. More... | |
int32_t | I2C_lld_deInit (I2CLLD_Handle handle) |
This API De-Initializes the I2C instance. More... | |
int32_t | I2C_lld_Transaction_init (I2CLLD_Transaction *transaction) |
API to set default values of I2CLLD_Transaction in transaction. More... | |
int32_t | I2C_lld_Message_init (I2CLLD_Message *msg) |
API to set default values of I2CLLD_Message in msg. More... | |
int32_t | I2C_lld_write (I2CLLD_Handle handle, I2C_ExtendedParams *extendedParams, uint32_t timeout) |
API to initiate the write transaction in polled mode. More... | |
int32_t | I2C_lld_writeIntr (I2CLLD_Handle handle, I2C_ExtendedParams *extendedParams) |
API to initiate the write transaction in Interrupt mode. More... | |
int32_t | I2C_lld_read (I2CLLD_Handle handle, I2C_ExtendedParams *extendedParams, uint32_t timeout) |
API to initiate the read transaction in polled mode. More... | |
int32_t | I2C_lld_readIntr (I2CLLD_Handle handle, I2C_ExtendedParams *extendedParams) |
API to initiate the read transaction in Interrupt mode. More... | |
int32_t | I2C_lld_mem_write (I2CLLD_Handle handle, I2C_Memory_ExtendedParams *mem_extendedParams, uint32_t timeout) |
Function to initiate a transfer from I2C in interrupt mode. More... | |
int32_t | I2C_lld_mem_writeIntr (I2CLLD_Handle handle, I2C_Memory_ExtendedParams *mem_extendedParams) |
Function to initiate a transfer from I2C in interrupt mode. More... | |
int32_t | I2C_lld_mem_read (I2CLLD_Handle handle, I2C_Memory_ExtendedParams *mem_extendedParams, uint32_t timeout) |
Function to initiate a transfer from I2C in interrupt mode. More... | |
int32_t | I2C_lld_mem_readIntr (I2CLLD_Handle handle, I2C_Memory_ExtendedParams *mem_extendedParams) |
Function to initiate a transfer from I2C in interrupt mode. More... | |
int32_t | I2C_lld_transferPoll (I2CLLD_Handle handle, I2CLLD_Message *msg) |
Function to initiate a transfer from I2C in polled mode. More... | |
int32_t | I2C_lld_transferIntr (I2CLLD_Handle handle, I2CLLD_Message *msg) |
Function to initiate a transfer from I2C in interrupt mode. More... | |
int32_t | I2C_lld_targetTransferIntr (I2CLLD_Handle handle, I2CLLD_targetTransaction *txn) |
Function to initiate a transfer from I2C in target mode. More... | |
int32_t | I2C_lld_probe (I2CLLD_Handle handle, uint32_t targetAddr) |
Function to probe I2C. More... | |
int32_t | I2C_lld_setBusFrequency (I2CLLD_Handle handle, uint32_t busFrequency) |
Function to set the bus frequency. More... | |
int32_t | I2C_lld_recoverBus (I2CLLD_Handle handle, uint32_t i2cDelay) |
Function to recover the bus in case of lockup. More... | |
void | I2C_lld_controllerIsr (void *args) |
This is the I2C Controller ISR and can be used as IRQ handler in Controller mode. More... | |
void | I2C_lld_targetIsr (void *args) |
This is the I2C Target ISR and can be used as IRQ handler in Target mode. More... | |
Typedefs | |
typedef uint32_t(* | I2C_Clock_getTicks) (void) |
The definition of a get System Tick function used by the I2C driver to keep track of time. More... | |
typedef uint32_t(* | I2C_Clock_usecToTicks) (uint64_t usecs) |
The definition of a micro seconds to ticks function used by the I2C driver to get ticks from microseconds. More... | |
typedef void(* | I2C_Clock_uSleep) (uint32_t usec) |
The definition of a sleep function used by the I2C driver for delay. More... | |
typedef void(* | I2C_lld_transferCompleteCallback) (void *args, const I2CLLD_Message *msg, int32_t transferStatus) |
The definition of a transfer completion callback function used by the I2C driver when used in Controller Callback Mode. More... | |
typedef void(* | I2C_lld_targetTransferCompleteCallback) (void *args, const I2CLLD_targetTransaction *targetTxn, int32_t transferStatus) |
The definition of a transfer completion callback function used by the I2C driver when used in Target Mode. More... | |
typedef struct I2CLLD_Object * | I2CLLD_Handle |
Macros | |
#define | I2C_MAX_NUM_OWN_TARGET_ADDR (4U) |
Return status | |
#define | I2C_STS_SUCCESS ((int32_t) 0) |
Return status when the API execution was successful. More... | |
#define | I2C_STS_ERR ((int32_t)-1) |
Return status when the API execution was not successful due to a generic Error. More... | |
#define | I2C_STS_ERR_TIMEOUT ((int32_t)-2) |
Return status when the API execution was not successful due to a time out. More... | |
#define | I2C_STS_ERR_INVALID_PARAM ((int32_t)-3) |
Return status when the API execution failed due invalid parameters. More... | |
#define | I2C_STS_ERR_BUS_BUSY ((int32_t)-4) |
Return status when the API execution failed due to driver busy. More... | |
#define | I2C_STS_ERR_NO_ACK ((int32_t)-5) |
Return status when the API execution failed due to no Acknowledgement from target. More... | |
#define | I2C_STS_ERR_ARBITRATION_LOST ((int32_t)-6) |
Return status when the API execution failed due to loss in arbitration during transmission. More... | |
#define | I2C_STS_ERR_ACCESS_ERROR ((int32_t)-7) |
Timeout values | |
#define | I2C_NO_WAIT ((uint32_t)0) |
Value to use when needing a timeout of zero or NO timeout, return immediately on resource not available. More... | |
#define | I2C_WAIT_FOREVER ((uint32_t)-1) |
Value to use when needing a timeout of infinity or wait forver until resource is available. More... | |
I2C Driver states | |
#define | I2C_STATE_RESET ((uint8_t) 0U) |
I2C driver is in Reset State prior to driver init and post driver deinit. More... | |
#define | I2C_STATE_IDLE ((uint8_t) 1U) |
I2C driver accepts runtime APIs only Ready State, otherwise return error. More... | |
#define | I2C_STATE_BUSY ((uint8_t) 2U) |
I2C driver is busy performing operation with peripherals, return error when APIs are invoked. More... | |
#define | I2C_STATE_ERROR ((uint8_t) 3U) |
I2C driver ran into error, returns error for all APIs other than deinit in this state. More... | |
MACROS used to select one of the standardized bus bit rates for | |
#define | I2C_100KHZ ((uint8_t) 0U) |
I2C bus frequency : 100KHz. More... | |
#define | I2C_400KHZ ((uint8_t) 1U) |
I2C bus frequency : 400KHz. More... | |
#define | I2C_1P0MHZ ((uint8_t) 2U) |
I2C bus frequency : 1.0MHz. More... | |
#define | I2C_3P4MHZ ((uint8_t) 3U) |
I2C bus frequency : 3.4MHz. More... | |
MACROS for the possible values of Memory Write/Read API parameter. | |
#define | I2C_MEM_ADDR_SIZE_8_BITS ((uint8_t) 1U) |
I2C Target Internal Memory address 8 bits. More... | |
#define | I2C_MEM_ADDR_SIZE_16_BITS ((uint8_t) 2U) |
I2C Target Internal Memory address 16 bits. More... | |
MACROS used to define the state of the I2C Driver State Machine | |
#define | I2C_WRITE_STATE ((uint8_t) 10U) |
I2C is in Write state. More... | |
#define | I2C_READ_STATE ((uint8_t) 11U) |
I2C is in Write state. More... | |
#define | I2C_TARGET_XFER_STATE ((uint8_t) 12U) |
I2C is trasferring in target mode. More... | |
#define | I2C_TARGET_RESTART_STATE ((uint8_t) 13U) |
I2C is restarting trasfer in target mode. More... | |
#define I2C_MAX_NUM_OWN_TARGET_ADDR (4U) |
#define I2C_STS_SUCCESS ((int32_t) 0) |
Return status when the API execution was successful.
#define I2C_STS_ERR ((int32_t)-1) |
Return status when the API execution was not successful due to a generic Error.
#define I2C_STS_ERR_TIMEOUT ((int32_t)-2) |
Return status when the API execution was not successful due to a time out.
#define I2C_STS_ERR_INVALID_PARAM ((int32_t)-3) |
Return status when the API execution failed due invalid parameters.
#define I2C_STS_ERR_BUS_BUSY ((int32_t)-4) |
Return status when the API execution failed due to driver busy.
#define I2C_STS_ERR_NO_ACK ((int32_t)-5) |
Return status when the API execution failed due to no Acknowledgement from target.
#define I2C_STS_ERR_ARBITRATION_LOST ((int32_t)-6) |
Return status when the API execution failed due to loss in arbitration during transmission.
#define I2C_STS_ERR_ACCESS_ERROR ((int32_t)-7) |
#define I2C_NO_WAIT ((uint32_t)0) |
Value to use when needing a timeout of zero or NO timeout, return immediately on resource not available.
#define I2C_WAIT_FOREVER ((uint32_t)-1) |
Value to use when needing a timeout of infinity or wait forver until resource is available.
#define I2C_STATE_RESET ((uint8_t) 0U) |
I2C driver is in Reset State prior to driver init and post driver deinit.
#define I2C_STATE_IDLE ((uint8_t) 1U) |
I2C driver accepts runtime APIs only Ready State, otherwise return error.
#define I2C_STATE_BUSY ((uint8_t) 2U) |
I2C driver is busy performing operation with peripherals, return error when APIs are invoked.
#define I2C_STATE_ERROR ((uint8_t) 3U) |
I2C driver ran into error, returns error for all APIs other than deinit in this state.
#define I2C_100KHZ ((uint8_t) 0U) |
I2C bus frequency : 100KHz.
#define I2C_400KHZ ((uint8_t) 1U) |
I2C bus frequency : 400KHz.
#define I2C_1P0MHZ ((uint8_t) 2U) |
I2C bus frequency : 1.0MHz.
#define I2C_3P4MHZ ((uint8_t) 3U) |
I2C bus frequency : 3.4MHz.
#define I2C_MEM_ADDR_SIZE_8_BITS ((uint8_t) 1U) |
I2C Target Internal Memory address 8 bits.
#define I2C_MEM_ADDR_SIZE_16_BITS ((uint8_t) 2U) |
I2C Target Internal Memory address 16 bits.
#define I2C_WRITE_STATE ((uint8_t) 10U) |
I2C is in Write state.
#define I2C_READ_STATE ((uint8_t) 11U) |
I2C is in Write state.
#define I2C_TARGET_XFER_STATE ((uint8_t) 12U) |
I2C is trasferring in target mode.
#define I2C_TARGET_RESTART_STATE ((uint8_t) 13U) |
I2C is restarting trasfer in target mode.
typedef uint32_t(* I2C_Clock_getTicks) (void) |
The definition of a get System Tick function used by the I2C driver to keep track of time.
typedef uint32_t(* I2C_Clock_usecToTicks) (uint64_t usecs) |
The definition of a micro seconds to ticks function used by the I2C driver to get ticks from microseconds.
usecs | Micro Seconds |
typedef void(* I2C_Clock_uSleep) (uint32_t usec) |
The definition of a sleep function used by the I2C driver for delay.
usec | Micro Seconds |
typedef void(* I2C_lld_transferCompleteCallback) (void *args, const I2CLLD_Message *msg, int32_t transferStatus) |
The definition of a transfer completion callback function used by the I2C driver when used in Controller Callback Mode.
args | Void Pointer |
msg | Pointer to I2CLLD_Message Object |
transferStatus | Transfer Status |
typedef void(* I2C_lld_targetTransferCompleteCallback) (void *args, const I2CLLD_targetTransaction *targetTxn, int32_t transferStatus) |
The definition of a transfer completion callback function used by the I2C driver when used in Target Mode.
args | Void Pointer |
targetTxn | Pointer to I2CLLD_targetTransaction Object |
transferStatus | Transfer Status |
typedef struct I2CLLD_Object * I2CLLD_Handle |
int32_t I2C_lld_init | ( | I2CLLD_Handle | handle | ) |
This API Initializes the I2C instance.
handle | [IN] Handle to the I2C instance used |
int32_t I2C_lld_deInit | ( | I2CLLD_Handle | handle | ) |
This API De-Initializes the I2C instance.
handle | [IN] Handle to the I2C instance used |
int32_t I2C_lld_Transaction_init | ( | I2CLLD_Transaction * | transaction | ) |
API to set default values of I2CLLD_Transaction in transaction.
transaction | [IN] Pointer to the structure to be initialized |
int32_t I2C_lld_Message_init | ( | I2CLLD_Message * | msg | ) |
API to set default values of I2CLLD_Message in msg.
msg | [IN] Pointer to the structure to be initialized |
int32_t I2C_lld_write | ( | I2CLLD_Handle | handle, |
I2C_ExtendedParams * | extendedParams, | ||
uint32_t | timeout | ||
) |
API to initiate the write transaction in polled mode.
handle | [IN] Handle to the I2C instance used |
extendedParams | [IN] Pointer to structure containing transfer parameters |
timeout | [IN] Timeout for read operation in Micro Seconds I2cTimeoutValues |
int32_t I2C_lld_writeIntr | ( | I2CLLD_Handle | handle, |
I2C_ExtendedParams * | extendedParams | ||
) |
API to initiate the write transaction in Interrupt mode.
handle | [IN] Handle to the I2C instance used |
extendedParams | [IN] Pointer to structure containing transfer parameters |
int32_t I2C_lld_read | ( | I2CLLD_Handle | handle, |
I2C_ExtendedParams * | extendedParams, | ||
uint32_t | timeout | ||
) |
API to initiate the read transaction in polled mode.
handle | [IN] Handle to the I2C instance used |
extendedParams | [IN] Pointer to structure containing transfer parameters |
timeout | [IN] Timeout for read operation in Micro Seconds I2cTimeoutValues |
int32_t I2C_lld_readIntr | ( | I2CLLD_Handle | handle, |
I2C_ExtendedParams * | extendedParams | ||
) |
API to initiate the read transaction in Interrupt mode.
handle | [IN] Handle to the I2C instance used |
extendedParams | [IN] Pointer to structure containing transfer parameters |
int32_t I2C_lld_mem_write | ( | I2CLLD_Handle | handle, |
I2C_Memory_ExtendedParams * | mem_extendedParams, | ||
uint32_t | timeout | ||
) |
Function to initiate a transfer from I2C in interrupt mode.
handle | [IN] Handle to the I2C instance used |
mem_extendedParams | [IN] Pointer to structure containing transfer parameters |
timeout | [IN] Timeout for read operation in Micro Seconds I2cTimeoutValues |
int32_t I2C_lld_mem_writeIntr | ( | I2CLLD_Handle | handle, |
I2C_Memory_ExtendedParams * | mem_extendedParams | ||
) |
Function to initiate a transfer from I2C in interrupt mode.
handle | [IN] Handle to the I2C instance used |
mem_extendedParams | [IN] Pointer to structure containing transfer parameters |
int32_t I2C_lld_mem_read | ( | I2CLLD_Handle | handle, |
I2C_Memory_ExtendedParams * | mem_extendedParams, | ||
uint32_t | timeout | ||
) |
Function to initiate a transfer from I2C in interrupt mode.
handle | [IN] Handle to the I2C instance used |
mem_extendedParams | [IN] Pointer to structure containing transfer parameters |
timeout | [IN] Timeout for read operation in Micro Seconds I2cTimeoutValues |
int32_t I2C_lld_mem_readIntr | ( | I2CLLD_Handle | handle, |
I2C_Memory_ExtendedParams * | mem_extendedParams | ||
) |
Function to initiate a transfer from I2C in interrupt mode.
handle | [IN] Handle to the I2C instance used |
mem_extendedParams | [IN] Pointer to structure containing transfer parameters |
int32_t I2C_lld_transferPoll | ( | I2CLLD_Handle | handle, |
I2CLLD_Message * | msg | ||
) |
Function to initiate a transfer from I2C in polled mode.
handle | [IN] Handle to the I2C instance used |
msg | [IN] Pointer to the I2CLLD_Message structure that contains values for this specific transfer |
int32_t I2C_lld_transferIntr | ( | I2CLLD_Handle | handle, |
I2CLLD_Message * | msg | ||
) |
Function to initiate a transfer from I2C in interrupt mode.
handle | [IN] Handle to the I2C instance used |
msg | [IN] Pointer to the I2CLLD_Message structure that contains values for this specific transfer |
int32_t I2C_lld_targetTransferIntr | ( | I2CLLD_Handle | handle, |
I2CLLD_targetTransaction * | txn | ||
) |
Function to initiate a transfer from I2C in target mode.
handle | [IN] Handle to the I2C instance used |
txn | [IN] Poiter to the I2CLLD_targetTransaction structure that contains values for this specific transfer |
int32_t I2C_lld_probe | ( | I2CLLD_Handle | handle, |
uint32_t | targetAddr | ||
) |
Function to probe I2C.
handle | [IN] handle to the I2C instance used |
targetAddr | [IN] address of the target to probe |
int32_t I2C_lld_setBusFrequency | ( | I2CLLD_Handle | handle, |
uint32_t | busFrequency | ||
) |
Function to set the bus frequency.
handle | [IN] handle to the I2C instance used |
busFrequency | [IN] frequency value to be set I2cBitRates |
int32_t I2C_lld_recoverBus | ( | I2CLLD_Handle | handle, |
uint32_t | i2cDelay | ||
) |
Function to recover the bus in case of lockup.
handle | [IN] handle to the I2C |
i2cDelay | [IN] the length of delay for sending clock pulses to target |
void I2C_lld_controllerIsr | ( | void * | args | ) |
This is the I2C Controller ISR and can be used as IRQ handler in Controller mode.
args | [IN] Argument to the ISR |
void I2C_lld_targetIsr | ( | void * | args | ) |
This is the I2C Target ISR and can be used as IRQ handler in Target mode.
args | [IN] Argument to the ISR |