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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

isf_uart_adapter.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: isf_uart_adapter.h
4 *
5 * Copyright (c) 2015, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file isf_uart_adapter.h
10 * @brief \b isf_uart_adapter.h defines the API definitions and types for the uart protocol adapter.
11 */
12 #ifndef ISF_UART_ADAPTER_H_
13 #define ISF_UART_ADAPTER_H_
14
15
16 #include "fsl_uart_driver.h"
17
18 #include "isf_comm.h"
19 #include "isf_protocol_adapter.h"
20
21
22 /*! @brief This structure defines a device endpoint encapsulation for uart handler. */
23 typedef struct uart_deviceEndpoint_struct
24 {
25 busHandle_t* pBusHandle; /*!< The pointer to the bus handle. */
26 } uart_Endpoint_t;
27
28 typedef struct uart_userDefinedVars_struct
29 {
30 isf_duration_t timeout;
31 uint8_t uartMode;
32 } uart_UserDefinedVars_t;
33
34
35 enum uart_operation_mode {
36 UART_MODE_INT = 0,
37 UART_MODE_DMA = 1,
38 };
39
40 /*! Type specifying for the uart modes */
41 enum uart_comm_flag {
42 UART_SYNC = 0, /*!< Read/write in synchronized mode.*/
43 UART_ASYNC = 1, /*!< Read/Write in asynchronized mode.*/
44 };
45
46 enum uart_lock_type{
47 UART_LOCK_COMMON,
48 UART_LOCK_READ,
49 UART_LOCK_CONFIG,
50 };
51
52 typedef comm_Flags_t uart_writeFlags_t;
53 typedef comm_Flags_t uart_readFlags_t;
54
55 /* Pointer to uart runtime state structure */
56 extern void * g_uartStatePtr[UART_INSTANCE_COUNT];
57
58 /* Holder for UART User defined Variables. */
59 extern const uart_UserDefinedVars_t * g_uartUserDefinedVars[UART_INSTANCE_COUNT];
60
61
62
63 /*!
64 * @brief Initializes UART User defined parameters.
65 *
66 * This function initializes the run-time state structure to provide the user defined UART
67 * settings.
68 *
69 * @param instance The UART instance to be initialized.
70 * @param userDefinedVars The UART user defined parameters such as timeout and UART Type.
71 *
72 * @return kStatus_UART_Success.
73 */
74 uart_status_t uart_user_init(uint32_t instance, const uart_UserDefinedVars_t * userDefinedVars);
75 /*! @brief This function initializes a uart bus.
76 *
77 * @details A bus must be initialized prior to use. Initialization creates the bus and initializes the data structures required to manage the bus.
78 *
79 * @param[in] aBusId The ID of the bus to initialize. This is an index into the array of known uart buses that can be used.
80 * @param[out] apBusHandle The handle to the bus to be initialized.
81 *
82 * @return ::uart_adapter_init() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
83 * @retval ::ISF_SUCCESS is returned when the bus is initialized successfully and the apBusHandle structure reference has been
84 * populated with initialized uart bus data.
85 * @retval ::COMM_ERROR_NOEXIST is returned when the supplied bus identifier does not exist.
86 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
87 * @retval ::COMM_ERROR_INIT is returned when the bus could not be initialized.
88 *
89 *
90 * @Constraints None
91 *
92 * @Reentrant Yes
93 * @Libs None
94 */
95 isf_status_t uart_adapter_init(comm_Id_t aBusId, busHandle_t *apBusHandle);
96 /*! @brief This function reconfigures an already initialized bus.
97 *
98 * @details A bus may be reconfigured after initialization. Calls to uart_adapter_configure() after initialization will override any previous
99 * configuration values and must be made while the bus state is ::COMM_STATE_STOPPED. The typical usage involves retrieving the
100 * current configuration using ::uart_adapter_get_config(), making modifications to the returned configuration, and then calling
101 * uart_adapter_configure() with the updated configuration. The bus is implicitly locked during the configuration.
102 *
103 * @param[in] apBusHandle The handle of the bus to be configured.
104 * @param[in] apBusConfig The configuration value for the bus to be configured.
105 *
106 * @return ::uart_adapter_configure() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
107 * @retval ::ISF_SUCCESS is returned when the bus was reconfigured successfully.
108 * @retval ::COMM_ERROR_STOP is returned when the bus was not STOPPED.
109 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
110 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
111 *
112 *
113 * @Constraints The following constraints must be observed when using this function:
114 * @li apBusHandle must be valid. A valid uart bus handler is created
115 * when the ::uart_adapter_init() function call is successfully returned.
116 *
117 * @Reentrant Yes
118 * @Libs None
119 */
120 isf_status_t uart_adapter_configure(busHandle_t *apBusHandle, uart_user_config_t* apBusConfig);
121 /*! @brief This function returns the current bus state.
122 *
123 * @details A bus may be queried for its current state.
124 *
125 * @param[in] apBusHandle The handle of the bus to be queried.
126 *
127 * @return ::uart_adapter_get_state() returns a value of type
128 * ::comm_State_t indicating the current state of the bus.
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 uart bus handle is created when ::uart_adapter_init() function call returns successfully.
133 *
134 * @Reentrant Yes
135 * @Libs None.
136 */
137 comm_State_t uart_adapter_get_state(busHandle_t *apBusHandle);
138 /*! @brief This function returns the current bus configuration.
139 *
140 * @details A bus may be queried for the current configuration.
141 *
142 * @param[in] apBusHandle The handle of the bus to be queried.
143 * @param[out] apBusConfig The address of a bus configuration to be filled.
144 *
145 * @return ::uart_adapter_get_config() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
146 * @retval ::ISF_SUCCESS is returned when the bus configuration is retrieved successfully.
147 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
148 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized bus.
149
150 * @Constraints The following constraints must be observed when using this function:
151 * @li apBusHandle must be valid. A valid uart bus handle is created when the ::uart_adapter_init() function call returns successfully.
152 *
153 * @Reentrant Yes
154 * @Libs None
155 */
156 isf_status_t uart_adapter_get_config(busHandle_t *apBusHandle, void* apBusConfig);
157 /*! @brief This function locks the bus for exclusive access.
158 *
159 * @details uart_adapter_acquire_lock() serializes multi-client access. While holding the bus lock,
160 * no other clients may perform any bus operations. Therefore, it is important to release the lock
161 * with ::uart_adapter_release_lock() as soon as practical.
162 *
163 * @param[in] apBusHandle The handle of the bus to be started.
164 * @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
165 * acquiring the lock, or wait as long as necessary for the lock to be acquired.
166 * @return ::dm_channel_acquire_lock() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
167 * @retval ::ISF_SUCCESS is returned when the bus lock is acquired.
168 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
169 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
170 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
171 *
172 * @Constraints The following constraints must be observed when using this function:
173 * @li apBusHandle must be valid. A valid uart bus handle is created when the ::uart_adapter_init() function call returns successfully.
174 *
175 * @Reentrant Yes
176 * @Libs None
177 */
178 isf_status_t uart_adapter_acquire_lock(busHandle_t *apBusHandle, isf_duration_t aTimeout );
179 /*! @brief This function releases exclusive bus access.
180 *
181 * @details uart_adapter_release_lock() is used to relinquish exclusive access on a particular bus. It is the inverse of ::uart_adapter_acquire_lock().
182 *
183 * @param[in] apBusHandle The handle of the bus to unlock.
184 * @return ::uart_adapter_release_lock() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
185 * @retval ::ISF_SUCCESS is returned when the bus released successfully.
186 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
187 * @retval ::COMM_ERROR_LOCK is returned when no lock was held on the specified bus.
188 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
189 *
190 * @Constraints The following constraints must be observed when using this function:
191 * @li apBusHandle must be valid. A valid uart bus handle is created when the ::uart_adapter_init() function call returns successfully.
192 *
193 * @Reentrant Yes
194 * @Libs None
195 */
196 isf_status_t uart_adapter_release_lock(busHandle_t *apBusHandle);
197 /*! @brief This function starts a bus.
198 *
199 * @details uart_adapter_start() enables communications with an initialized bus.
200 * @param[in] apBusHandle The handle of the bus to be started.
201 * @return ::uart_adapter_start() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
202 * @retval ::ISF_SUCCESS is returned when the bus was started successfully.
203 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
204 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
205 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
206 *
207 * @Constraints The following constraints must be observed when using this function:
208 * @li apBusHandle must be valid. A valid uart bus handle is created when the ::uart_adapter_init() function call returns successfully.
209 *
210 * @Reentrant Yes
211 * @Libs None
212 */
213 isf_status_t uart_adapter_start(busHandle_t *apBusHandle);
214 /*! @brief This function stops the given uart bus.
215 *
216 * @details uart_adapter_stop() disables an initialized bus and stops communications with the channel.
217 *
218 * @param[in] apBusHandle The handle of the bus to be stopped.
219 * @return ::uart_adapter_stop() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
220 *
221 * @retval ::ISF_SUCCESS is returned when the bus is successfully stopped.
222 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
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 apBusHandle must be valid. A valid uart bus handle is created when the ::uart_adapter_init() function call returns successfully.
227 *
228 * @Reentrant Yes
229 * @Libs None
230 */
231 isf_status_t uart_adapter_stop(busHandle_t *apBusHandle);
232 /*! @brief This function creates a endpoint at a already initialized bus.
233 *
234 * @details The uart_adapter_get_endpoint() function may be used to get a handle to a intialized device.
235 *
236 * @param[in] apBusHandle The handle of the bus to be opened.
237 * @param[in] apDevice The known information of the device to be opened.
238 * @param[out] apEndpointHandle The address of a apEndpointHandle to be filled.
239 *
240 * @return ::uart_adapter_get_endpoint() returns a value of type ::isf_status_t indicating the success or failure of the function call.
241 *
242 * @retval ::ISF_SUCCESS is returned when the device is located and a valid handle is returned.
243 * @retval ::COMM_ERROR_NOEXIST is returned when a device does not exist at the specified bus.
244 * @retval ::COMM_ERROR_INIT is returned when the channel handle refers to a non-initialized channel.
245 * @retval ::COMM_ERROR_STOP is returned when the channel has not been started.
246 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
247 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
248 *
249 * @Constraints The following constraints must be observed when using this function:
250 * @li apBusHandle must be valid. A valid uart bus handle is created when the ::uart_adapter_init() function call returns successfully.
251 *
252 * @Reentrant Yes
253 * @Libs isf_core.lib
254 */
255 isf_status_t uart_adapter_get_endpoint(busHandle_t *apBusHandle, void *apDevice , void** apEndpointHandle);
256 /*! @brief This function closes a particular endpoint.
257 *
258 * @details The uart_adapter_release_endpoint() function is used when no further communication with the device is needed. A closed device should not be
259 * passed to ::uart_adapter_write() or ::uart_adapter_write().
260 *
261 * @param[in] apEndpoint The address of the end point where the endpoint is established.
262 * @return ::uart_adapter_release_endpoint() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
263 * @retval ::ISF_SUCCESS is returned when the device changes to closed.
264 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
265 *
266 * @Constraints The following constraints must be observed when using this function:
267 * @li pBusHandle must be valid. A valid uart bus handle is created when the ::uart_adapter_init() function call returns successfully.
268 *
269 * @Reentrant Yes
270 * @Libs None
271 */
272 isf_status_t uart_adapter_release_endpoint(uart_Endpoint_t *apEndpoint);
273 /*! @brief This function writes to a uart device.
274 *
275 * @details uart_adapter_write () writes data to the specified device. The device is implicitly locked during the write.
276 *
277 * @param[in] apEndpointHandle The handle to the device endpoint to which to write is performed.
278 * @param[in] offset The read offset/sub address from which the data to be write.
279 * @param[in] apWriteBuffer The buffer address where write data is placed.
280 * @param[in] aBuffsize The size of the buffer passed.
281 * @param[in] aNbyteWrite The number of bytes to write to the device.
282 * @param[in] aFlags The write flag that change the mode of read of operation.
283 * @return ::uart_adapter_write() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
284 * @retval ::ISF_SUCCESS is returned when the device was written successfully.
285 * @retval ::COMM_ERROR_STOP is returned when the write is invoked on a stopped channel.
286 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
287 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
288 * @retval ::COMM_ERROR_LOCK is returned when a lock could not be acquired properly.
289 *
290 * @Constraints The following constraints must be observed when using this function:
291 * @li apEndpointHandle must be valid. A valid device endpoint handle is created when the ::uart_adapter_get_endpoint() function returns successfully.
292 *
293 * @Reentrant Yes
294 * @Libs isf_core.lib
295 */
296 isf_status_t uart_adapter_write(void* apEndpointHandle, int32 offset, void* apWriteBuffer, uint32 aBuffsize, uint32 aNbyteWrite, uart_writeFlags_t aFlags);
297 /*! @brief This function reads from a uart device.
298 *
299 * @details uart_adapter_read() reads data from the specified device. It wait for the requested number of bytes to be read from the UART receive buffer.
300 * The device is implicitly locked during the read.
301 *
302 * @param[in] apEndpointHandle The handle to the device endpoint for.
303 * @param[in] offset The read offset/sub address from which the data to be read.
304 * @param[in] apReadBuffer The buffer address where any returned data is placed.
305 * @param[in] aBuffsize The size of the buffer passed.
306 * @param[in] aNbyteRead The number of bytes to read from the device.
307 * @param[in] aFlags The read flag that change the mode of read of operation.
308
309 * @return ::uart_adapter_read() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
310 *
311 * @retval ::ISF_SUCCESS is returned when data from the device was read successfully.
312 * @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.
313 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
314 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
315 * @retval ::COMM_ERROR_LOCK is returned when a lock could not be acquired properly.
316 *
317 * @Constraints The following constraints must be observed when using this function:
318 * @li apEndpointHandle must be valid. A valid device endpoint handle is created when the ::uart_adapter_get_endpoint() function returns successfully.
319 *
320 * @Reentrant Yes
321 * @Libs None
322 */
323 isf_status_t uart_adapter_read(void* apEndpointHandle, int32 offset, void* apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead, uart_readFlags_t aFlags);
324
325 #endif /* ISF_UART_ADAPTER_H_ */
326
327
328
uart_operation_mode
uart_operation_mode
Definition: isf_uart_adapter.h:35
uart_adapter_configure
isf_status_t uart_adapter_configure(busHandle_t *apBusHandle, uart_user_config_t *apBusConfig)
This function reconfigures an already initialized bus.
Definition: isf_uart_adapter.c:75
uart_adapter_get_state
comm_State_t uart_adapter_get_state(busHandle_t *apBusHandle)
This function returns the current bus state.
Definition: isf_uart_adapter.c:110
UART_LOCK_CONFIG
Definition: isf_uart_adapter.h:49
uart_adapter_write
isf_status_t uart_adapter_write(void *apEndpointHandle, int32 offset, void *apWriteBuffer, uint32 aBuffsize, uint32 aNbyteWrite, uart_writeFlags_t aFlags)
This function writes to a uart device.
Definition: isf_uart_adapter.c:268
UART_MODE_DMA
Definition: isf_uart_adapter.h:37
g_uartStatePtr
void * g_uartStatePtr[UART_INSTANCE_COUNT]
uart_adapter_get_endpoint
isf_status_t uart_adapter_get_endpoint(busHandle_t *apBusHandle, void *apDevice, void **apEndpointHandle)
This function creates a endpoint at a already initialized bus.
Definition: isf_uart_adapter.c:225
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
uart_adapter_stop
isf_status_t uart_adapter_stop(busHandle_t *apBusHandle)
This function stops the given uart bus.
Definition: isf_uart_adapter.c:200
uart_adapter_release_endpoint
isf_status_t uart_adapter_release_endpoint(uart_Endpoint_t *apEndpoint)
This function closes a particular endpoint.
Definition: isf_uart_adapter.c:253
uart_userDefinedVars_struct::timeout
isf_duration_t timeout
Definition: isf_uart_adapter.h:30
UART_LOCK_COMMON
Definition: isf_uart_adapter.h:47
uart_deviceEndpoint_struct::pBusHandle
busHandle_t * pBusHandle
Definition: isf_uart_adapter.h:25
uart_adapter_acquire_lock
isf_status_t uart_adapter_acquire_lock(busHandle_t *apBusHandle, isf_duration_t aTimeout)
This function locks the bus for exclusive access.
Definition: isf_uart_adapter.c:142
UART_ASYNC
Definition: isf_uart_adapter.h:43
isf_protocol_adapter.h
isf_protocol_adapter.h defines the general interface definition for the protocol adapter.
uart_comm_flag
uart_comm_flag
Definition: isf_uart_adapter.h:41
uart_adapter_init
isf_status_t uart_adapter_init(comm_Id_t aBusId, busHandle_t *apBusHandle)
This function initializes a uart bus.
Definition: isf_uart_adapter.c:43
busHandle_struct
This structure is a declaration of a BusHandle type.
Definition: isf_protocol_adapter.h:86
uart_Endpoint_t
struct uart_deviceEndpoint_struct uart_Endpoint_t
This structure defines a device endpoint encapsulation for uart handler.
uart_lock_type
uart_lock_type
Definition: isf_uart_adapter.h:46
comm_Flags_t
uint8 comm_Flags_t
This is a bit array of flags governing device read/write behavior.
Definition: isf_comm.h:59
UART_LOCK_READ
Definition: isf_uart_adapter.h:48
uart_UserDefinedVars_t
struct uart_userDefinedVars_struct uart_UserDefinedVars_t
uart_readFlags_t
comm_Flags_t uart_readFlags_t
Definition: isf_uart_adapter.h:53
uart_adapter_get_config
isf_status_t uart_adapter_get_config(busHandle_t *apBusHandle, void *apBusConfig)
This function returns the current bus configuration.
Definition: isf_uart_adapter.c:124
uart_adapter_release_lock
isf_status_t uart_adapter_release_lock(busHandle_t *apBusHandle)
This function releases exclusive bus access.
Definition: isf_uart_adapter.c:159
uart_userDefinedVars_struct
Definition: isf_uart_adapter.h:28
UART_MODE_INT
Definition: isf_uart_adapter.h:36
uart_writeFlags_t
comm_Flags_t uart_writeFlags_t
Definition: isf_uart_adapter.h:52
uart_user_init
uart_status_t uart_user_init(uint32_t instance, const uart_UserDefinedVars_t *userDefinedVars)
Initializes UART User defined parameters.
Definition: isf_uart_adapter.c:432
isf_duration_t
uint32 isf_duration_t
ISF time duration in microseconds.
Definition: isf.h:84
uart_adapter_start
isf_status_t uart_adapter_start(busHandle_t *apBusHandle)
This function starts a bus.
Definition: isf_uart_adapter.c:175
int32
signed long int int32
Definition: isf_types.h:74
uart_deviceEndpoint_struct
This structure defines a device endpoint encapsulation for uart handler.
Definition: isf_uart_adapter.h:23
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
UART_SYNC
Definition: isf_uart_adapter.h:42
uint32
unsigned long int uint32
Definition: isf_types.h:78
uart_adapter_read
isf_status_t uart_adapter_read(void *apEndpointHandle, int32 offset, void *apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead, uart_readFlags_t aFlags)
This function reads from a uart device.
Definition: isf_uart_adapter.c:319
uart_userDefinedVars_struct::uartMode
uint8_t uartMode
Definition: isf_uart_adapter.h:31
g_uartUserDefinedVars
const uart_UserDefinedVars_t * g_uartUserDefinedVars[UART_INSTANCE_COUNT]
Definition: isf_uart_adapter.c:26
- © Freescale Semiconductor, Inc. 2016. All Rights Reserved.