Zephyr API Documentation 4.4.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
uart_internal.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2019 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Wind River Systems, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_UART_UART_INTERNAL_H_
14#define ZEPHYR_INCLUDE_DRIVERS_UART_UART_INTERNAL_H_
15
16#include <errno.h>
17#include <stddef.h>
18
19#include <zephyr/device.h>
20
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
36typedef void (*uart_irq_config_func_t)(const struct device *dev);
37
39__subsystem struct uart_driver_api {
40
41#ifdef CONFIG_UART_ASYNC_API
42
43 int (*callback_set)(const struct device *dev, uart_callback_t callback, void *user_data);
44
45 int (*tx)(const struct device *dev, const uint8_t *buf, size_t len, int32_t timeout);
46 int (*tx_abort)(const struct device *dev);
47
48 int (*rx_enable)(const struct device *dev, uint8_t *buf, size_t len, int32_t timeout);
49 int (*rx_buf_rsp)(const struct device *dev, uint8_t *buf, size_t len);
50 int (*rx_disable)(const struct device *dev);
51
52#ifdef CONFIG_UART_WIDE_DATA
53 int (*tx_u16)(const struct device *dev, const uint16_t *buf, size_t len, int32_t timeout);
54 int (*rx_enable_u16)(const struct device *dev, uint16_t *buf, size_t len, int32_t timeout);
55 int (*rx_buf_rsp_u16)(const struct device *dev, uint16_t *buf, size_t len);
56#endif
57
58#endif
59
61 int (*poll_in)(const struct device *dev, unsigned char *p_char);
62 void (*poll_out)(const struct device *dev, unsigned char out_char);
63
64#ifdef CONFIG_UART_WIDE_DATA
65 int (*poll_in_u16)(const struct device *dev, uint16_t *p_u16);
66 void (*poll_out_u16)(const struct device *dev, uint16_t out_u16);
67#endif
68
70 int (*err_check)(const struct device *dev);
71
72#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
74 int (*configure)(const struct device *dev, const struct uart_config *cfg);
75 int (*config_get)(const struct device *dev, struct uart_config *cfg);
76#endif
77
78#ifdef CONFIG_UART_INTERRUPT_DRIVEN
79
81 int (*fifo_fill)(const struct device *dev, const uint8_t *tx_data, int len);
82
83#ifdef CONFIG_UART_WIDE_DATA
84 int (*fifo_fill_u16)(const struct device *dev, const uint16_t *tx_data, int len);
85#endif
86
88 int (*fifo_read)(const struct device *dev, uint8_t *rx_data, const int size);
89
90#ifdef CONFIG_UART_WIDE_DATA
91 int (*fifo_read_u16)(const struct device *dev, uint16_t *rx_data, const int size);
92#endif
93
95 void (*irq_tx_enable)(const struct device *dev);
96
98 void (*irq_tx_disable)(const struct device *dev);
99
101 int (*irq_tx_ready)(const struct device *dev);
102
104 void (*irq_rx_enable)(const struct device *dev);
105
107 void (*irq_rx_disable)(const struct device *dev);
108
110 int (*irq_tx_complete)(const struct device *dev);
111
113 int (*irq_rx_ready)(const struct device *dev);
114
116 void (*irq_err_enable)(const struct device *dev);
117
119 void (*irq_err_disable)(const struct device *dev);
120
122 int (*irq_is_pending)(const struct device *dev);
123
125 void (*irq_update)(const struct device *dev);
126
128 void (*irq_callback_set)(const struct device *dev, uart_irq_callback_user_data_t cb,
129 void *user_data);
130
131#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
132
133#ifdef CONFIG_UART_LINE_CTRL
134 int (*line_ctrl_set)(const struct device *dev, uint32_t ctrl, uint32_t val);
135 int (*line_ctrl_get)(const struct device *dev, uint32_t ctrl, uint32_t *val);
136#endif
137
138#ifdef CONFIG_UART_DRV_CMD
139 int (*drv_cmd)(const struct device *dev, uint32_t cmd, uint32_t p);
140#endif
141};
142
143static inline int z_impl_uart_err_check(const struct device *dev)
144{
145 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
146
147 if (api->err_check == NULL) {
148 return -ENOSYS;
149 }
150
151 return api->err_check(dev);
152}
153
154static inline int z_impl_uart_poll_in(const struct device *dev, unsigned char *p_char)
155{
156 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
157
158 if (api->poll_in == NULL) {
159 return -ENOSYS;
160 }
161
162 return api->poll_in(dev, p_char);
163}
164
165static inline int z_impl_uart_poll_in_u16(const struct device *dev, uint16_t *p_u16)
166{
167#ifdef CONFIG_UART_WIDE_DATA
168 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
169
170 if (api->poll_in_u16 == NULL) {
171 return -ENOSYS;
172 }
173
174 return api->poll_in_u16(dev, p_u16);
175#else
176 ARG_UNUSED(dev);
177 ARG_UNUSED(p_u16);
178 return -ENOTSUP;
179#endif
180}
181
182static inline void z_impl_uart_poll_out(const struct device *dev, unsigned char out_char)
183{
184 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
185
186 api->poll_out(dev, out_char);
187}
188
189static inline void z_impl_uart_poll_out_u16(const struct device *dev, uint16_t out_u16)
190{
191#ifdef CONFIG_UART_WIDE_DATA
192 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
193
194 api->poll_out_u16(dev, out_u16);
195#else
196 ARG_UNUSED(dev);
197 ARG_UNUSED(out_u16);
198#endif
199}
200
201static inline int z_impl_uart_configure(const struct device *dev, const struct uart_config *cfg)
202{
203#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
204 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
205
206 if (api->configure == NULL) {
207 return -ENOSYS;
208 }
209 return api->configure(dev, cfg);
210#else
211 ARG_UNUSED(dev);
212 ARG_UNUSED(cfg);
213 return -ENOTSUP;
214#endif
215}
216
217static inline int z_impl_uart_config_get(const struct device *dev, struct uart_config *cfg)
218{
219#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
220 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
221
222 if (api->config_get == NULL) {
223 return -ENOSYS;
224 }
225
226 return api->config_get(dev, cfg);
227#else
228 ARG_UNUSED(dev);
229 ARG_UNUSED(cfg);
230 return -ENOTSUP;
231#endif
232}
233
234static inline int uart_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
235{
236#ifdef CONFIG_UART_INTERRUPT_DRIVEN
237 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
238
239 if (api->fifo_fill == NULL) {
240 return -ENOSYS;
241 }
242
243 return api->fifo_fill(dev, tx_data, size);
244#else
245 ARG_UNUSED(dev);
246 ARG_UNUSED(tx_data);
247 ARG_UNUSED(size);
248 return -ENOTSUP;
249#endif
250}
251
252static inline int uart_fifo_fill_u16(const struct device *dev, const uint16_t *tx_data, int size)
253{
254#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
255 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
256
257 if (api->fifo_fill_u16 == NULL) {
258 return -ENOSYS;
259 }
260
261 return api->fifo_fill_u16(dev, tx_data, size);
262#else
263 ARG_UNUSED(dev);
264 ARG_UNUSED(tx_data);
265 ARG_UNUSED(size);
266 return -ENOTSUP;
267#endif
268}
269
270static inline int uart_fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
271{
272#ifdef CONFIG_UART_INTERRUPT_DRIVEN
273 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
274
275 if (api->fifo_read == NULL) {
276 return -ENOSYS;
277 }
278
279 return api->fifo_read(dev, rx_data, size);
280#else
281 ARG_UNUSED(dev);
282 ARG_UNUSED(rx_data);
283 ARG_UNUSED(size);
284 return -ENOTSUP;
285#endif
286}
287
288static inline int uart_fifo_read_u16(const struct device *dev, uint16_t *rx_data, const int size)
289{
290#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
291 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
292
293 if (api->fifo_read_u16 == NULL) {
294 return -ENOSYS;
295 }
296
297 return api->fifo_read_u16(dev, rx_data, size);
298#else
299 ARG_UNUSED(dev);
300 ARG_UNUSED(rx_data);
301 ARG_UNUSED(size);
302 return -ENOTSUP;
303#endif
304}
305
306static inline void z_impl_uart_irq_tx_enable(const struct device *dev)
307{
308#ifdef CONFIG_UART_INTERRUPT_DRIVEN
309 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
310
311 if (api->irq_tx_enable != NULL) {
312 api->irq_tx_enable(dev);
313 }
314#else
315 ARG_UNUSED(dev);
316#endif
317}
318
319static inline void z_impl_uart_irq_tx_disable(const struct device *dev)
320{
321#ifdef CONFIG_UART_INTERRUPT_DRIVEN
322 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
323
324 if (api->irq_tx_disable != NULL) {
325 api->irq_tx_disable(dev);
326 }
327#else
328 ARG_UNUSED(dev);
329#endif
330}
331
332static inline int uart_irq_tx_ready(const struct device *dev)
333{
334#ifdef CONFIG_UART_INTERRUPT_DRIVEN
335 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
336
337 if (api->irq_tx_ready == NULL) {
338 return -ENOSYS;
339 }
340
341 return api->irq_tx_ready(dev);
342#else
343 ARG_UNUSED(dev);
344 return -ENOTSUP;
345#endif
346}
347
348static inline void z_impl_uart_irq_rx_enable(const struct device *dev)
349{
350#ifdef CONFIG_UART_INTERRUPT_DRIVEN
351 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
352
353 if (api->irq_rx_enable != NULL) {
354 api->irq_rx_enable(dev);
355 }
356#else
357 ARG_UNUSED(dev);
358#endif
359}
360
361static inline void z_impl_uart_irq_rx_disable(const struct device *dev)
362{
363#ifdef CONFIG_UART_INTERRUPT_DRIVEN
364 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
365
366 if (api->irq_rx_disable != NULL) {
367 api->irq_rx_disable(dev);
368 }
369#else
370 ARG_UNUSED(dev);
371#endif
372}
373
374static inline int uart_irq_tx_complete(const struct device *dev)
375{
376#ifdef CONFIG_UART_INTERRUPT_DRIVEN
377 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
378
379 if (api->irq_tx_complete == NULL) {
380 return -ENOSYS;
381 }
382 return api->irq_tx_complete(dev);
383#else
384 ARG_UNUSED(dev);
385 return -ENOTSUP;
386#endif
387}
388
389static inline int uart_irq_rx_ready(const struct device *dev)
390{
391#ifdef CONFIG_UART_INTERRUPT_DRIVEN
392 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
393
394 if (api->irq_rx_ready == NULL) {
395 return -ENOSYS;
396 }
397 return api->irq_rx_ready(dev);
398#else
399 ARG_UNUSED(dev);
400 return -ENOTSUP;
401#endif
402}
403
404static inline void z_impl_uart_irq_err_enable(const struct device *dev)
405{
406#ifdef CONFIG_UART_INTERRUPT_DRIVEN
407 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
408
409 if (api->irq_err_enable) {
410 api->irq_err_enable(dev);
411 }
412#else
413 ARG_UNUSED(dev);
414#endif
415}
416
417static inline void z_impl_uart_irq_err_disable(const struct device *dev)
418{
419#ifdef CONFIG_UART_INTERRUPT_DRIVEN
420 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
421
422 if (api->irq_err_disable) {
423 api->irq_err_disable(dev);
424 }
425#else
426 ARG_UNUSED(dev);
427#endif
428}
429
430static inline int uart_irq_is_pending(const struct device *dev)
431{
432#ifdef CONFIG_UART_INTERRUPT_DRIVEN
433 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
434
435 if (api->irq_is_pending == NULL) {
436 return -ENOSYS;
437 }
438 return api->irq_is_pending(dev);
439#else
440 ARG_UNUSED(dev);
441 return -ENOTSUP;
442#endif
443}
444
445static inline void uart_irq_update(const struct device *dev)
446{
447#ifdef CONFIG_UART_INTERRUPT_DRIVEN
448 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
449
450 if (api->irq_update != NULL) {
451 api->irq_update(dev);
452 }
453#endif
454}
455
456static inline int uart_irq_callback_user_data_set(const struct device *dev,
457 uart_irq_callback_user_data_t cb, void *user_data)
458{
459#ifdef CONFIG_UART_INTERRUPT_DRIVEN
460 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
461
462 if ((api != NULL) && (api->irq_callback_set != NULL)) {
463 api->irq_callback_set(dev, cb, user_data);
464 return 0;
465 } else {
466 return -ENOSYS;
467 }
468#else
469 ARG_UNUSED(dev);
470 ARG_UNUSED(cb);
471 ARG_UNUSED(user_data);
472 return -ENOTSUP;
473#endif
474}
475
476static inline int uart_irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb)
477{
478 return uart_irq_callback_user_data_set(dev, cb, NULL);
479}
480
481static inline int uart_callback_set(const struct device *dev, uart_callback_t callback,
482 void *user_data)
483{
484#ifdef CONFIG_UART_ASYNC_API
485 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
486
487 if (api->callback_set == NULL) {
488 return -ENOSYS;
489 }
490
491 return api->callback_set(dev, callback, user_data);
492#else
493 ARG_UNUSED(dev);
494 ARG_UNUSED(callback);
495 ARG_UNUSED(user_data);
496 return -ENOTSUP;
497#endif
498}
499
500static inline int z_impl_uart_tx(const struct device *dev, const uint8_t *buf, size_t len,
501 int32_t timeout)
502
503{
504#ifdef CONFIG_UART_ASYNC_API
505 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
506
507 return api->tx(dev, buf, len, timeout);
508#else
509 ARG_UNUSED(dev);
510 ARG_UNUSED(buf);
511 ARG_UNUSED(len);
512 ARG_UNUSED(timeout);
513 return -ENOTSUP;
514#endif
515}
516
517static inline int z_impl_uart_tx_u16(const struct device *dev, const uint16_t *buf, size_t len,
518 int32_t timeout)
519
520{
521#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
522 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
523
524 return api->tx_u16(dev, buf, len, timeout);
525#else
526 ARG_UNUSED(dev);
527 ARG_UNUSED(buf);
528 ARG_UNUSED(len);
529 ARG_UNUSED(timeout);
530 return -ENOTSUP;
531#endif
532}
533
534static inline int z_impl_uart_tx_abort(const struct device *dev)
535{
536#ifdef CONFIG_UART_ASYNC_API
537 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
538
539 return api->tx_abort(dev);
540#else
541 ARG_UNUSED(dev);
542 return -ENOTSUP;
543#endif
544}
545
546static inline int z_impl_uart_rx_enable(const struct device *dev, uint8_t *buf, size_t len,
547 int32_t timeout)
548{
549#ifdef CONFIG_UART_ASYNC_API
550 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
551
552 return api->rx_enable(dev, buf, len, timeout);
553#else
554 ARG_UNUSED(dev);
555 ARG_UNUSED(buf);
556 ARG_UNUSED(len);
557 ARG_UNUSED(timeout);
558 return -ENOTSUP;
559#endif
560}
561
562static inline int z_impl_uart_rx_enable_u16(const struct device *dev, uint16_t *buf, size_t len,
563 int32_t timeout)
564{
565#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
566 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
567
568 return api->rx_enable_u16(dev, buf, len, timeout);
569#else
570 ARG_UNUSED(dev);
571 ARG_UNUSED(buf);
572 ARG_UNUSED(len);
573 ARG_UNUSED(timeout);
574 return -ENOTSUP;
575#endif
576}
577
578static inline int uart_rx_buf_rsp(const struct device *dev, uint8_t *buf, size_t len)
579{
580#ifdef CONFIG_UART_ASYNC_API
581 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
582
583 return api->rx_buf_rsp(dev, buf, len);
584#else
585 ARG_UNUSED(dev);
586 ARG_UNUSED(buf);
587 ARG_UNUSED(len);
588 return -ENOTSUP;
589#endif
590}
591
592static inline int uart_rx_buf_rsp_u16(const struct device *dev, uint16_t *buf, size_t len)
593{
594#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
595 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
596
597 return api->rx_buf_rsp_u16(dev, buf, len);
598#else
599 ARG_UNUSED(dev);
600 ARG_UNUSED(buf);
601 ARG_UNUSED(len);
602 return -ENOTSUP;
603#endif
604}
605
606static inline int z_impl_uart_rx_disable(const struct device *dev)
607{
608#ifdef CONFIG_UART_ASYNC_API
609 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
610
611 return api->rx_disable(dev);
612#else
613 ARG_UNUSED(dev);
614 return -ENOTSUP;
615#endif
616}
617
618static inline int z_impl_uart_line_ctrl_set(const struct device *dev, uint32_t ctrl, uint32_t val)
619{
620#ifdef CONFIG_UART_LINE_CTRL
621 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
622
623 if (api->line_ctrl_set == NULL) {
624 return -ENOSYS;
625 }
626 return api->line_ctrl_set(dev, ctrl, val);
627#else
628 ARG_UNUSED(dev);
629 ARG_UNUSED(ctrl);
630 ARG_UNUSED(val);
631 return -ENOTSUP;
632#endif
633}
634
635static inline int z_impl_uart_line_ctrl_get(const struct device *dev, uint32_t ctrl, uint32_t *val)
636{
637#ifdef CONFIG_UART_LINE_CTRL
638 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
639
640 if (api->line_ctrl_get == NULL) {
641 return -ENOSYS;
642 }
643 return api->line_ctrl_get(dev, ctrl, val);
644#else
645 ARG_UNUSED(dev);
646 ARG_UNUSED(ctrl);
647 ARG_UNUSED(val);
648 return -ENOTSUP;
649#endif
650}
651
652static inline int z_impl_uart_drv_cmd(const struct device *dev, uint32_t cmd, uint32_t p)
653{
654#ifdef CONFIG_UART_DRV_CMD
655 const struct uart_driver_api *api = (const struct uart_driver_api *)dev->api;
656
657 if (api->drv_cmd == NULL) {
658 return -ENOSYS;
659 }
660 return api->drv_cmd(dev, cmd, p);
661#else
662 ARG_UNUSED(dev);
663 ARG_UNUSED(cmd);
664 ARG_UNUSED(p);
665 return -ENOTSUP;
666#endif
667}
668
669#ifdef __cplusplus
670}
671#endif
672
674
675#endif /* ZEPHYR_INCLUDE_DRIVERS_UART_UART_INTERNAL_H_ */
System error numbers.
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define ENOTSUP
Unsupported value.
Definition errno.h:114
void(* uart_callback_t)(const struct device *dev, struct uart_event *evt, void *user_data)
Define the application callback function signature for uart_callback_set() function.
Definition uart.h:317
static int uart_rx_buf_rsp(const struct device *dev, uint8_t *buf, size_t len)
Provide receive buffer in response to UART_RX_BUF_REQUEST event.
static int uart_rx_buf_rsp_u16(const struct device *dev, uint16_t *buf, size_t len)
Provide wide data receive buffer in response to UART_RX_BUF_REQUEST event.
static int uart_callback_set(const struct device *dev, uart_callback_t callback, void *user_data)
Set event handler function.
static void uart_irq_update(const struct device *dev)
Start processing interrupts in ISR.
static int uart_fifo_read_u16(const struct device *dev, uint16_t *rx_data, const int size)
Read wide data from FIFO.
static int uart_irq_tx_ready(const struct device *dev)
Check if UART TX buffer can accept bytes.
static int uart_irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb)
Set the IRQ callback function pointer (legacy).
static int uart_irq_tx_complete(const struct device *dev)
Check if UART TX block finished transmission.
static int uart_fifo_fill_u16(const struct device *dev, const uint16_t *tx_data, int size)
Fill FIFO with wide data.
static int uart_fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
Read data from FIFO.
static int uart_irq_is_pending(const struct device *dev)
Check if any IRQs is pending.
static int uart_irq_rx_ready(const struct device *dev)
Check if UART RX buffer has a received char.
void(* uart_irq_callback_user_data_t)(const struct device *dev, void *user_data)
Define the application callback function signature for uart_irq_callback_user_data_set() function.
Definition uart.h:142
static int uart_irq_callback_user_data_set(const struct device *dev, uart_irq_callback_user_data_t cb, void *user_data)
Set the IRQ callback function pointer.
static int uart_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
Fill FIFO with data.
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
UART controller configuration structure.
Definition uart.h:122