![]() |
ISF
2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
|
isf_i2c_master_adapter.h defines the API definitions and types for the i2c master protocol adapter. More...
#include "isf_i2c_master_types.h"
#include "fsl_i2c_master_driver.h"
#include "fsl_i2c_hal.h"
#include "isf_comm.h"
#include "isf_protocol_adapter.h"
Go to the source code of this file.
Data Structures | |
struct | i2c_deviceEndpoint_struct |
This structure defines a device endpoint encapsulation for i2c handler. More... | |
Typedefs | |
typedef struct i2c_deviceEndpoint_struct | i2c_Endpoint_t |
This structure defines a device endpoint encapsulation for i2c handler. More... | |
typedef comm_Flags_t | i2c_writeFlags_t |
typedef comm_Flags_t | i2c_readFlags_t |
Enumerations | |
enum | i2c_comm_flag { I2C_SEND_NO_STOP = 1 <<0, I2C_SEND_STOP = 1 <<1 } |
Functions | |
isf_status_t | i2c_master_adapter_init (comm_Id_t aBusId, busHandle_t *apBusHandle) |
This function initializes a i2c bus. More... | |
isf_status_t | i2c_master_adapter_configure (busHandle_t *apBusHandle, void *apBusConfig) |
This function reconfigures an already initialized bus. More... | |
comm_State_t | i2c_master_adapter_get_state (busHandle_t *apBusHandle) |
This function returns the current bus state. More... | |
isf_status_t | i2c_master_adapter_get_config (busHandle_t *apBusHandle, void *apBusConfig) |
This function returns the current bus configuration. More... | |
isf_status_t | i2c_master_adapter_acquire_lock (busHandle_t *apBusHandle, isf_duration_t aTimeout) |
This function locks the bus for exclusive access. More... | |
isf_status_t | i2c_master_adapter_release_lock (busHandle_t *apBusHandle) |
This function releases exclusive bus access. More... | |
isf_status_t | i2c_master_adapter_start (busHandle_t *apBusHandle) |
This function starts a bus. More... | |
isf_status_t | i2c_master_adapter_stop (busHandle_t *apBusHandle) |
This function stops the given i2c bus. More... | |
isf_status_t | i2c_master_adapter_get_endpoint (busHandle_t *apBusHandle, void *apDevice, void **apEndpointHandle) |
This function creates a endpoint for a device at a specified bus address. More... | |
isf_status_t | i2c_master_adapter_release_endpoint (i2c_Endpoint_t *apEndpoint) |
This function closes a particular endpoint. More... | |
isf_status_t | i2c_master_adapter_write (void *apEndpointHandle, int32 offset, void *apWriteBuffer, uint32 aBuffsize, uint32 aNbyteWrite, i2c_writeFlags_t aFlags) |
This function writes to a i2c device. More... | |
isf_status_t | i2c_master_adapter_read (void *apEndpointHandle, int32 offset, void *apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead, i2c_readFlags_t aFlags) |
This function reads from a i2c device. More... | |
isf_i2c_master_adapter.h defines the API definitions and types for the i2c master protocol adapter.
File: isf_i2c_master_adapter.h
Copyright (c) 2015, Freescale Semiconductor, Inc.
Definition in file isf_i2c_master_adapter.h.
typedef struct i2c_deviceEndpoint_struct i2c_Endpoint_t |
This structure defines a device endpoint encapsulation for i2c handler.
typedef comm_Flags_t i2c_readFlags_t |
Definition at line 33 of file isf_i2c_master_adapter.h.
typedef comm_Flags_t i2c_writeFlags_t |
Definition at line 32 of file isf_i2c_master_adapter.h.
enum i2c_comm_flag |
Type specifying generate the stop condition
Enumerator | |
---|---|
I2C_SEND_NO_STOP |
Do not send stop signal. |
I2C_SEND_STOP |
Send stop signal. |
Definition at line 26 of file isf_i2c_master_adapter.h.
isf_status_t i2c_master_adapter_acquire_lock | ( | busHandle_t * | apBusHandle, |
isf_duration_t | aTimeout | ||
) |
This function locks the bus for exclusive access.
i2c_master_adapter_acquire_lock() serializes multi-client access. While holding the bus lock, no other clients may perform any bus operations. Therefore, it is important to release the lock with i2c_master_adapter_release_lock() as soon as practical.
[in] | apBusHandle | The handle of the bus to be started. |
[in] | aTimeout | The time to wait for the lock before returning without the lock. The timeout parameter may be set to zero to wait for calls that fail to return without acquiring the lock, or wait as long as necessary for the lock to be acquired. |
ISF_SUCCESS | is returned when the bus lock is acquired. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized channel. |
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 pointer argument was passed into the function. |
Definition at line 130 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busConfig, COMM_ERROR_NULL_PTR, ISF_SUCCESS, busHandle_struct::pHandle, and i2c_Master_BusConfig_struct::timeout.
isf_status_t i2c_master_adapter_configure | ( | busHandle_t * | apBusHandle, |
void * | apBusConfig | ||
) |
This function reconfigures an already initialized bus.
A bus may be reconfigured after initialization. Calls to i2c_master_adapter_configure() after initialization will override any previous configuration values and must be made while the bus state is COMM_STATE_STOPPED. The typical usage involves retrieving the current configuration using i2c_master_adapter_get_config(), making modifications to the returned configuration, and then calling i2c_master_adapter_configure() with the updated configuration. The bus is implicitly locked during the configuration.
[in] | apBusHandle | The handle of the bus to be configured. |
[in] | apBusConfig | The configuration value for the bus to be configured. |
ISF_SUCCESS | is returned when the bus was reconfigured successfully. |
COMM_ERROR_STOP | is returned when the bus was not STOPPED. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
Definition at line 69 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busConfig, i2c_Master_BusHandle_struct::busInstance, i2c_Master_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, COMM_ERROR_STOP, COMM_STATE_INIT, COMM_STATE_STOPPED, i2c_Master_BusConfig_struct::defaultSpeed, ISF_SUCCESS, i2c_Master_BusHandle_struct::master, busHandle_struct::pHandle, and i2c_Master_BusConfig_struct::timeout.
isf_status_t i2c_master_adapter_get_config | ( | busHandle_t * | apBusHandle, |
void * | apBusConfig | ||
) |
This function returns the current bus configuration.
A bus may be queried for the current configuration.
[in] | apBusHandle | The handle of the bus to be queried. |
[out] | apBusConfig | The address of a bus configuration to be filled. |
ISF_SUCCESS | is returned when the bus configuration is retrieved successfully. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized bus. |
Definition at line 112 of file isf_i2c_master_adapter.c.
References COMM_ERROR_NULL_PTR, ISF_SUCCESS, and busHandle_struct::pHandle.
isf_status_t i2c_master_adapter_get_endpoint | ( | busHandle_t * | apBusHandle, |
void * | apDevice, | ||
void ** | apEndpointHandle | ||
) |
This function creates a endpoint for a device at a specified bus address.
The i2c_master_adapter_get_endpoint() function may be used to get a handle to a device at a known bus address.
[in] | apBusHandle | The handle of the bus to be opened. |
[in] | apDevice | The known information of the device to be opened. |
[out] | apEndpointHandle | The address of a apEndpointHandle to be filled. |
ISF_SUCCESS | is returned when the device is located and a valid handle is returned. |
COMM_ERROR_NOEXIST | is returned when a device does not exist at the specified bus. |
COMM_ERROR_INIT | is returned when the channel handle refers to a non-initialized channel. |
COMM_ERROR_STOP | is returned when the channel has not been started. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
Definition at line 207 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busConfig, i2c_Master_BusHandle_struct::busInstance, i2c_Master_BusHandle_struct::busState, COMM_ERROR_NOEXIST, COMM_ERROR_NULL_PTR, COMM_ERROR_STOP, COMM_STATE_OK, i2c_deviceEndpoint_struct::device, ISF_SUCCESS, i2c_deviceEndpoint_struct::pBusHandle, busHandle_struct::pHandle, and i2c_Master_BusConfig_struct::timeout.
comm_State_t i2c_master_adapter_get_state | ( | busHandle_t * | apBusHandle | ) |
This function returns the current 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 | is returned when a NULL pointer argument was passed into the function. |
Definition at line 98 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, and busHandle_struct::pHandle.
isf_status_t i2c_master_adapter_init | ( | comm_Id_t | aBusId, |
busHandle_t * | apBusHandle | ||
) |
This function initializes a i2c bus.
A bus must be initialized prior to use. Initialization creates the bus and initializes the data structures required to manage the bus.
[in] | aBusId | The ID of the bus to initialize. This is an index into the array of known i2c buses that can be used. |
[out] | apBusHandle | The handle to the bus to be initialized. |
ISF_SUCCESS | is returned when the bus is initialized successfully and the apBusHandle structure reference has been populated with initialized i2c bus data. |
COMM_ERROR_NOEXIST | is returned when the supplied bus identifier does not exist. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_INIT | is returned when the bus could not be initialized. |
Definition at line 37 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busInstance, i2c_Master_BusHandle_struct::busState, COMM_ERROR_NOEXIST, COMM_STATE_INIT, COMM_STATE_NO_INIT, gSys_NumI2cBuses, I2C_MASTER_ADAPTER_LOCK_DEFAULT, i2c_Master_mutexHandler, ISF_SUCCESS, busHandle_struct::nLock, busHandle_struct::pHandle, and busHandle_struct::pLock.
isf_status_t i2c_master_adapter_read | ( | void * | apEndpointHandle, |
int32 | offset, | ||
void * | apReadBuffer, | ||
uint32 | aBuffsize, | ||
uint32 | aNbyteRead, | ||
i2c_readFlags_t | aFlags | ||
) |
This function reads from a i2c device.
i2c_master_adapter_read() reads data from the specified device. The supplied command is sent to the device triggering the device to return some data. Any data returned by the device is read and placed in the provided read buffer. The device is implicitly locked during the read.
[in] | apEndpointHandle | The handle to the device endpoint for. |
[in] | offset | The read offset/sub address from which the data to be read. |
[in] | apReadBuffer | The buffer address where any returned data is placed. |
[in] | aBuffsize | The size of the buffer passed. |
[in] | aNbyteRead | The number of bytes to read from the device. |
[in] | aFlags | The read flag that change the mode of read of operation. |
ISF_SUCCESS | is returned when data from the device was read successfully. |
COMM_ERROR_BUF_SIZE | is returned when the provided buffer is too small to hold all the data or the number of bytes read is zero. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument 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 a lock could not be acquired properly. |
Definition at line 305 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busConfig, i2c_Master_BusHandle_struct::busInstance, i2c_Master_BusHandle_struct::busState, COMM_ERROR_BUF_SIZE, COMM_ERROR_INIT, COMM_ERROR_NULL_PTR, COMM_STATE_OK, i2c_deviceEndpoint_struct::device, INVALID_OFFSET, ISF_SUCCESS, i2c_deviceEndpoint_struct::pBusHandle, busHandle_struct::pHandle, and i2c_Master_BusConfig_struct::timeout.
isf_status_t i2c_master_adapter_release_endpoint | ( | i2c_Endpoint_t * | apEndpoint | ) |
This function closes a particular endpoint.
The i2c_master_adapter_release_endpoint() function is used when no further communication with the device is needed. A closed device should not be passed to i2c_master_adapter_write() or i2c_master_adapter_write().
[in] | apEndpoint | The address of the end point where the endpoint is established. |
ISF_SUCCESS | is returned when the device changes to closed. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
Definition at line 252 of file isf_i2c_master_adapter.c.
References COMM_ERROR_NULL_PTR, and ISF_SUCCESS.
isf_status_t i2c_master_adapter_release_lock | ( | busHandle_t * | apBusHandle | ) |
This function releases exclusive bus access.
i2c_master_adapter_release_lock() is used to relinquish exclusive access on a particular bus. It is the inverse of i2c_master_adapter_acquire_lock().
[in] | apBusHandle | The handle of the bus to unlock. |
ISF_SUCCESS | is returned when the bus released successfully. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized channel. |
COMM_ERROR_LOCK | is returned when no lock was held on the specified bus. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
Definition at line 147 of file isf_i2c_master_adapter.c.
References COMM_ERROR_NULL_PTR, and ISF_SUCCESS.
isf_status_t i2c_master_adapter_start | ( | busHandle_t * | apBusHandle | ) |
This function starts a bus.
i2c_master_adapter_start() enables communications with an initialized bus.
[in] | apBusHandle | The handle of the bus to be started. |
ISF_SUCCESS | is returned when the bus was started successfully. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized channel. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
COMM_ERROR_TIME_OUT | is returned when the request could not be fulfilled in the specified timeout period. |
Definition at line 163 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busConfig, i2c_Master_BusHandle_struct::busInstance, i2c_Master_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, COMM_STATE_OK, busHandle_struct::pHandle, and i2c_Master_BusConfig_struct::timeout.
isf_status_t i2c_master_adapter_stop | ( | busHandle_t * | apBusHandle | ) |
This function stops the given i2c bus.
i2c_master_adapter_stop() disables an initialized bus and stops communications with the channel.
[in] | apBusHandle | The handle of the bus to be stopped. |
ISF_SUCCESS | is returned when the bus is successfully stopped. |
COMM_ERROR_INIT | is returned when the bus handle refers to a non-initialized channel. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument was passed into the function. |
Definition at line 185 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busConfig, i2c_Master_BusHandle_struct::busInstance, i2c_Master_BusHandle_struct::busState, COMM_ERROR_NULL_PTR, COMM_STATE_STOPPED, busHandle_struct::pHandle, and i2c_Master_BusConfig_struct::timeout.
isf_status_t i2c_master_adapter_write | ( | void * | apEndpointHandle, |
int32 | offset, | ||
void * | apWriteBuffer, | ||
uint32 | aBuffsize, | ||
uint32 | aNbyteWrite, | ||
i2c_writeFlags_t | aFlags | ||
) |
This function writes to a i2c device.
i2c_master_adapter_write () writes data to the specified device. The device is implicitly locked during the write.
[in] | apEndpointHandle | The handle to the device endpoint to which to write is performed. |
[in] | offset | The read offset/sub address from which the data to be write. |
[in] | apWriteBuffer | The buffer address where write data is placed. |
[in] | aBuffsize | The size of the buffer passed. |
[in] | aNbyteWrite | The number of bytes to write to the device. |
[in] | aFlags | The write flag that change the mode of read of operation. |
ISF_SUCCESS | is returned when the device was written successfully. |
COMM_ERROR_STOP | is returned when the write is invoked on a stopped channel. |
COMM_ERROR_NULL_PTR | is returned when a NULL pointer argument 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 a lock could not be acquired properly. |
Definition at line 269 of file isf_i2c_master_adapter.c.
References i2c_Master_BusHandle_struct::busConfig, i2c_Master_BusHandle_struct::busInstance, i2c_Master_BusHandle_struct::busState, COMM_ERROR_BUF_SIZE, COMM_ERROR_INIT, COMM_ERROR_NULL_PTR, COMM_STATE_OK, i2c_deviceEndpoint_struct::device, INVALID_OFFSET, ISF_SUCCESS, i2c_deviceEndpoint_struct::pBusHandle, busHandle_struct::pHandle, and i2c_Master_BusConfig_struct::timeout.