Macros | Typedefs | Enumerations | Functions | Variables
fsl_lpi2c.c File Reference
#include "fsl_lpi2c.h"
#include <stdlib.h>
#include <string.h>
Include dependency graph for fsl_lpi2c.c:

Go to the source code of this file.

Macros

#define FSL_COMPONENT_ID   "platform.drivers.lpi2c"
 

Typedefs

typedef void(* lpi2c_master_isr_t) (LPI2C_Type *base, lpi2c_master_handle_t *handle)
 Typedef for master interrupt handler. More...
 
typedef void(* lpi2c_slave_isr_t) (LPI2C_Type *base, lpi2c_slave_handle_t *handle)
 Typedef for slave interrupt handler. More...
 

Enumerations

enum  {
  kMasterClearFlags, kMasterIrqFlags, kMasterErrorFlags, kSlaveClearFlags,
  kSlaveIrqFlags, kSlaveErrorFlags = kLPI2C_SlaveFifoErrFlag | kLPI2C_SlaveBitErrFlag
}
 Common sets of flags used by the driver. More...
 
enum  { kTxDataCmd = LPI2C_MTDR_CMD(0x0U), kRxDataCmd = LPI2C_MTDR_CMD(0X1U), kStopCmd = LPI2C_MTDR_CMD(0x2U), kStartCmd = LPI2C_MTDR_CMD(0x4U) }
 
enum  { kDefaultTxWatermark = 0, kDefaultRxWatermark = 0 }
 Default watermark values. More...
 
enum  {
  kIdleState = 0, kSendCommandState, kIssueReadCommandState, kTransferDataState,
  kStopState, kWaitForCompletionState
}
 States for the state machine used by transactional APIs. More...
 

Functions

status_t LPI2C_CheckForBusyBus (LPI2C_Type *base)
 Make sure the bus isn't already busy. More...
 
static void LPI2C_CommonIRQHandler (LPI2C_Type *base, uint32_t instance)
 Shared IRQ handler that can call both master and slave ISRs. More...
 
static uint32_t LPI2C_GetCyclesForWidth (uint32_t sourceClock_Hz, uint32_t width_ns, uint32_t maxCycles, uint32_t prescaler)
 Computes a cycle count for a given time in nanoseconds. More...
 
uint32_t LPI2C_GetInstance (LPI2C_Type *base)
 Returns an instance number given a base address. More...
 
static void LPI2C_InitTransferStateMachine (lpi2c_master_handle_t *handle)
 Prepares the transfer state machine and fills in the command buffer. More...
 
status_t LPI2C_MasterCheckAndClearError (LPI2C_Type *base, uint32_t status)
 Convert provided flags to status code, and clear any errors if present. More...
 
void LPI2C_MasterConfigureDataMatch (LPI2C_Type *base, const lpi2c_data_match_config_t *config)
 Configures LPI2C master data match feature. More...
 
void LPI2C_MasterDeinit (LPI2C_Type *base)
 Deinitializes the LPI2C master peripheral. More...
 
void LPI2C_MasterGetDefaultConfig (lpi2c_master_config_t *masterConfig)
 Provides a default configuration for the LPI2C master peripheral. More...
 
void LPI2C_MasterInit (LPI2C_Type *base, const lpi2c_master_config_t *masterConfig, uint32_t sourceClock_Hz)
 Initializes the LPI2C master peripheral. More...
 
status_t LPI2C_MasterReceive (LPI2C_Type *base, void *rxBuff, size_t rxSize)
 Performs a polling receive transfer on the I2C bus. More...
 
status_t LPI2C_MasterSend (LPI2C_Type *base, void *txBuff, size_t txSize)
 Performs a polling send transfer on the I2C bus. More...
 
void LPI2C_MasterSetBaudRate (LPI2C_Type *base, uint32_t sourceClock_Hz, uint32_t baudRate_Hz)
 Sets the I2C bus frequency for master transactions. More...
 
status_t LPI2C_MasterStart (LPI2C_Type *base, uint8_t address, lpi2c_direction_t dir)
 Sends a START signal and slave address on the I2C bus. More...
 
