SmartSnippets DA1459x SDK
ad_uart.h
Go to the documentation of this file.
1 
44 #ifndef AD_UART_H_
45 #define AD_UART_H_
46 
47 #if dg_configUART_ADAPTER
48 
49 #include "ad.h"
50 #include "hw_uart.h"
51 #include "hw_dma.h"
52 #include "osal.h"
53 #include "resmgmt.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
65 #ifndef CONFIG_UART_USE_ASYNC_TRANSACTIONS
66 #define CONFIG_UART_USE_ASYNC_TRANSACTIONS (1)
67 #endif
68 
77 #ifndef CONFIG_UART_USE_SYNC_TRANSACTIONS
78 #define CONFIG_UART_USE_SYNC_TRANSACTIONS (1)
79 #endif
80 
81 #if (CONFIG_UART_USE_SYNC_TRANSACTIONS == 0) && (CONFIG_UART_USE_ASYNC_TRANSACTIONS == 0)
82 #error "At least one macro CONFIG_UART_USE_SYNC_TRANSACTIONS or CONFIG_UART_USE_ASYNC_TRANSACTIONS must be set"
83 #endif
84 
89 typedef void (*ad_uart_user_cb)(void *user_data, uint16_t transferred);
90 
94 typedef enum
95 {
99 
103 
107 
111 
112 
117 typedef enum {
118  AD_UART_ERROR_CONFIG_TX_SIZE = -9,
128 } AD_UART_ERROR;
129 
130 
136 typedef struct {
137  ad_io_conf_t rx;
142 
148 typedef struct {
149  uart_config hw_conf;
151 
158 typedef struct {
159  const HW_UART_ID id;
163 
164 
165 typedef void *ad_uart_handle_t;
166 
167 
173 void ad_uart_init(void);
174 
175 
191 ad_uart_handle_t ad_uart_open(const ad_uart_controller_conf_t *ad_uart_ctrl_conf);
192 
193 
222 int ad_uart_close(ad_uart_handle_t handle, bool force);
223 
224 
237 int ad_uart_reconfig(ad_uart_handle_t handle, const ad_uart_driver_conf_t *ad_drv);
238 
239 #if (CONFIG_UART_USE_SYNC_TRANSACTIONS == 1)
240 
255 int ad_uart_write(ad_uart_handle_t handle, const char *wbuf, size_t wlen);
256 
257 
277 int ad_uart_read(ad_uart_handle_t handle, char *rbuf, size_t rlen, OS_TICK_TIME timeout);
278 #endif /* CONFIG_UART_USE_SYNC_TRANSACTIONS */
279 
280 #if (CONFIG_UART_USE_ASYNC_TRANSACTIONS == 1)
281 
307 int ad_uart_write_async(ad_uart_handle_t handle, const char *wbuf, size_t wlen,
308  ad_uart_user_cb cb, void *user_data);
309 
335 int ad_uart_read_async(ad_uart_handle_t handle, char *rbuf, size_t rlen, ad_uart_user_cb cb,
336  void *user_data);
337 
355 int ad_uart_complete_async_read(ad_uart_handle_t handle);
356 
371 int ad_uart_complete_async_write(ad_uart_handle_t handle);
372 #endif /* CONFIG_UART_USE_ASYNC_TRANSACTIONS */
373 
384 HW_UART_ID ad_uart_get_hw_uart_id(ad_uart_handle_t handle);
385 
399 int ad_uart_io_config (HW_UART_ID id, const ad_uart_io_conf_t *io, AD_IO_CONF_STATE state);
400 
401 #ifdef __cplusplus
402 }
403 #endif
404 
405 #endif /* dg_configUART_ADAPTER */
406 
407 #endif /* AD_UART_H_ */
408 
ad_uart_io_conf_t::ctsn
ad_io_conf_t ctsn
Definition: ad_uart.h:140
ad_uart_controller_conf_t
UART controller configuration.
Definition: ad_uart.h:158
AD_UART_ERROR_AUTOFLOW_CONF_INVALID
Definition: ad_uart.h:125
ad_uart_complete_async_write
int ad_uart_complete_async_write(ad_uart_handle_t handle)
Finish asynchronous write.
hw_dma.h
Definition of API for the DMA Low Level Driver.
ad_uart_user_cb
void(* ad_uart_user_cb)(void *user_data, uint16_t transferred)
Asynchronous callback function.
Definition: ad_uart.h:89
AD_UART_ERROR_CONTROLLER_BUSY
Definition: ad_uart.h:122
ad_uart_read
int ad_uart_read(ad_uart_handle_t handle, char *rbuf, size_t rlen, OS_TICK_TIME timeout)
Perform a blocking read transaction.
ad_uart_complete_async_read
int ad_uart_complete_async_read(ad_uart_handle_t handle)
Finish asynchronous read.
uart_config
UART configuration structure definition.
Definition: hw_uart.h:258
ad_uart_io_conf_t::rtsn
ad_io_conf_t rtsn
Definition: ad_uart.h:139
AD_UART_ERROR_IO_CFG_INVALID
Definition: ad_uart.h:120
ad_uart_write
int ad_uart_write(ad_uart_handle_t handle, const char *wbuf, size_t wlen)
Perform a blocking write transaction.
ad_uart_io_conf_t
UART I/O configuration.
Definition: ad_uart.h:136
ad_uart_init
void ad_uart_init(void)
Initialize UART adapter.
AD_UART_ERROR_NONE
Definition: ad_uart.h:127
resmgmt.h
Resource management API.
osal.h
OS abstraction layer API.
AD_UART_ERROR_RESOURCE_NOT_AVAILABLE
Definition: ad_uart.h:121
AD_UART_ERROR_DEVICE_CLOSED
Definition: ad_uart.h:123
ad_uart_read_async
int ad_uart_read_async(ad_uart_handle_t handle, char *rbuf, size_t rlen, ad_uart_user_cb cb, void *user_data)
Perform a non blocking read transaction.
ad_uart_controller_conf_t::drv
const ad_uart_driver_conf_t * drv
Definition: ad_uart.h:161
AD_UART_RES_TYPE_CONFIG
Definition: ad_uart.h:98
ad.h
Adapters shared definitions.
AD_IO_CONF_STATE
AD_IO_CONF_STATE
Adapters IO configuration state.
Definition: ad.h:65
AD_UART_RES_TYPES
Definition: ad_uart.h:109
AD_UART_RES_TYPE
AD_UART_RES_TYPE
UART resource types.
Definition: ad_uart.h:94
ad_uart_write_async
int ad_uart_write_async(ad_uart_handle_t handle, const char *wbuf, size_t wlen, ad_uart_user_cb cb, void *user_data)
Perform a non blocking write transaction.
ad_uart_get_hw_uart_id
HW_UART_ID ad_uart_get_hw_uart_id(ad_uart_handle_t handle)
Get UART controller id.
AD_UART_ERROR
AD_UART_ERROR
UART adapter error codes.
Definition: ad_uart.h:117
ad_uart_io_config
int ad_uart_io_config(HW_UART_ID id, const ad_uart_io_conf_t *io, AD_IO_CONF_STATE state)
Initialize controller pins to on / off io configuration.
AD_UART_RES_TYPE_WRITE
Definition: ad_uart.h:102
AD_UART_ERROR_CONFIG_RX_SIZE
Definition: ad_uart.h:119
AD_UART_RES_TYPE_READ
Definition: ad_uart.h:106
AD_UART_ERROR_CONTROLLER_CONF_INVALID
Definition: ad_uart.h:124
ad_uart_reconfig
int ad_uart_reconfig(ad_uart_handle_t handle, const ad_uart_driver_conf_t *ad_drv)
Reconfigure UART controller.
ad_uart_close
int ad_uart_close(ad_uart_handle_t handle, bool force)
Close UART controller.
hw_uart.h
Definition of API for the UART Low Level Driver.
ad_uart_io_conf_t::tx
ad_io_conf_t tx
Definition: ad_uart.h:138
AD_UART_ERROR_HANDLE_INVALID
Definition: ad_uart.h:126
ad_io_conf_t
Adapters IO configuration.
Definition: ad.h:104
ad_uart_controller_conf_t::io
const ad_uart_io_conf_t * io
Definition: ad_uart.h:160
ad_uart_open
ad_uart_handle_t ad_uart_open(const ad_uart_controller_conf_t *ad_uart_ctrl_conf)
Open UART controller.
ad_uart_driver_conf_t
UART driver configuration.
Definition: ad_uart.h:148