XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
controller.h
浏览该文件的文档.
1
21#ifndef __xwcd_ds_uart_controller_h__
22#define __xwcd_ds_uart_controller_h__
23
24#include <xwcd/ds/standard.h>
25#include <xwos/lib/xwbop.h>
27#include <xwos/osal/sync/sem.h>
28#include <xwos/osal/lock/mtx.h>
29#include <xwcd/ds/device.h>
30#include <xwcd/ds/soc/dma.h>
31
101#define XWDS_UART_RXQ_SIZE XWCDCFG_ds_UART_RXQ_SIZE
102
112};
113
122};
123
131};
132
140};
141
149};
150
156 struct {
163 void * soccfg;
164};
165
166struct xwds_uartc;
167
171typedef void (* xwds_uartc_eqcb_f)(struct xwds_uartc *, xwer_t);
172
178 xwer_t (* cfg)(struct xwds_uartc * /*uartc*/,
179 const struct xwds_uart_cfg * /*cfg*/);
180 xwer_t (* tx)(struct xwds_uartc * /*uartc*/,
181 const xwu8_t * /*data*/, xwsz_t * /*size*/,
182 xwtm_t /*to*/);
183 xwer_t (* eq)(struct xwds_uartc * /*uartc*/,
184 const xwu8_t * /*data*/, xwsz_t * /*size*/,
185 xwds_uartc_eqcb_f /*cb*/);
186 xwer_t (* putc)(struct xwds_uartc * /*uartc*/,
187 const xwu8_t /*byte*/);
188};
189
196 /* attributes */
197 const struct xwds_uart_cfg * cfg;
201 /* TX */
204 /* RX */
205 struct {
206 struct xwos_sem sem;
207 struct xwos_splk lock;
212 } rxq;
213};
214
215/******** ******** APIs ******** ********/
216void xwds_uartc_construct(struct xwds_uartc * uartc);
217void xwds_uartc_destruct(struct xwds_uartc * uartc);
218xwer_t xwds_uartc_grab(struct xwds_uartc * uartc);
219xwer_t xwds_uartc_put(struct xwds_uartc * uartc);
220
241xwer_t xwds_uartc_rx(struct xwds_uartc * uartc,
242 xwu8_t * buf, xwsz_t * size,
243 xwtm_t to);
244
259xwer_t xwds_uartc_try_rx(struct xwds_uartc * uartc,
260 xwu8_t * buf, xwsz_t * size);
261
284xwer_t xwds_uartc_tx(struct xwds_uartc * uartc,
285 const xwu8_t * data, xwsz_t * size,
286 xwtm_t to);
287
309xwer_t xwds_uartc_eq(struct xwds_uartc * uartc,
310 const xwu8_t * data, xwsz_t * size,
312
330xwer_t xwds_uartc_putc(struct xwds_uartc * uartc,
331 const xwu8_t byte,
332 xwtm_t to);
333
345xwer_t xwds_uartc_cfg(struct xwds_uartc * uartc,
346 const struct xwds_uart_cfg * cfg);
347
352static __xwcc_inline
354{
355 return ((50U == baudrate) || (75U == baudrate) || (110U == baudrate) ||
356 (134U == baudrate) || (150U == baudrate) || (200U == baudrate) ||
357 (300U == baudrate) || (600U == baudrate) || (1200U == baudrate) ||
358 (1800U == baudrate) || (2400U == baudrate) || (4800U == baudrate) ||
359 (9600U == baudrate) || (19200U == baudrate) || (38400U == baudrate) ||
360 (57600U == baudrate) || (115200U == baudrate) ||
361 (230400U == baudrate) || (460800U == baudrate) ||
362 (576000U == baudrate) || (921600U == baudrate) ||
363 (1000000U == baudrate) || (1152000U == baudrate) ||
364 (1500000U == baudrate) || (2000000U == baudrate) ||
365 (2500000U == baudrate) || (3000000U == baudrate) ||
366 (3500000U == baudrate) || (4000000U == baudrate));
367}
368
369/******** ******** Callbacks for driver ******** ********/
374void xwds_uartc_drvcb_rxq_flush(struct xwds_uartc * uartc);
375
385 xwu8_t bytes[], xwsz_t size);
386
392void xwds_uartc_drvcb_rxq_pub(struct xwds_uartc * uartc, xwsq_t tail);
393
398#endif /* xwcd/ds/uart/controller.h */
玄武设备栈:SOC:DMA
玄武设备栈:设备基类
xwer_t xwds_uartc_grab(struct xwds_uartc *uartc)
增加对象的引用计数
Definition controller.c:94
static bool xwds_uart_tst_baudrate(xwu32_t baudrate)
测试UART波特率是否合法
Definition controller.h:353
xwer_t xwds_uartc_tx(struct xwds_uartc *uartc, const xwu8_t *data, xwsz_t *size, xwtm_t to)
XWDS API:同步发送
Definition controller.c:348
void xwds_uartc_drvcb_rxq_pub(struct xwds_uartc *uartc, xwsq_t tail)
XWDS Driver Callback:发布数据到接收队列
Definition controller.c:522
xwds_uart_bits_em
UART字长枚举
Definition controller.h:106
xwds_uart_parity_em
UART奇偶校验枚举
Definition controller.h:127
xwer_t xwds_uartc_cfg(struct xwds_uartc *uartc, const struct xwds_uart_cfg *cfg)
XWDS API:配置UART
Definition controller.c:462
#define XWDS_UART_RXQ_SIZE
Definition controller.h:101
void xwds_uartc_destruct(struct xwds_uartc *uartc)
XWDS API:UART控制器对象的析构函数
Definition controller.c:84
xwer_t xwds_uartc_rx(struct xwds_uartc *uartc, xwu8_t *buf, xwsz_t *size, xwtm_t to)
XWDS API:从接收队列中获取数据
Definition controller.c:229
void xwds_uartc_construct(struct xwds_uartc *uartc)
XWDS API:UART控制器的构造函数
Definition controller.c:73
xwer_t xwds_uartc_eq(struct xwds_uartc *uartc, const xwu8_t *data, xwsz_t *size, xwds_uartc_eqcb_f cb)
XWDS API:异步发送
Definition controller.c:389
xwds_uart_hardwareflowcontrol_em
UART硬件流控枚举
Definition controller.h:136
xwer_t xwds_uartc_put(struct xwds_uartc *uartc)
减少对象的引用计数
Definition controller.c:104
xwds_uart_stopbits_em
UART停止位枚举
Definition controller.h:117
xwer_t xwds_uartc_putc(struct xwds_uartc *uartc, const xwu8_t byte, xwtm_t to)
XWDS API:直接发送一个字节(非DMA模式)
Definition controller.c:423
void(* xwds_uartc_eqcb_f)(struct xwds_uartc *, xwer_t)
异步发送的回调函数类型
Definition controller.h:171
xwds_uart_mode_em
UART模式枚举
Definition controller.h:145
xwsq_t xwds_uartc_drvcb_rxq_fill(struct xwds_uartc *uartc, xwu8_t bytes[], xwsz_t size)
XWDS Driver Callback:从UART硬件接收数据到缓冲区
Definition controller.c:508
void xwds_uartc_drvcb_rxq_flush(struct xwds_uartc *uartc)
XWDS Driver Callback:清空接收队列
Definition controller.c:495
xwer_t xwds_uartc_try_rx(struct xwds_uartc *uartc, xwu8_t *buf, xwsz_t *size)
XWDS API:尝试从接收队列中获取数据
Definition controller.c:289
@ XWDS_UART_BITS_8
Definition controller.h:110
@ XWDS_UART_BITS_5
Definition controller.h:107
@ XWDS_UART_BITS_6
Definition controller.h:108
@ XWDS_UART_BITS_9
Definition controller.h:111
@ XWDS_UART_BITS_7
Definition controller.h:109
@ XWDS_UART_PARITY_EVEN
Definition controller.h:129
@ XWDS_UART_PARITY_NONE
Definition controller.h:128
@ XWDS_UART_PARITY_ODD
Definition controller.h:130
@ XWDS_UART_HFC_CTS
Definition controller.h:139
@ XWDS_UART_HFC_RTS
Definition controller.h:138
@ XWDS_UART_HFC_NONE
Definition controller.h:137
@ XWDS_UART_STOPBITS_1_0
Definition controller.h:119
@ XWDS_UART_STOPBITS_0_5
Definition controller.h:118
@ XWDS_UART_STOPBITS_1_5
Definition controller.h:120
@ XWDS_UART_STOPBITS_2_0
Definition controller.h:121
@ XWDS_UART_MODE_TX
Definition controller.h:147
@ XWDS_UART_MODE_RX
Definition controller.h:148
@ XWDS_UART_MODE_CLOSE
Definition controller.h:146
#define __xwcc_alignl1cache
Definition compiler.h:123
#define __xwcc_inline
Definition compiler.h:77
xws64_t xwtm_t
XWOS系统时间 (有符号)
Definition type.h:742
signed long xwer_t
Definition type.h:554
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
unsigned long xwsq_t
Definition type.h:445
uint32_t xwu32_t
Definition type.h:266
#define XWBOP_BIT(n)
Definition xwbop.h:27
操作系统抽象层:互斥锁
操作系统抽象层:自旋锁
设备(所有设备的基类)
Definition device.h:127
基本驱动函数表(所有设备驱动的基类)
Definition device.h:113
设备栈DMA资源
Definition standard.h:108
UART配置
Definition controller.h:154
xwu32_t baudrate
Definition controller.h:155
struct xwds_uart_cfg::@26 bus
xwu8_t stopbits
Definition controller.h:158
BSP中需要提供的UART控制器驱动函数表
Definition controller.h:176
xwer_t(* eq)(struct xwds_uartc *, const xwu8_t *, xwsz_t *, xwds_uartc_eqcb_f)
Definition controller.h:183
struct xwds_driver base
Definition controller.h:177
xwer_t(* cfg)(struct xwds_uartc *, const struct xwds_uart_cfg *)
Definition controller.h:178
xwer_t(* tx)(struct xwds_uartc *, const xwu8_t *, xwsz_t *, xwtm_t)
Definition controller.h:180
xwer_t(* putc)(struct xwds_uartc *, const xwu8_t)
Definition controller.h:186
UART控制器
Definition controller.h:193
struct xwds_device dev
Definition controller.h:194
const struct xwds_resource_dma * txdmarsc
Definition controller.h:199
const struct xwds_resource_dma * rxdmarsc
Definition controller.h:198
struct xwds_uartc::@27 rxq
xwsq_t idx
Definition controller.h:210
struct xwos_mtx txmtx
Definition controller.h:202
xwsq_t pos
Definition controller.h:208
xwsz_t tail
Definition controller.h:209
const struct xwds_uart_cfg * cfg
Definition controller.h:197
XWOS API:互斥锁
Definition mtx.h:82
XWOS API:信号量对象
Definition sem.h:95
XWOS API:自旋锁
Definition spinlock.h:73
操作系统抽象层:信号量
XWOS通用库:位操作
玄武设备栈:顶级头文件