status_t LPI2C_MasterStop (LPI2C_Type *base)
 Sends a STOP signal on the I2C bus. More...
 
void LPI2C_MasterTransferAbort (LPI2C_Type *base, lpi2c_master_handle_t *handle)
 Terminates a non-blocking LPI2C master transmission early. More...
 
status_t LPI2C_MasterTransferBlocking (LPI2C_Type *base, lpi2c_master_transfer_t *transfer)
 Performs a master polling transfer on the I2C bus. More...
 
void LPI2C_MasterTransferCreateHandle (LPI2C_Type *base, lpi2c_master_handle_t *handle, lpi2c_master_transfer_callback_t callback, void *userData)
 Creates a new handle for the LPI2C master non-blocking APIs. More...
 
status_t LPI2C_MasterTransferGetCount (LPI2C_Type *base, lpi2c_master_handle_t *handle, size_t *count)
 Returns number of bytes transferred so far. More...
 
void LPI2C_MasterTransferHandleIRQ (LPI2C_Type *base, lpi2c_master_handle_t *handle)
 Reusable routine to handle master interrupts. More...
 
status_t LPI2C_MasterTransferNonBlocking (LPI2C_Type *base, lpi2c_master_handle_t *handle, lpi2c_master_transfer_t *transfer)
 Performs a non-blocking transaction on the I2C bus. More...
 
static status_t LPI2C_MasterWaitForTxReady (LPI2C_Type *base)
 Wait until there is room in the tx fifo. More...
 
static status_t LPI2C_RunTransferStateMachine (LPI2C_Type *base, lpi2c_master_handle_t *handle, bool *isDone)
 Execute states until FIFOs are exhausted. More...
 
static status_t LPI2C_SlaveCheckAndClearError (LPI2C_Type *base, uint32_t flags)
 Convert provided flags to status code, and clear any errors if present. More...
 
void LPI2C_SlaveDeinit (LPI2C_Type *base)
 Deinitializes the LPI2C slave peripheral. More...
 
void LPI2C_SlaveGetDefaultConfig (lpi2c_slave_config_t *slaveConfig)
 Provides a default configuration for the LPI2C slave peripheral. More...
 
void LPI2C_SlaveInit (LPI2C_Type *base, const lpi2c_slave_config_t *slaveConfig, uint32_t sourceClock_Hz)
 Initializes the LPI2C slave peripheral. More...
 
status_t LPI2C_SlaveReceive (LPI2C_Type *base, void *rxBuff, size_t rxSize, size_t *actualRxSize)
 Performs a polling receive transfer on the I2C bus. More...
 
status_t LPI2C_SlaveSend (LPI2C_Type *base, void *txBuff, size_t txSize, size_t *actualTxSize)
 Performs a polling send transfer on the I2C bus. More...
 
void LPI2C_SlaveTransferAbort (LPI2C_Type *base, lpi2c_slave_handle_t *handle)
 Aborts the slave non-blocking transfers. More...
 
void LPI2C_SlaveTransferCreateHandle (LPI2C_Type *base, lpi2c_slave_handle_t *handle, lpi2c_slave_transfer_callback_t callback, void *userData)
 Creates a new handle for the LPI2C slave non-blocking APIs. More...
 
status_t LPI2C_SlaveTransferGetCount (LPI2C_Type *base, lpi2c_slave_handle_t *handle, size_t *count)
 Gets the slave transfer status during a non-blocking transfer. More...
 
void LPI2C_SlaveTransferHandleIRQ (LPI2C_Type *base, lpi2c_slave_handle_t *handle)
 Reusable routine to handle slave interrupts. More...
 
status_t LPI2C_SlaveTransferNonBlocking (LPI2C_Type *base, lpi2c_slave_handle_t *handle, uint32_t eventMask)
 Starts accepting slave transfers. More...
 

Variables

static LPI2C_Type *const kLpi2cBases [] = LPI2C_BASE_PTRS
 Array to map LPI2C instance number to base pointer. More...
 
static const clock_ip_name_t kLpi2cClocks [] = LPI2C_CLOCKS
 Array to map LPI2C instance number to clock gate enum. More...
 
