![]() |
ISF
1.1
Intelligent Sensing Framework
|
isf_i2c.h describes the definitions and types for the ISF I2C component. More...
Go to the source code of this file.
Data Structures | |
struct | i2c_BusConfig_struct |
This structure defines the user-specified parameters for bus configuration. More... | |
struct | i2c_MessageBuffer_struct |
This structure defines a buffer to hold data read from or written to the I2C bus. More... | |
struct | i2c_Command_struct |
This structure defines the data of a command transferred over the I2C bus. More... | |
struct | i2c_BusHandle_struct |
This structure defines the data bus handle. More... | |
struct | i2c_SlaveHandle_struct |
This structure defines a slave handler. More... | |
Defines | |
#define | I2C_SIZED_BUFFER(bufSize) struct { uint16 size; uint8 buffer[(bufSize)]; } |
#define | I2C_FIND_FIRST_SLAVE { 0, NULL} |
#define | I2C_CMD_DEFN(cmdLen) struct { uint16 nWrite; uint16 nRead; uint8 cmdWords[(cmdLen)]; } |
#define | I2C_10BITADDRESS_BITMASK 0x8000 |
#define | I2C_MAKE_10BITADDRESS(addr) (addr | I2C_10BITADDRESS_BITMASK) |
Typedefs | |
typedef comm_Id_t | i2c_BusId_t |
typedef uint8 | i2c_BusConfigFlags_t |
typedef comm_State_t | i2c_BusState_t |
typedef comm_Address_t | i2c_AddrHint_t |
typedef comm_Flags_t | i2c_readFlags_t |
typedef comm_Flags_t | i2c_writeFlags_t |
typedef struct i2c_BusConfig_struct | i2c_BusConfig_t |
This structure defines the user-specified parameters for bus configuration. | |
typedef struct i2c_MessageBuffer_struct | i2c_MessageBuffer_t |
This structure defines a buffer to hold data read from or written to the I2C bus. | |
typedef struct i2c_Command_struct | i2c_Command_t |
This structure defines the data of a command transferred over the I2C bus. | |
typedef struct i2c_BusHandle_struct | i2c_BusHandle_t |
This structure defines the data bus handle. | |
typedef struct i2c_SlaveHandle_struct | i2c_SlaveHandle_t |
This structure defines a slave handler. | |
Enumerations | |
enum | i2c_BusConfigFlag_vals { I2C_CONFIG_MASTER = 0x1 } |
These are I2C bus configuration parameters. More... | |
enum | i2c_writeFlags_vals { I2C_WRITE_FLAGS_DEFAULT = 0x0 } |
These are flags for modifying the behavior of a write. More... | |
enum | i2c_readFlags_vals { I2C_READ_FLAGS_DEFAULT = 0x0 } |
These are flags for modifying the behavior of a read. More... | |
enum | i2c_HWSpecificReg_Config { HWSPECIFIC_REG_FREQUENCY = 0, HWSPECIFIC_REG_CTRL_1 = 1, HWSPECIFIC_MAX = 2 } |
These are hardware-specific configuration parameters for devices similar to the FXLC95000CL and should not be modified. More... | |
enum | i2c_Speed { I2C_SPEED_START = 0, I2C_SPEED_600_KHZ = I2C_SPEED_START, I2C_SPEED_400_KHZ = 1, I2C_SPEED_200_KHZ = 2, I2C_SPEED_END = 3 } |
These values establish the i2C bus speed. The user can specify other valid speeds by configuring the frequency register via the hwSpecificCfg parameter in the i2c_BusConfig_t structure. More... | |
Functions | |
isf_status_t | i2c_bus_init (i2c_BusId_t aBusId, i2c_BusHandle_t *apBusHandle) |
This function initializes the I2C bus. | |
isf_status_t | i2c_bus_configure (i2c_BusHandle_t *apBusHandle, i2c_BusConfig_t *apBusConfig) |
This function configures or reconfigures an already initialized bus. | |
i2c_BusState_t | i2c_get_bus_state (i2c_BusHandle_t *apBusHandle) |
This function returns the bus state. | |
isf_status_t | i2c_get_bus_config (i2c_BusHandle_t *apBusHandle, i2c_BusConfig_t *apBusConfig) |
This function returns the current bus configuration. | |
isf_status_t | i2c_get_slave_at (i2c_BusHandle_t *apBusHandle, i2c_AddrHint_t aSlaveAddr, i2c_SlaveHandle_t *apSlaveHandle) |
This function creates a slave handle for a device at a specified bus address. | |
isf_status_t | i2c_bus_enumerate (i2c_BusHandle_t *apBusHandle, i2c_SlaveHandle_t *apPrevSlaveHandle, i2c_SlaveHandle_t *apNextSlaveHandle) |
This function searches for a slave device on the bus. | |
isf_status_t | i2c_bus_start (i2c_BusHandle_t *apBusHandle) |
This function starts a bus. | |
isf_status_t | i2c_bus_stop (i2c_BusHandle_t *apBusHandle, isf_duration_t aTimeout) |
This function stops a bus. | |
isf_status_t | i2c_bus_acquire_lock (i2c_BusHandle_t *apBusHandle, isf_duration_t aTimeout) |
This function locks the bus for exclusive access. | |
isf_status_t | i2c_bus_release_lock (i2c_BusHandle_t *apBusHandle) |
This function releases exclusive access to the bus. | |
isf_status_t | i2c_read (i2c_SlaveHandle_t *apSlaveHandle, i2c_Command_t *apReadCmd, i2c_MessageBuffer_t *apReadBuffer, i2c_readFlags_t aFlags) |
This function reads from an I2C device. | |
isf_status_t | i2c_write (i2c_SlaveHandle_t *apSlaveHandle, i2c_Command_t *apWriteCmd, i2c_writeFlags_t aFlags) |
This function writes to an I2C device. | |
i2c_BusHandle_t * | i2c_get_bus_handle (i2c_SlaveHandle_t *apSlaveHandle) |
This function retrieves the bus handle from a slaveHandle. |
isf_i2c.h describes the definitions and types for the ISF I2C component.
File: isf_i2c.h
Copyright (c) 2012, Freescale Semiconductor, Inc.
Definition in file isf_i2c.h.
#define I2C_10BITADDRESS_BITMASK 0x8000 |
#define I2C_CMD_DEFN | ( | cmdLen | ) | struct { uint16 nWrite; uint16 nRead; uint8 cmdWords[(cmdLen)]; } |
Macro used for storing the created concretely sized typdedefs compatible with i2c_Command_t.
#define I2C_FIND_FIRST_SLAVE { 0, NULL} |
A macro used with * i2c_bus_enumerate() to specify a full search for slave devices.
#define I2C_MAKE_10BITADDRESS | ( | addr | ) | (addr | I2C_10BITADDRESS_BITMASK) |
Macro used for 10-bit addressing. As an example, for an actual 10-bit address of 0x120, I2C_MAKE_10BITADDRESS(0x120) is called to make it acceptable to the I2C module.
#define I2C_SIZED_BUFFER | ( | bufSize | ) | struct { uint16 size; uint8 buffer[(bufSize)]; } |
typedef comm_Address_t i2c_AddrHint_t |
typedef struct i2c_BusConfig_struct i2c_BusConfig_t |
This structure defines the user-specified parameters for bus configuration.
An effort has been made to keep the contents of this type generic, hiding any specific I2C peripheral details in the pHWSpecificCfg field.
typedef uint8 i2c_BusConfigFlags_t |
typedef struct i2c_BusHandle_struct i2c_BusHandle_t |
This structure defines the data bus handle.
typedef comm_Id_t i2c_BusId_t |
typedef comm_State_t i2c_BusState_t |
typedef struct i2c_Command_struct i2c_Command_t |
This structure defines the data of a command transferred over the I2C bus.
typedef struct i2c_MessageBuffer_struct i2c_MessageBuffer_t |
This structure defines a buffer to hold data read from or written to the I2C bus.
typedef comm_Flags_t i2c_readFlags_t |
typedef struct i2c_SlaveHandle_struct i2c_SlaveHandle_t |
This structure defines a slave handler.
typedef comm_Flags_t i2c_writeFlags_t |
enum i2c_readFlags_vals |
enum i2c_Speed |
These values establish the i2C bus speed. The user can specify other valid speeds by configuring the frequency register via the hwSpecificCfg parameter in the i2c_BusConfig_t structure.
enum i2c_writeFlags_vals |
isf_status_t i2c_bus_acquire_lock | ( | i2c_BusHandle_t * | apBusHandle, |
isf_duration_t | aTimeout | ||
) |
This function locks the bus for exclusive access.
i2c_bus_acquire_lock() serializes multi-client access to the bus. Each bus user should acquire a bus lock prior to sending messages on the bus. While holding the bus lock, no other clients may perform any bus messaging. For this reason, it is important to release the bus lock as soon as practical.
[in] | apBusHandle | The handle of the bus to be locked. |
[in] | aTimeout | The length of time to wait before returning without the lock. The timeout parameter may be set to 0 to wait forever, or as long as necessary to get the lock. |
ISF_SUCCESS | is returned if the lock was acquired. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized bus. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter was passed into the function. |
isf_status_t i2c_bus_configure | ( | i2c_BusHandle_t * | apBusHandle, |
i2c_BusConfig_t * | apBusConfig | ||
) |
This function configures or reconfigures an already initialized bus.
A bus may be configured during initialization or it may be configured separately after initialization. Calls made to i2c_bus_configure() after initialization overrides any previous configuration values, and must be made while the bus state is STOPPED.
[in] | apBusHandle | The handle of the bus to be configured. |
[in] | apBusConfig | The configuration parameters to be used during configuration. |
COMM_ERROR_STOP | is returned when the bus was not in a STOPPED state. |
COMM_ERROR_INIT | is returned when the bus is not initialized. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout interval. |
COMM_ERROR_LOCK | is returned when the request could not be completed as there is a invalid lock associated with the bus. |
isf_status_t i2c_bus_enumerate | ( | i2c_BusHandle_t * | apBusHandle, |
i2c_SlaveHandle_t * | apPrevSlaveHandle, | ||
i2c_SlaveHandle_t * | apNextSlaveHandle | ||
) |
This function searches for a slave device on the bus.
To enumerate a bus, i2c_bus_enumerate() is called repeatedly until all the desired slaves are found. The slave handle found on the preceding call is passed in the subsequent call to find the next slave. If all slave addresses are known, bus enumeration is not required and i2c_get_slave_at() may be used to acquire all the slave handles.
[in] | apBusHandle | The handle of the bus to be queried. |
[in] | apPrevSlaveHandle | The known address of a slave device. |
[out] | apNextSlaveHandle | The known address of the next slave device. |
ISF_SUCCESS | is returned when another slave device was found. |
COMM_ERROR_NOEXIST | is returned when no more slave devices are found. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized bus. |
COMM_ERROR_STOP | is returned when the bus is not started. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period provided during the bus configuration. |
COMM_ERROR_LOCK | is returned when the internal lock request fails due to an invalid lock on the bus handle. |
isf_status_t i2c_bus_init | ( | i2c_BusId_t | aBusId, |
i2c_BusHandle_t * | apBusHandle | ||
) |
This function initializes the I2C bus.
Any I2C bus must be initialized prior to use. Initialization creates and initializes the data structures required to manage the bus. The bus is implicitly locked during initialization.
[in] | aBusId | The ID of the bus to initialize. This is an index into the array of known buses that can be used. |
[out] | apBusHandle | The bus handle of the bus to be configured. |
COMM_ERROR_NOEXIST | is returned when the supplied bus identifier does not exist. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter was passed into the function. |
COMM_ERROR_INIT | is returned when the bus could not be initialized. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
COMM_ERROR_LOCK | is returned when the lock could not be acquired properly. |
isf_status_t i2c_bus_release_lock | ( | i2c_BusHandle_t * | apBusHandle | ) |
This function releases exclusive access to the bus.
i2c_bus_release_lock() relinquishes the bus.
[in] | apBusHandle | The handle of the bus to be released. |
ISF_SUCCESS | is returned if the bus was successfully released. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized bus. |
COMM_ERROR_LOCK | is returned when there is no lock held on the specified bus. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter was passed into the function. |
isf_status_t i2c_bus_start | ( | i2c_BusHandle_t * | apBusHandle | ) |
This function starts a bus.
. i2c_bus_start() enables an initialized bus to begin communications. This call enables the hardware peripherals associated with the bus.
[in] | apBusHandle | The handle of the bus to be started. |
ISF_SUCCESS | is returned when the bus is started. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized bus. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter is passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period provided during the bus configuration. |
COMM_ERROR_LOCK | is returned when the internal lock request fails due to an invalid lock on the bus handle. |
isf_status_t i2c_bus_stop | ( | i2c_BusHandle_t * | apBusHandle, |
isf_duration_t | aTimeout | ||
) |
This function stops a bus.
i2c_bus_stop() disables an initialized bus and stops communications. This call disables the hardware peripherals associated with the bus.
[in] | apBusHandle | The handle of the bus to be started. |
[in] | aTimeout | The length of time to wait before returning without the stop. The timeout parameter may be set to 0 to wait forever, or as long as necessary to stop. |
ISF_SUCCESS | is returned when the bus is stopped. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized bus. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter is passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period provided when the bus was configured. |
COMM_ERROR_LOCK | is returned when the internal lock request fails due to an invalid lock on the bus handle. |
isf_status_t i2c_get_bus_config | ( | i2c_BusHandle_t * | apBusHandle, |
i2c_BusConfig_t * | apBusConfig | ||
) |
This function returns the current bus configuration.
A bus may be queried for the current configuration in use.
[in] | apBusHandle | The handle of the bus to be queried. |
[out] | apBusConfig | The address of the configuration of the bus queried. |
COMM_ERROR_NULL_PTR | is returned when an invalid bus handle was provided to the function. |
i2c_BusHandle_t* i2c_get_bus_handle | ( | i2c_SlaveHandle_t * | apSlaveHandle | ) |
This function retrieves the bus handle from a slaveHandle.
i2c_get_bus_handle() returns the busHandle associated with the bus where the slave resides.
[in] | apSlaveHandle | Handle of slave device containing the bus handle of interest. |
NULL | is returned when the specified slave is invalid. |
i2c_BusState_t i2c_get_bus_state | ( | i2c_BusHandle_t * | apBusHandle | ) |
This function returns the bus state.
A bus may be queried for its current state.
[in] | apBusHandle | The handle of the bus to be queried. |
COMM_ERROR_NULL_PTR | A NULL parameter was passed into the function. |
isf_status_t i2c_get_slave_at | ( | i2c_BusHandle_t * | apBusHandle, |
i2c_AddrHint_t | aSlaveAddr, | ||
i2c_SlaveHandle_t * | apSlaveHandle | ||
) |
This function creates a slave handle for a device at a specified bus address.
The i2c_get_slave_at() function obtains the handle to a slave device at a known bus address.
[in] | apBusHandle | The handle of the bus to be queried. |
[in] | aSlaveAddr | The known address of a slave device. |
[out] | apSlaveHandle | The address of the slave handle provided for the slave device on the given bus. |
ISF_SUCCESS | is returned when a slave with the given address is found. |
COMM_ERROR_NOEXIST | is returned when a slave does not exist at the specified address. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized bus. |
COMM_ERROR_STOP | is returned when the bus has not been started. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period made during the bus configuration. |
COMM_ERROR_LOCK | is returned when the internal lock request fails due to an invalid lock on the bus handle. |
isf_status_t i2c_read | ( | i2c_SlaveHandle_t * | apSlaveHandle, |
i2c_Command_t * | apReadCmd, | ||
i2c_MessageBuffer_t * | apReadBuffer, | ||
i2c_readFlags_t | aFlags | ||
) |
This function reads from an I2C device.
i2c_read() reads data from the specified I2C slave device. The supplied command is sent to the slave device which triggers the device to return some data. Any data returned by the slave is read and placed in the provided read buffer.
[in] | apSlaveHandle | The handle to the slave device from which to read. |
[in] | apReadCmd | The read command to transmit to the device. |
[out] | apReadBuffer | Address of the buffer in which to place the read data. |
[in] | aFlags | A set of bit flags controlling the behavior of the read. |
ISF_SUCCESS | is returned if the read is completed successfully. |
COMM_ERROR_INIT | is returned when the specified slave device is on an uninitialized bus. |
COMM_ERROR_BUF_SIZE | is returned when either the the number of bytes to read is zero or the provided buffer is too small to hold all the data returned. If the provided buffer is too small to hold all the data returned, no data is written to the buffer. |
COMM_ERROR_STOP | is returned when the read is invoked on a STOPPED bus. |
COMM_ERROR_NO_ACK | is returned when no acknowledgment has been received from the slave device. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
COMM_ERROR_LOCK | is returned when the request could not be completed as there is a invalid lock associated with bus. |
isf_status_t i2c_write | ( | i2c_SlaveHandle_t * | apSlaveHandle, |
i2c_Command_t * | apWriteCmd, | ||
i2c_writeFlags_t | aFlags | ||
) |
This function writes to an I2C device.
i2c_write() writes data to the specified i2c slave device. The supplied command writes to the slave device.
[in] | apSlaveHandle | The handle to which the slave device is to write. |
[in] | apWriteCmd | The command to send to the device. |
[in] | aFlags | A set of bit flags controlling the behavior of the write. |
ISF_SUCCESS | is returned when the write command completes successfully. |
COMM_ERROR_INIT | is returned when the specified slave device is on an uninitialized bus. |
COMM_ERROR_STOP | is returned when the write is invoked on a STOPPED bus. |
COMM_ERROR_NO_ACK | is returned when no acknowledgment has been received from the slave device. |
COMM_ERROR_NULL_PTR | is returned when a NULL parameter was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
COMM_ERROR_LOCK | is returned when the request could not be completed as there is a invalid lock associated with the bus. |