| ISF 2.2 rev 5 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

isf_i2c_master_adapter.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: isf_i2c_master_adapter.h
4 *
5 * Copyright (c) 2015, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file isf_i2c_master_adapter.h
10 * @brief \b isf_i2c_master_adapter.h defines the API definitions and types for the i2c master protocol adapter.
11 */
12 #ifndef ISF_I2C_MASTER_ADAPTER_H_
13 #define ISF_I2C_MASTER_ADAPTER_H_
14 #include "isf_i2c_master_types.h"
15 #include "fsl_i2c_master_driver.h"
16 #include "fsl_i2c_hal.h"
17 #include "isf_comm.h"
18 #include "isf_protocol_adapter.h"
19 /*! @brief This structure defines a device endpoint encapsulation for i2c handler. */
20 typedef struct i2c_deviceEndpoint_struct
21 {
22 busHandle_t* pBusHandle; /*!< The pointer to the bus handle. */
23 i2c_device_t device; /*!< The slave address. */
24 }i2c_Endpoint_t;
25 /*! Type specifying generate the stop condition */
26 enum i2c_comm_flag {
27 I2C_SEND_NO_STOP = 1 <<0, /*!< Do not send stop signal. */
28 I2C_SEND_STOP = 1 <<1, /*!< Send stop signal. */
29 };
30
31
32 typedef comm_Flags_t i2c_writeFlags_t;
33 typedef comm_Flags_t i2c_readFlags_t;
34 /*! @brief This function initializes a i2c bus.
35 *
36 * @details A bus must be initialized prior to use. Initialization creates the bus and initializes the data structures required to manage the bus.
37 *
38 * @param[in] aBusId The ID of the bus to initialize. This is an index into the array of known i2c buses that can be used.
39 * @param[out] apBusHandle The handle to the bus to be initialized.
40 *
41 * @return ::i2c_master_adapter_init() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
42 * @retval ::ISF_SUCCESS is returned when the bus is initialized successfully and the apBusHandle structure reference has been
43 * populated with initialized i2c bus data.
44 * @retval ::COMM_ERROR_NOEXIST is returned when the supplied bus identifier does not exist.
45 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
46 * @retval ::COMM_ERROR_INIT is returned when the bus could not be initialized.
47 *
48 *
49 * @Constraints None
50 *
51 * @Reentrant Yes
52 * @Libs None
53 */
54 isf_status_t i2c_master_adapter_init(comm_Id_t aBusId, busHandle_t *apBusHandle);
55 /*! @brief This function reconfigures an already initialized bus.
56 *
57 * @details A bus may be reconfigured after initialization. Calls to i2c_master_adapter_configure() after initialization will override any previous
58 * configuration values and must be made while the bus state is ::COMM_STATE_STOPPED. The typical usage involves retrieving the
59 * current configuration using ::i2c_master_adapter_get_config(), making modifications to the returned configuration, and then calling
60 * i2c_master_adapter_configure() with the updated configuration. The bus is implicitly locked during the configuration.
61 *
62 * @param[in] apBusHandle The handle of the bus to be configured.
63 * @param[in] apBusConfig The configuration value for the bus to be configured.
64 *
65 * @return ::i2c_master_adapter_configure() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
66 * @retval ::ISF_SUCCESS is returned when the bus was reconfigured successfully.
67 * @retval ::COMM_ERROR_STOP is returned when the bus was not STOPPED.
68 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
69 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
70 *
71 *
72 * @Constraints The following constraints must be observed when using this function:
73 * @li apBusHandle must be valid. A valid i2c bus handler is created
74 * when the ::i2c_master_adapter_init() function call is successfully returned.
75 *
76 * @Reentrant Yes
77 * @Libs None
78 */
79 isf_status_t i2c_master_adapter_configure(busHandle_t *apBusHandle, void* apBusConfig);
80 /*! @brief This function returns the current bus state.
81 *
82 * @details A bus may be queried for its current state.
83 *
84 * @param[in] apBusHandle The handle of the bus to be queried.
85 *
86 * @return ::i2c_master_adapter_get_state() returns a value of type
87 * ::comm_State_t indicating the current state of the bus.
88 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
89 *
90 * @Constraints The following constraints must be observed when using this function:
91 * @li apBusHandle must be valid. A valid i2c bus handle is created when ::i2c_master_adapter_init() function call returns successfully.
92 *
93 * @Reentrant Yes
94 * @Libs None.
95 */
96 comm_State_t i2c_master_adapter_get_state(busHandle_t *apBusHandle);
97 /*! @brief This function returns the current bus configuration.
98 *
99 * @details A bus may be queried for the current configuration.
100 *
101 * @param[in] apBusHandle The handle of the bus to be queried.
102 * @param[out] apBusConfig The address of a bus configuration to be filled.
103 *
104 * @return ::i2c_master_adapter_get_config() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
105 * @retval ::ISF_SUCCESS is returned when the bus configuration is retrieved successfully.
106 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
107 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized bus.
108
109 * @Constraints The following constraints must be observed when using this function:
110 * @li apBusHandle must be valid. A valid i2c bus handle is created when the ::i2c_master_adapter_init() function call returns successfully.
111 *
112 * @Reentrant Yes
113 * @Libs None
114 */
115 isf_status_t i2c_master_adapter_get_config(busHandle_t *apBusHandle, void* apBusConfig);
116 /*! @brief This function locks the bus for exclusive access.
117 *
118 * @details i2c_master_adapter_acquire_lock() serializes multi-client access. While holding the bus lock,
119 * no other clients may perform any bus operations. Therefore, it is important to release the lock
120 * with ::i2c_master_adapter_release_lock() as soon as practical.
121 *
122 * @param[in] apBusHandle The handle of the bus to be started.
123 * @param[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
124 * acquiring the lock, or wait as long as necessary for the lock to be acquired.
125 * @return ::dm_channel_acquire_lock() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
126 * @retval ::ISF_SUCCESS is returned when the bus lock is acquired.
127 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
128 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
129 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
130 *
131 * @Constraints The following constraints must be observed when using this function:
132 * @li apBusHandle must be valid. A valid i2c bus handle is created when the ::i2c_master_adapter_init() function call returns successfully.
133 *
134 * @Reentrant Yes
135 * @Libs None
136 */
137 isf_status_t i2c_master_adapter_acquire_lock(busHandle_t *apBusHandle, isf_duration_t aTimeout );
138 /*! @brief This function releases exclusive bus access.
139 *
140 * @details 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().
141 *
142 * @param[in] apBusHandle The handle of the bus to unlock.
143 * @return ::i2c_master_adapter_release_lock() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
144 * @retval ::ISF_SUCCESS is returned when the bus released successfully.
145 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
146 * @retval ::COMM_ERROR_LOCK is returned when no lock was held on the specified bus.
147 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
148 *
149 * @Constraints The following constraints must be observed when using this function:
150 * @li apBusHandle must be valid. A valid i2c bus handle is created when the ::i2c_master_adapter_init() function call returns successfully.
151 *
152 * @Reentrant Yes
153 * @Libs None
154 */
155 isf_status_t i2c_master_adapter_release_lock(busHandle_t *apBusHandle);
156 /*! @brief This function starts a bus.
157 *
158 * @details i2c_master_adapter_start() enables communications with an initialized bus.
159 * @param[in] apBusHandle The handle of the bus to be started.
160 * @return ::i2c_master_adapter_start() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
161 * @retval ::ISF_SUCCESS is returned when the bus was started successfully.
162 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
163 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
164 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
165 *
166 * @Constraints The following constraints must be observed when using this function:
167 * @li apBusHandle must be valid. A valid i2c bus handle is created when the ::i2c_master_adapter_init() function call returns successfully.
168 *
169 * @Reentrant Yes
170 * @Libs None
171 */
172 isf_status_t i2c_master_adapter_start(busHandle_t *apBusHandle);
173 /*! @brief This function stops the given i2c bus.
174 *
175 * @details i2c_master_adapter_stop() disables an initialized bus and stops communications with the channel.
176 *
177 * @param[in] apBusHandle The handle of the bus to be stopped.
178 * @return ::i2c_master_adapter_stop() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
179 *
180 * @retval ::ISF_SUCCESS is returned when the bus is successfully stopped.
181 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
182 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
183 *
184 * @Constraints The following constraints must be observed when using this function:
185 * @li apBusHandle must be valid. A valid i2c bus handle is created when the ::i2c_master_adapter_init() function call returns successfully.
186 *
187 * @Reentrant Yes
188 * @Libs None
189 */
190 isf_status_t i2c_master_adapter_stop(busHandle_t *apBusHandle);
191 /*! @brief This function creates a endpoint for a device at a specified bus address.
192 *
193 * @details The i2c_master_adapter_get_endpoint() function may be used to get a handle to a device at a known bus address.
194 *
195 * @param[in] apBusHandle The handle of the bus to be opened.
196 * @param[in] apDevice The known information of the device to be opened.
197 * @param[out] apEndpointHandle The address of a apEndpointHandle to be filled.
198 *
199 * @return ::i2c_master_adapter_get_endpoint() returns a value of type ::isf_status_t indicating the success or failure of the function call.
200 *
201 * @retval ::ISF_SUCCESS is returned when the device is located and a valid handle is returned.
202 * @retval ::COMM_ERROR_NOEXIST is returned when a device does not exist at the specified bus.
203 * @retval ::COMM_ERROR_INIT is returned when the channel handle refers to a non-initialized channel.
204 * @retval ::COMM_ERROR_STOP is returned when the channel has not been started.
205 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
206 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
207 *
208 * @Constraints The following constraints must be observed when using this function:
209 * @li apBusHandle must be valid. A valid i2c bus handle is created when the ::i2c_master_adapter_init() function call returns successfully.
210 *
211 * @Reentrant Yes
212 * @Libs isf_core.lib
213 */
214 isf_status_t i2c_master_adapter_get_endpoint(busHandle_t *apBusHandle, void *apDevice , void** apEndpointHandle);
215 /*! @brief This function closes a particular endpoint.
216 *
217 * @details The i2c_master_adapter_release_endpoint() function is used when no further communication with the device is needed. A closed device should not be
218 * passed to ::i2c_master_adapter_write() or ::i2c_master_adapter_write().
219 *
220 * @param[in] apEndpoint The address of the end point where the endpoint is established.
221 * @return ::i2c_master_adapter_release_endpoint() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
222 * @retval ::ISF_SUCCESS is returned when the device changes to closed.
223 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
224 *
225 * @Constraints The following constraints must be observed when using this function:
226 * @li pBusHandle must be valid. A valid i2c bus handle is created when the ::i2c_master_adapter_init() function call returns successfully.
227 *
228 * @Reentrant Yes
229 * @Libs None
230 */
231 isf_status_t i2c_master_adapter_release_endpoint(i2c_Endpoint_t *apEndpoint);
232 /*! @brief This function writes to a i2c device.
233 *
234 * @details i2c_master_adapter_write () writes data to the specified device. The device is implicitly locked during the write.
235 *
236 * @param[in] apEndpointHandle The handle to the device endpoint to which to write is performed.
237 * @param[in] offset The read offset/sub address from which the data to be write.
238 * @param[in] apWriteBuffer The buffer address where write data is placed.
239 * @param[in] aBuffsize The size of the buffer passed.
240 * @param[in] aNbyteWrite The number of bytes to write to the device.
241 * @param[in] aFlags The write flag that change the mode of read of operation.
242 * @return ::i2c_master_adapter_write() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
243 * @retval ::ISF_SUCCESS is returned when the device was written successfully.
244 * @retval ::COMM_ERROR_STOP is returned when the write is invoked on a stopped channel.
245 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
246 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
247 * @retval ::COMM_ERROR_LOCK is returned when a lock could not be acquired properly.
248 *
249 * @Constraints The following constraints must be observed when using this function:
250 * @li apEndpointHandle must be valid. A valid device endpoint handle is created when the ::i2c_master_adapter_get_endpoint() function returns successfully.
251 *
252 * @Reentrant Yes
253 * @Libs isf_core.lib
254 */
255 isf_status_t i2c_master_adapter_write(void* apEndpointHandle, int32 offset, void* apWriteBuffer, uint32 aBuffsize, uint32 aNbyteWrite, i2c_writeFlags_t aFlags);
256 /*! @brief This function reads from a i2c device.
257 *
258 * @details i2c_master_adapter_read() reads data from the specified device. The supplied command is sent to the device triggering the
259 * device to return some data. Any data returned by the device is read and placed in the provided read buffer.
260 * The device is implicitly locked during the read.
261 *
262 * @param[in] apEndpointHandle The handle to the device endpoint for.
263 * @param[in] offset The read offset/sub address from which the data to be read.
264 * @param[in] apReadBuffer The buffer address where any returned data is placed.
265 * @param[in] aBuffsize The size of the buffer passed.
266 * @param[in] aNbyteRead The number of bytes to read from the device.
267 * @param[in] aFlags The read flag that change the mode of read of operation.
268
269 * @return ::i2c_master_adapter_read() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
270 *
271 * @retval ::ISF_SUCCESS is returned when data from the device was read successfully.
272 * @retval ::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.
273 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
274 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
275 * @retval ::COMM_ERROR_LOCK is returned when a lock could not be acquired properly.
276 *
277 * @Constraints The following constraints must be observed when using this function:
278 * @li apEndpointHandle must be valid. A valid device endpoint handle is created when the ::i2c_master_adapter_get_endpoint() function returns successfully.
279 *
280 * @Reentrant Yes
281 * @Libs None
282 */
283 isf_status_t i2c_master_adapter_read(void* apEndpointHandle, int32 offset, void* apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead, i2c_readFlags_t aFlags);
284
285
286 #endif /* ISF_I2C_MASTER_ADAPTER_H_ */
287
288
isf_i2c_master_types.h
isf_i2c_master_types.h defines the i2c master protocol adapter structure and types.
i2c_master_adapter_release_endpoint
isf_status_t i2c_master_adapter_release_endpoint(i2c_Endpoint_t *apEndpoint)
This function closes a particular endpoint.
Definition: isf_i2c_master_adapter.c:252
i2c_master_adapter_get_config
isf_status_t i2c_master_adapter_get_config(busHandle_t *apBusHandle, void *apBusConfig)
This function returns the current bus configuration.
Definition: isf_i2c_master_adapter.c:112
i2c_master_adapter_release_lock
isf_status_t i2c_master_adapter_release_lock(busHandle_t *apBusHandle)
This function releases exclusive bus access.
Definition: isf_i2c_master_adapter.c:147
comm_Id_t
uint32 comm_Id_t
This type is for a numeric channel identifier- index into an array of channels in the system...
Definition: isf_comm.h:50
i2c_deviceEndpoint_struct
This structure defines a device endpoint encapsulation for i2c handler.
Definition: isf_i2c_master_adapter.h:20
i2c_master_adapter_stop
isf_status_t i2c_master_adapter_stop(busHandle_t *apBusHandle)
This function stops the given i2c bus.
Definition: isf_i2c_master_adapter.c:185
i2c_comm_flag
i2c_comm_flag
Definition: isf_i2c_master_adapter.h:26
i2c_master_adapter_configure
isf_status_t i2c_master_adapter_configure(busHandle_t *apBusHandle, void *apBusConfig)
This function reconfigures an already initialized bus.
Definition: isf_i2c_master_adapter.c:69
i2c_master_adapter_get_endpoint
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.
Definition: isf_i2c_master_adapter.c:207
i2c_master_adapter_get_state
comm_State_t i2c_master_adapter_get_state(busHandle_t *apBusHandle)
This function returns the current bus state.
Definition: isf_i2c_master_adapter.c:98
i2c_master_adapter_acquire_lock
isf_status_t i2c_master_adapter_acquire_lock(busHandle_t *apBusHandle, isf_duration_t aTimeout)
This function locks the bus for exclusive access.
Definition: isf_i2c_master_adapter.c:130
isf_protocol_adapter.h
isf_protocol_adapter.h defines the general interface definition for the protocol adapter.
I2C_SEND_STOP
Definition: isf_i2c_master_adapter.h:28
i2c_deviceEndpoint_struct::device
i2c_device_t device
Definition: isf_i2c_master_adapter.h:23
i2c_master_adapter_start
isf_status_t i2c_master_adapter_start(busHandle_t *apBusHandle)
This function starts a bus.
Definition: isf_i2c_master_adapter.c:163
busHandle_struct
This structure is a declaration of a BusHandle type.
Definition: isf_protocol_adapter.h:86
i2c_Endpoint_t
struct i2c_deviceEndpoint_struct i2c_Endpoint_t
This structure defines a device endpoint encapsulation for i2c handler.
i2c_readFlags_t
comm_Flags_t i2c_readFlags_t
Definition: isf_i2c_master_adapter.h:33
comm_Flags_t
uint8 comm_Flags_t
This is a bit array of flags governing device read/write behavior.
Definition: isf_comm.h:59
I2C_SEND_NO_STOP
Definition: isf_i2c_master_adapter.h:27
isf_duration_t
uint32 isf_duration_t
ISF time duration in microseconds.
Definition: isf.h:84
int32
signed long int int32
Definition: isf_types.h:74
i2c_master_adapter_write
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.
Definition: isf_i2c_master_adapter.c:269
i2c_master_adapter_init
isf_status_t i2c_master_adapter_init(comm_Id_t aBusId, busHandle_t *apBusHandle)
This function initializes a i2c bus.
Definition: isf_i2c_master_adapter.c:37
isf_status_t
int32 isf_status_t
ISF return status type.
Definition: isf.h:76
isf_comm.h
isf_comm.h defines the common types for the Communications Service Family of the Intelligent Sensing ...
comm_State_t
enum comm_State_vals comm_State_t
This enum holds an enumerated value describing the state of a channel.
Definition: isf_comm.h:53
uint32
unsigned long int uint32
Definition: isf_types.h:78
i2c_writeFlags_t
comm_Flags_t i2c_writeFlags_t
Definition: isf_i2c_master_adapter.h:32
i2c_deviceEndpoint_struct::pBusHandle
busHandle_t * pBusHandle
Definition: isf_i2c_master_adapter.h:22
i2c_master_adapter_read
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.
Definition: isf_i2c_master_adapter.c:305
- © Freescale Semiconductor, Inc. 2016. All Rights Reserved.