static const IRQn_Type kLpi2cIrqs [] = LPI2C_IRQS
 Array to map LPI2C instance number to IRQ number. More...
 
static lpi2c_master_handle_ts_lpi2cMasterHandle [ARRAY_SIZE(kLpi2cBases)]
 Pointers to master handles for each instance. More...
 
static lpi2c_master_isr_t s_lpi2cMasterIsr
 Pointer to master IRQ handler for each instance. More...
 
static lpi2c_slave_handle_ts_lpi2cSlaveHandle [ARRAY_SIZE(kLpi2cBases)]
 Pointers to slave handles for each instance. More...
 
static lpi2c_slave_isr_t s_lpi2cSlaveIsr
 Pointer to slave IRQ handler for each instance. More...
 

Macro Definition Documentation

◆ FSL_COMPONENT_ID

#define FSL_COMPONENT_ID   "platform.drivers.lpi2c"

Definition at line 19 of file fsl_lpi2c.c.

Typedef Documentation

◆ lpi2c_master_isr_t

typedef void(* lpi2c_master_isr_t) (LPI2C_Type *base, lpi2c_master_handle_t *handle)

Typedef for master interrupt handler.

Definition at line 84 of file fsl_lpi2c.c.

◆ lpi2c_slave_isr_t

typedef void(* lpi2c_slave_isr_t) (LPI2C_Type *base, lpi2c_slave_handle_t *handle)

Typedef for slave interrupt handler.

Definition at line 87 of file fsl_lpi2c.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Common sets of flags used by the driver.

Enumerator
kMasterClearFlags 

All flags which are cleared by the driver upon starting a transfer.

kMasterIrqFlags 

IRQ sources enabled by the non-blocking transactional API.

kMasterErrorFlags 

Errors to check for.

kSlaveClearFlags 

All flags which are cleared by the driver upon starting a transfer.

kSlaveIrqFlags 

IRQ sources enabled by the non-blocking transactional API.

kSlaveErrorFlags 

Errors to check for.

Definition at line 23 of file fsl_lpi2c.c.

◆ anonymous enum

anonymous enum
Enumerator
kTxDataCmd 

Transmit DATA[7:0]

kRxDataCmd 

Receive (DATA[7:0] + 1) bytes

kStopCmd 

Generate STOP condition

kStartCmd 

Generate(repeated) START and transmit address in DATA[[7:0]

Definition at line 53 of file fsl_lpi2c.c.

◆ anonymous enum

anonymous enum

Default watermark values.

The default watermarks are set to zero.

Enumerator
kDefaultTxWatermark 
kDefaultRxWatermark 

Definition at line 66 of file fsl_lpi2c.c.

◆ anonymous enum

anonymous enum

States for the state machine used by transactional APIs.

Enumerator
kIdleState 
kSendCommandState 
kIssueReadCommandState 
kTransferDataState 
kStopState 
kWaitForCompletionState 

Definition at line 73 of file fsl_lpi2c.c.

Function Documentation

◆ LPI2C_CommonIRQHandler()

static void LPI2C_CommonIRQHandler ( LPI2C_Type base,
uint32_t  instance 
)
static

Shared IRQ handler that can call both master and slave ISRs.

The master and slave ISRs are called through function pointers in order to decouple this code from the ISR functions. Without this, the linker would always pull in both ISRs and every function they call, even if only the functional API was used.

Parameters
baseThe LPI2C peripheral base address.
instanceThe LPI2C peripheral instance number.

Definition at line 2138 of file fsl_lpi2c.c.

◆ LPI2C_GetCyclesForWidth()

static uint32_t LPI2C_GetCyclesForWidth ( uint32_t  sourceClock_Hz,
uint32_t  width_ns,
uint32_t  maxCycles,
uint32_t  prescaler 
)
static

Computes a cycle count for a given time in nanoseconds.

Parameters
sourceClock_HzLPI2C functional clock frequency in Hertz.
width_nsDesired with in nanoseconds.
maxCyclesMaximum cycle count, determined by the number of bits wide the cycle count field is.
prescalerLPI2C prescaler setting. Pass 1 if the prescaler should not be used, as for slave glitch widths.

Definition at line 179 of file fsl_lpi2c.c.

◆ LPI2C_GetInstance()

uint32_t LPI2C_GetInstance ( LPI2C_Type base)

Returns an instance number given a base address.

If an invalid base address is passed, debug builds will assert. Release builds will just return instance number 0.

Parameters
baseThe LPI2C peripheral base address.
Returns
LPI2C instance number starting from 0.

Definition at line 157 of file fsl_lpi2c.c.

◆ LPI2C_InitTransferStateMachine()

static void LPI2C_InitTransferStateMachine ( lpi2c_master_handle_t handle)
static

Prepares the transfer state machine and fills in the command buffer.

Parameters
handleMaster nonblocking driver handle.

Definition at line 1188 of file fsl_lpi2c.c.

◆ LPI2C_MasterWaitForTxReady()

static status_t LPI2C_MasterWaitForTxReady ( LPI2C_Type base)
static

Wait until there is room in the tx fifo.

Parameters
baseThe LPI2C peripheral base address.
Return values
kStatus_Success
kStatus_LPI2C_PinLowTimeout
kStatus_LPI2C_ArbitrationLost
kStatus_LPI2C_Nak
kStatus_LPI2C_FifoError

Definition at line 271 of file fsl_lpi2c.c.

◆ LPI2C_RunTransferStateMachine()

static status_t LPI2C_RunTransferStateMachine ( LPI2C_Type base,
lpi2c_master_handle_t handle,
bool *  isDone 
)
static

Execute states until FIFOs are exhausted.

Parameters
handleMaster nonblocking driver handle.
[out]isDoneSet to true if the transfer has completed.
Return values
kStatus_Success
kStatus_LPI2C_PinLowTimeout
kStatus_LPI2C_ArbitrationLost
kStatus_LPI2C_Nak
kStatus_LPI2C_FifoError

Definition at line 1009 of file fsl_lpi2c.c.

◆ LPI2C_SlaveCheckAndClearError()

static status_t LPI2C_SlaveCheckAndClearError ( LPI2C_Type base,
uint32_t  flags 
)
static

Convert provided flags to status code, and clear any errors if present.

Parameters
baseThe LPI2C peripheral base address.
statusCurrent status flags value that will be checked.
Return values
kStatus_Success
kStatus_LPI2C_BitError
kStatus_LPI2C_FifoError

Definition at line 1609 of file fsl_lpi2c.c.

Variable Documentation

◆ kLpi2cBases

LPI2C_Type* const kLpi2cBases[] = LPI2C_BASE_PTRS
static

Array to map LPI2C instance number to base pointer.

Definition at line 116 of file fsl_lpi2c.c.

◆ kLpi2cClocks

const clock_ip_name_t kLpi2cClocks[] = LPI2C_CLOCKS
static

Array to map LPI2C instance number to clock gate enum.

Definition at line 123 of file fsl_lpi2c.c.

◆ kLpi2cIrqs

const IRQn_Type kLpi2cIrqs[] = LPI2C_IRQS
static

Array to map LPI2C instance number to IRQ number.

Definition at line 119 of file fsl_lpi2c.c.

◆ s_lpi2cMasterHandle

lpi2c_master_handle_t* s_lpi2cMasterHandle[ARRAY_SIZE(kLpi2cBases)]
static

Pointers to master handles for each instance.

Definition at line 136 of file fsl_lpi2c.c.

◆ s_lpi2cMasterIsr

lpi2c_master_isr_t s_lpi2cMasterIsr
static

Pointer to master IRQ handler for each instance.

Definition at line 133 of file fsl_lpi2c.c.

◆ s_lpi2cSlaveHandle

lpi2c_slave_handle_t* s_lpi2cSlaveHandle[ARRAY_SIZE(kLpi2cBases)]
static

Pointers to slave handles for each instance.

Definition at line 142 of file fsl_lpi2c.c.

◆ s_lpi2cSlaveIsr

lpi2c_slave_isr_t s_lpi2cSlaveIsr
static

Pointer to slave IRQ handler for each instance.

Definition at line 139 of file fsl_lpi2c.c.



picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:57