Zephyr Project API  3.4.0
A Scalable Open Source RTOS
uart.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
13#ifndef ZEPHYR_INCLUDE_DRIVERS_UART_H_
14#define ZEPHYR_INCLUDE_DRIVERS_UART_H_
15
23#include <errno.h>
24#include <stddef.h>
25
26#include <zephyr/device.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
39};
40
61 UART_BREAK = (1 << 3),
73 UART_ERROR_NOISE = (1 << 5),
74};
75
83};
84
91};
92
100};
101
114};
115
131};
132
145typedef void (*uart_irq_callback_user_data_t)(const struct device *dev,
146 void *user_data);
147
153typedef void (*uart_irq_config_func_t)(const struct device *dev);
154
261};
262
266 const uint8_t *buf;
268 size_t len;
269};
270
281 size_t offset;
283 size_t len;
284};
285
288 /* @brief Pointer to buffer that is no longer in use. */
290};
291
298};
299
315};
316
326typedef void (*uart_callback_t)(const struct device *dev,
327 struct uart_event *evt, void *user_data);
328
340__subsystem struct uart_driver_api {
341
342#ifdef CONFIG_UART_ASYNC_API
343
344 int (*callback_set)(const struct device *dev,
345 uart_callback_t callback,
346 void *user_data);
347
348 int (*tx)(const struct device *dev, const uint8_t *buf, size_t len,
350 int (*tx_abort)(const struct device *dev);
351
352 int (*rx_enable)(const struct device *dev, uint8_t *buf, size_t len,
354 int (*rx_buf_rsp)(const struct device *dev, uint8_t *buf, size_t len);
355 int (*rx_disable)(const struct device *dev);
356
357#ifdef CONFIG_UART_WIDE_DATA
358 int (*tx_u16)(const struct device *dev, const uint16_t *buf,
359 size_t len, int32_t timeout);
360 int (*rx_enable_u16)(const struct device *dev, uint16_t *buf,
361 size_t len, int32_t timeout);
362 int (*rx_buf_rsp_u16)(const struct device *dev, uint16_t *buf,
363 size_t len);
364#endif
365
366#endif
367
369 int (*poll_in)(const struct device *dev, unsigned char *p_char);
370 void (*poll_out)(const struct device *dev, unsigned char out_char);
371
372#ifdef CONFIG_UART_WIDE_DATA
373 int (*poll_in_u16)(const struct device *dev, uint16_t *p_u16);
374 void (*poll_out_u16)(const struct device *dev, uint16_t out_u16);
375#endif
376
378 int (*err_check)(const struct device *dev);
379
381 int (*configure)(const struct device *dev,
382 const struct uart_config *cfg);
383 int (*config_get)(const struct device *dev, struct uart_config *cfg);
384
385#ifdef CONFIG_UART_INTERRUPT_DRIVEN
386
388 int (*fifo_fill)(const struct device *dev, const uint8_t *tx_data,
389 int len);
390
391#ifdef CONFIG_UART_WIDE_DATA
392 int (*fifo_fill_u16)(const struct device *dev, const uint16_t *tx_data,
393 int len);
394#endif
395
397 int (*fifo_read)(const struct device *dev, uint8_t *rx_data,
398 const int size);
399
400#ifdef CONFIG_UART_WIDE_DATA
401 int (*fifo_read_u16)(const struct device *dev, uint16_t *rx_data,
402 const int size);
403#endif
404
406 void (*irq_tx_enable)(const struct device *dev);
407
409 void (*irq_tx_disable)(const struct device *dev);
410
412 int (*irq_tx_ready)(const struct device *dev);
413
415 void (*irq_rx_enable)(const struct device *dev);
416
418 void (*irq_rx_disable)(const struct device *dev);
419
421 int (*irq_tx_complete)(const struct device *dev);
422
424 int (*irq_rx_ready)(const struct device *dev);
425
427 void (*irq_err_enable)(const struct device *dev);
428
430 void (*irq_err_disable)(const struct device *dev);
431
433 int (*irq_is_pending)(const struct device *dev);
434
436 int (*irq_update)(const struct device *dev);
437
439 void (*irq_callback_set)(const struct device *dev,
441 void *user_data);
442
443#endif
444
445#ifdef CONFIG_UART_LINE_CTRL
446 int (*line_ctrl_set)(const struct device *dev, uint32_t ctrl,
447 uint32_t val);
448 int (*line_ctrl_get)(const struct device *dev, uint32_t ctrl,
449 uint32_t *val);
450#endif
451
452#ifdef CONFIG_UART_DRV_CMD
453 int (*drv_cmd)(const struct device *dev, uint32_t cmd, uint32_t p);
454#endif
455
456};
457
469__syscall int uart_err_check(const struct device *dev);
470
471static inline int z_impl_uart_err_check(const struct device *dev)
472{
473 const struct uart_driver_api *api =
474 (const struct uart_driver_api *)dev->api;
475
476 if (api->err_check == NULL) {
477 return -ENOSYS;
478 }
479
480 return api->err_check(dev);
481}
482
506__syscall int uart_poll_in(const struct device *dev, unsigned char *p_char);
507
508static inline int z_impl_uart_poll_in(const struct device *dev,
509 unsigned char *p_char)
510{
511 const struct uart_driver_api *api =
512 (const struct uart_driver_api *)dev->api;
513
514 if (api->poll_in == NULL) {
515 return -ENOSYS;
516 }
517
518 return api->poll_in(dev, p_char);
519}
520
540__syscall int uart_poll_in_u16(const struct device *dev, uint16_t *p_u16);
541
542static inline int z_impl_uart_poll_in_u16(const struct device *dev,
543 uint16_t *p_u16)
544{
545#ifdef CONFIG_UART_WIDE_DATA
546 const struct uart_driver_api *api =
547 (const struct uart_driver_api *)dev->api;
548
549 if (api->poll_in_u16 == NULL) {
550 return -ENOSYS;
551 }
552
553 return api->poll_in_u16(dev, p_u16);
554#else
555 ARG_UNUSED(dev);
556 ARG_UNUSED(p_u16);
557 return -ENOTSUP;
558#endif
559}
560
575__syscall void uart_poll_out(const struct device *dev,
576 unsigned char out_char);
577
578static inline void z_impl_uart_poll_out(const struct device *dev,
579 unsigned char out_char)
580{
581 const struct uart_driver_api *api =
582 (const struct uart_driver_api *)dev->api;
583
584 api->poll_out(dev, out_char);
585}
586
601__syscall void uart_poll_out_u16(const struct device *dev, uint16_t out_u16);
602
603static inline void z_impl_uart_poll_out_u16(const struct device *dev,
604 uint16_t out_u16)
605{
606#ifdef CONFIG_UART_WIDE_DATA
607 const struct uart_driver_api *api =
608 (const struct uart_driver_api *)dev->api;
609
610 api->poll_out_u16(dev, out_u16);
611#else
612 ARG_UNUSED(dev);
613 ARG_UNUSED(out_u16);
614#endif
615}
616
634__syscall int uart_configure(const struct device *dev,
635 const struct uart_config *cfg);
636
637static inline int z_impl_uart_configure(const struct device *dev,
638 const struct uart_config *cfg)
639{
640 const struct uart_driver_api *api =
641 (const struct uart_driver_api *)dev->api;
642
643 if (api->configure == NULL) {
644 return -ENOSYS;
645 }
646 return api->configure(dev, cfg);
647}
648
662__syscall int uart_config_get(const struct device *dev,
663 struct uart_config *cfg);
664
665static inline int z_impl_uart_config_get(const struct device *dev,
666 struct uart_config *cfg)
667{
668 const struct uart_driver_api *api =
669 (const struct uart_driver_api *)dev->api;
670
671 if (api->config_get == NULL) {
672 return -ENOSYS;
673 }
674
675 return api->config_get(dev, cfg);
676}
677
703static inline int uart_fifo_fill(const struct device *dev,
704 const uint8_t *tx_data,
705 int size)
706{
707#ifdef CONFIG_UART_INTERRUPT_DRIVEN
708 const struct uart_driver_api *api =
709 (const struct uart_driver_api *)dev->api;
710
711 if (api->fifo_fill == NULL) {
712 return -ENOSYS;
713 }
714
715 return api->fifo_fill(dev, tx_data, size);
716#else
717 ARG_UNUSED(dev);
718 ARG_UNUSED(tx_data);
719 ARG_UNUSED(size);
720 return -ENOTSUP;
721#endif
722}
723
744static inline int uart_fifo_fill_u16(const struct device *dev,
745 const uint16_t *tx_data,
746 int size)
747{
748#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
749 const struct uart_driver_api *api =
750 (const struct uart_driver_api *)dev->api;
751
752 if (api->fifo_fill_u16 == NULL) {
753 return -ENOSYS;
754 }
755
756 return api->fifo_fill_u16(dev, tx_data, size);
757#else
758 ARG_UNUSED(dev);
759 ARG_UNUSED(tx_data);
760 ARG_UNUSED(size);
761 return -ENOTSUP;
762#endif
763}
764
789static inline int uart_fifo_read(const struct device *dev, uint8_t *rx_data,
790 const int size)
791{
792#ifdef CONFIG_UART_INTERRUPT_DRIVEN
793 const struct uart_driver_api *api =
794 (const struct uart_driver_api *)dev->api;
795
796 if (api->fifo_read == NULL) {
797 return -ENOSYS;
798 }
799
800 return api->fifo_read(dev, rx_data, size);
801#else
802 ARG_UNUSED(dev);
803 ARG_UNUSED(rx_data);
804 ARG_UNUSED(size);
805 return -ENOTSUP;
806#endif
807}
808
833static inline int uart_fifo_read_u16(const struct device *dev,
834 uint16_t *rx_data,
835 const int size)
836{
837#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
838 const struct uart_driver_api *api =
839 (const struct uart_driver_api *)dev->api;
840
841 if (api->fifo_read_u16 == NULL) {
842 return -ENOSYS;
843 }
844
845 return api->fifo_read_u16(dev, rx_data, size);
846#else
847 ARG_UNUSED(dev);
848 ARG_UNUSED(rx_data);
849 ARG_UNUSED(size);
850 return -ENOTSUP;
851#endif
852}
853
859__syscall void uart_irq_tx_enable(const struct device *dev);
860
861static inline void z_impl_uart_irq_tx_enable(const struct device *dev)
862{
863#ifdef CONFIG_UART_INTERRUPT_DRIVEN
864 const struct uart_driver_api *api =
865 (const struct uart_driver_api *)dev->api;
866
867 if (api->irq_tx_enable != NULL) {
868 api->irq_tx_enable(dev);
869 }
870#else
871 ARG_UNUSED(dev);
872#endif
873}
874
880__syscall void uart_irq_tx_disable(const struct device *dev);
881
882static inline void z_impl_uart_irq_tx_disable(const struct device *dev)
883{
884#ifdef CONFIG_UART_INTERRUPT_DRIVEN
885 const struct uart_driver_api *api =
886 (const struct uart_driver_api *)dev->api;
887
888 if (api->irq_tx_disable != NULL) {
889 api->irq_tx_disable(dev);
890 }
891#else
892 ARG_UNUSED(dev);
893#endif
894}
895
914static inline int uart_irq_tx_ready(const struct device *dev)
915{
916#ifdef CONFIG_UART_INTERRUPT_DRIVEN
917 const struct uart_driver_api *api =
918 (const struct uart_driver_api *)dev->api;
919
920 if (api->irq_tx_ready == NULL) {
921 return -ENOSYS;
922 }
923
924 return api->irq_tx_ready(dev);
925#else
926 ARG_UNUSED(dev);
927 return -ENOTSUP;
928#endif
929}
930
936__syscall void uart_irq_rx_enable(const struct device *dev);
937
938static inline void z_impl_uart_irq_rx_enable(const struct device *dev)
939{
940#ifdef CONFIG_UART_INTERRUPT_DRIVEN
941 const struct uart_driver_api *api =
942 (const struct uart_driver_api *)dev->api;
943
944 if (api->irq_rx_enable != NULL) {
945 api->irq_rx_enable(dev);
946 }
947#else
948 ARG_UNUSED(dev);
949#endif
950}
951
957__syscall void uart_irq_rx_disable(const struct device *dev);
958
959static inline void z_impl_uart_irq_rx_disable(const struct device *dev)
960{
961#ifdef CONFIG_UART_INTERRUPT_DRIVEN
962 const struct uart_driver_api *api =
963 (const struct uart_driver_api *)dev->api;
964
965 if (api->irq_rx_disable != NULL) {
966 api->irq_rx_disable(dev);
967 }
968#else
969 ARG_UNUSED(dev);
970#endif
971}
972
992static inline int uart_irq_tx_complete(const struct device *dev)
993{
994#ifdef CONFIG_UART_INTERRUPT_DRIVEN
995 const struct uart_driver_api *api =
996 (const struct uart_driver_api *)dev->api;
997
998 if (api->irq_tx_complete == NULL) {
999 return -ENOSYS;
1000 }
1001 return api->irq_tx_complete(dev);
1002#else
1003 ARG_UNUSED(dev);
1004 return -ENOTSUP;
1005#endif
1006}
1007
1028static inline int uart_irq_rx_ready(const struct device *dev)
1029{
1030#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1031 const struct uart_driver_api *api =
1032 (const struct uart_driver_api *)dev->api;
1033
1034 if (api->irq_rx_ready == NULL) {
1035 return -ENOSYS;
1036 }
1037 return api->irq_rx_ready(dev);
1038#else
1039 ARG_UNUSED(dev);
1040 return -ENOTSUP;
1041#endif
1042}
1048__syscall void uart_irq_err_enable(const struct device *dev);
1049
1050static inline void z_impl_uart_irq_err_enable(const struct device *dev)
1051{
1052#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1053 const struct uart_driver_api *api =
1054 (const struct uart_driver_api *)dev->api;
1055
1056 if (api->irq_err_enable) {
1057 api->irq_err_enable(dev);
1058 }
1059#else
1060 ARG_UNUSED(dev);
1061#endif
1062}
1063
1069__syscall void uart_irq_err_disable(const struct device *dev);
1070
1071static inline void z_impl_uart_irq_err_disable(const struct device *dev)
1072{
1073#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1074 const struct uart_driver_api *api =
1075 (const struct uart_driver_api *)dev->api;
1076
1077 if (api->irq_err_disable) {
1078 api->irq_err_disable(dev);
1079 }
1080#else
1081 ARG_UNUSED(dev);
1082#endif
1083}
1084
1095__syscall int uart_irq_is_pending(const struct device *dev);
1096
1097static inline int z_impl_uart_irq_is_pending(const struct device *dev)
1098{
1099#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1100 const struct uart_driver_api *api =
1101 (const struct uart_driver_api *)dev->api;
1102
1103 if (api->irq_is_pending == NULL) {
1104 return -ENOSYS;
1105 }
1106 return api->irq_is_pending(dev);
1107#else
1108 ARG_UNUSED(dev);
1109 return -ENOTSUP;
1110#endif
1111}
1112
1138__syscall int uart_irq_update(const struct device *dev);
1139
1140static inline int z_impl_uart_irq_update(const struct device *dev)
1141{
1142#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1143 const struct uart_driver_api *api =
1144 (const struct uart_driver_api *)dev->api;
1145
1146 if (api->irq_update == NULL) {
1147 return -ENOSYS;
1148 }
1149 return api->irq_update(dev);
1150#else
1151 ARG_UNUSED(dev);
1152 return -ENOTSUP;
1153#endif
1154}
1155
1171static inline int uart_irq_callback_user_data_set(const struct device *dev,
1173 void *user_data)
1174{
1175#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1176 const struct uart_driver_api *api =
1177 (const struct uart_driver_api *)dev->api;
1178
1179 if ((api != NULL) && (api->irq_callback_set != NULL)) {
1180 api->irq_callback_set(dev, cb, user_data);
1181 return 0;
1182 } else {
1183 return -ENOSYS;
1184 }
1185#else
1186 ARG_UNUSED(dev);
1187 ARG_UNUSED(cb);
1188 ARG_UNUSED(user_data);
1189 return -ENOTSUP;
1190#endif
1191}
1192
1206static inline int uart_irq_callback_set(const struct device *dev,
1208{
1209 return uart_irq_callback_user_data_set(dev, cb, NULL);
1210}
1211
1236static inline int uart_callback_set(const struct device *dev,
1237 uart_callback_t callback,
1238 void *user_data)
1239{
1240#ifdef CONFIG_UART_ASYNC_API
1241 const struct uart_driver_api *api =
1242 (const struct uart_driver_api *)dev->api;
1243
1244 if (api->callback_set == NULL) {
1245 return -ENOSYS;
1246 }
1247
1248 return api->callback_set(dev, callback, user_data);
1249#else
1250 ARG_UNUSED(dev);
1251 ARG_UNUSED(callback);
1252 ARG_UNUSED(user_data);
1253 return -ENOTSUP;
1254#endif
1255}
1256
1274__syscall int uart_tx(const struct device *dev, const uint8_t *buf,
1275 size_t len,
1277
1278static inline int z_impl_uart_tx(const struct device *dev, const uint8_t *buf,
1279 size_t len, int32_t timeout)
1280
1281{
1282#ifdef CONFIG_UART_ASYNC_API
1283 const struct uart_driver_api *api =
1284 (const struct uart_driver_api *)dev->api;
1285
1286 return api->tx(dev, buf, len, timeout);
1287#else
1288 ARG_UNUSED(dev);
1289 ARG_UNUSED(buf);
1290 ARG_UNUSED(len);
1291 ARG_UNUSED(timeout);
1292 return -ENOTSUP;
1293#endif
1294}
1295
1313__syscall int uart_tx_u16(const struct device *dev, const uint16_t *buf,
1314 size_t len, int32_t timeout);
1315
1316static inline int z_impl_uart_tx_u16(const struct device *dev,
1317 const uint16_t *buf,
1318 size_t len, int32_t timeout)
1319
1320{
1321#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1322 const struct uart_driver_api *api =
1323 (const struct uart_driver_api *)dev->api;
1324
1325 return api->tx_u16(dev, buf, len, timeout);
1326#else
1327 ARG_UNUSED(dev);
1328 ARG_UNUSED(buf);
1329 ARG_UNUSED(len);
1330 ARG_UNUSED(timeout);
1331 return -ENOTSUP;
1332#endif
1333}
1334
1347__syscall int uart_tx_abort(const struct device *dev);
1348
1349static inline int z_impl_uart_tx_abort(const struct device *dev)
1350{
1351#ifdef CONFIG_UART_ASYNC_API
1352 const struct uart_driver_api *api =
1353 (const struct uart_driver_api *)dev->api;
1354
1355 return api->tx_abort(dev);
1356#else
1357 ARG_UNUSED(dev);
1358 return -ENOTSUP;
1359#endif
1360}
1361
1383__syscall int uart_rx_enable(const struct device *dev, uint8_t *buf,
1384 size_t len,
1386
1387static inline int z_impl_uart_rx_enable(const struct device *dev,
1388 uint8_t *buf,
1389 size_t len, int32_t timeout)
1390{
1391#ifdef CONFIG_UART_ASYNC_API
1392 const struct uart_driver_api *api =
1393 (const struct uart_driver_api *)dev->api;
1394
1395 return api->rx_enable(dev, buf, len, timeout);
1396#else
1397 ARG_UNUSED(dev);
1398 ARG_UNUSED(buf);
1399 ARG_UNUSED(len);
1400 ARG_UNUSED(timeout);
1401 return -ENOTSUP;
1402#endif
1403}
1404
1426__syscall int uart_rx_enable_u16(const struct device *dev, uint16_t *buf,
1427 size_t len, int32_t timeout);
1428
1429static inline int z_impl_uart_rx_enable_u16(const struct device *dev,
1430 uint16_t *buf, size_t len,
1432{
1433#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1434 const struct uart_driver_api *api =
1435 (const struct uart_driver_api *)dev->api;
1436
1437 return api->rx_enable_u16(dev, buf, len, timeout);
1438#else
1439 ARG_UNUSED(dev);
1440 ARG_UNUSED(buf);
1441 ARG_UNUSED(len);
1442 ARG_UNUSED(timeout);
1443 return -ENOTSUP;
1444#endif
1445}
1446
1467static inline int uart_rx_buf_rsp(const struct device *dev, uint8_t *buf,
1468 size_t len)
1469{
1470#ifdef CONFIG_UART_ASYNC_API
1471 const struct uart_driver_api *api =
1472 (const struct uart_driver_api *)dev->api;
1473
1474 return api->rx_buf_rsp(dev, buf, len);
1475#else
1476 ARG_UNUSED(dev);
1477 ARG_UNUSED(buf);
1478 ARG_UNUSED(len);
1479 return -ENOTSUP;
1480#endif
1481}
1482
1504static inline int uart_rx_buf_rsp_u16(const struct device *dev, uint16_t *buf,
1505 size_t len)
1506{
1507#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1508 const struct uart_driver_api *api =
1509 (const struct uart_driver_api *)dev->api;
1510
1511 return api->rx_buf_rsp_u16(dev, buf, len);
1512#else
1513 ARG_UNUSED(dev);
1514 ARG_UNUSED(buf);
1515 ARG_UNUSED(len);
1516 return -ENOTSUP;
1517#endif
1518}
1519
1535__syscall int uart_rx_disable(const struct device *dev);
1536
1537static inline int z_impl_uart_rx_disable(const struct device *dev)
1538{
1539#ifdef CONFIG_UART_ASYNC_API
1540 const struct uart_driver_api *api =
1541 (const struct uart_driver_api *)dev->api;
1542
1543 return api->rx_disable(dev);
1544#else
1545 ARG_UNUSED(dev);
1546 return -ENOTSUP;
1547#endif
1548}
1549
1566__syscall int uart_line_ctrl_set(const struct device *dev,
1567 uint32_t ctrl, uint32_t val);
1568
1569static inline int z_impl_uart_line_ctrl_set(const struct device *dev,
1570 uint32_t ctrl, uint32_t val)
1571{
1572#ifdef CONFIG_UART_LINE_CTRL
1573 const struct uart_driver_api *api =
1574 (const struct uart_driver_api *)dev->api;
1575
1576 if (api->line_ctrl_set == NULL) {
1577 return -ENOSYS;
1578 }
1579 return api->line_ctrl_set(dev, ctrl, val);
1580#else
1581 ARG_UNUSED(dev);
1582 ARG_UNUSED(ctrl);
1583 ARG_UNUSED(val);
1584 return -ENOTSUP;
1585#endif
1586}
1587
1600__syscall int uart_line_ctrl_get(const struct device *dev, uint32_t ctrl,
1601 uint32_t *val);
1602
1603static inline int z_impl_uart_line_ctrl_get(const struct device *dev,
1604 uint32_t ctrl, uint32_t *val)
1605{
1606#ifdef CONFIG_UART_LINE_CTRL
1607 const struct uart_driver_api *api =
1608 (const struct uart_driver_api *)dev->api;
1609
1610 if (api->line_ctrl_get == NULL) {
1611 return -ENOSYS;
1612 }
1613 return api->line_ctrl_get(dev, ctrl, val);
1614#else
1615 ARG_UNUSED(dev);
1616 ARG_UNUSED(ctrl);
1617 ARG_UNUSED(val);
1618 return -ENOTSUP;
1619#endif
1620}
1621
1637__syscall int uart_drv_cmd(const struct device *dev, uint32_t cmd, uint32_t p);
1638
1639static inline int z_impl_uart_drv_cmd(const struct device *dev, uint32_t cmd,
1640 uint32_t p)
1641{
1642#ifdef CONFIG_UART_DRV_CMD
1643 const struct uart_driver_api *api =
1644 (const struct uart_driver_api *)dev->api;
1645
1646 if (api->drv_cmd == NULL) {
1647 return -ENOSYS;
1648 }
1649 return api->drv_cmd(dev, cmd, p);
1650#else
1651 ARG_UNUSED(dev);
1652 ARG_UNUSED(cmd);
1653 ARG_UNUSED(p);
1654 return -ENOTSUP;
1655#endif
1656}
1657
1658#ifdef __cplusplus
1659}
1660#endif
1661
1666#include <syscalls/uart.h>
1667
1668#endif /* ZEPHYR_INCLUDE_DRIVERS_UART_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
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 BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
#define ENOSYS
Definition: errno.h:83
#define ENOTSUP
Definition: errno.h:115
int uart_rx_enable_u16(const struct device *dev, uint16_t *buf, size_t len, int32_t timeout)
Start receiving wide data through UART.
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.
Definition: uart.h:1467
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.
Definition: uart.h:1504
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:326
int uart_rx_enable(const struct device *dev, uint8_t *buf, size_t len, int32_t timeout)
Start receiving data through UART.
int uart_tx_abort(const struct device *dev)
Abort current TX transmission.
int uart_tx_u16(const struct device *dev, const uint16_t *buf, size_t len, int32_t timeout)
Send given number of datum from buffer through UART.
static int uart_callback_set(const struct device *dev, uart_callback_t callback, void *user_data)
Set event handler function.
Definition: uart.h:1236
uart_event_type
Types of events passed to callback in UART_ASYNC_API.
Definition: uart.h:209
int uart_tx(const struct device *dev, const uint8_t *buf, size_t len, int32_t timeout)
Send given number of bytes from buffer through UART.
int uart_rx_disable(const struct device *dev)
Disable RX.
@ UART_RX_STOPPED
RX has stopped due to external event.
Definition: uart.h:260
@ UART_TX_ABORTED
Transmitting aborted due to timeout or uart_tx_abort call.
Definition: uart.h:219
@ UART_RX_BUF_REQUEST
Driver requests next buffer for continuous reception.
Definition: uart.h:242
@ UART_TX_DONE
Whole TX buffer was transmitted.
Definition: uart.h:211
@ UART_RX_RDY
Received data is ready for processing.
Definition: uart.h:230
@ UART_RX_DISABLED
RX has been disabled and can be reenabled.
Definition: uart.h:254
@ UART_RX_BUF_RELEASED
Buffer is no longer used by UART driver.
Definition: uart.h:246
uart_line_ctrl
Line control signals.
Definition: uart.h:33
int uart_err_check(const struct device *dev)
Check whether an error was detected.
int uart_config_get(const struct device *dev, struct uart_config *cfg)
Get UART configuration.
uart_config_flow_control
Hardware flow control options.
Definition: uart.h:109
int uart_configure(const struct device *dev, const struct uart_config *cfg)
Set UART configuration.
int uart_drv_cmd(const struct device *dev, uint32_t cmd, uint32_t p)
Send extra command to driver.
int uart_line_ctrl_set(const struct device *dev, uint32_t ctrl, uint32_t val)
Manipulate line control for UART.
uart_config_parity
Parity modes.
Definition: uart.h:77
uart_config_data_bits
Number of data bits.
Definition: uart.h:94
uart_rx_stop_reason
Reception stop reasons.
Definition: uart.h:47
uart_config_stop_bits
Number of stop bits.
Definition: uart.h:86
int uart_line_ctrl_get(const struct device *dev, uint32_t ctrl, uint32_t *val)
Retrieve line control for UART.
@ UART_LINE_CTRL_DTR
Definition: uart.h:36
@ UART_LINE_CTRL_RTS
Definition: uart.h:35
@ UART_LINE_CTRL_BAUD_RATE
Definition: uart.h:34
@ UART_LINE_CTRL_DCD
Definition: uart.h:37
@ UART_LINE_CTRL_DSR
Definition: uart.h:38
@ UART_CFG_FLOW_CTRL_DTR_DSR
Definition: uart.h:112
@ UART_CFG_FLOW_CTRL_NONE
Definition: uart.h:110
@ UART_CFG_FLOW_CTRL_RS485
Definition: uart.h:113
@ UART_CFG_FLOW_CTRL_RTS_CTS
Definition: uart.h:111
@ UART_CFG_PARITY_MARK
Definition: uart.h:81
@ UART_CFG_PARITY_NONE
Definition: uart.h:78
@ UART_CFG_PARITY_ODD
Definition: uart.h:79
@ UART_CFG_PARITY_SPACE
Definition: uart.h:82
@ UART_CFG_PARITY_EVEN
Definition: uart.h:80
@ UART_CFG_DATA_BITS_5
Definition: uart.h:95
@ UART_CFG_DATA_BITS_8
Definition: uart.h:98
@ UART_CFG_DATA_BITS_7
Definition: uart.h:97
@ UART_CFG_DATA_BITS_6
Definition: uart.h:96
@ UART_CFG_DATA_BITS_9
Definition: uart.h:99
@ UART_ERROR_NOISE
Noise error.
Definition: uart.h:73
@ UART_ERROR_OVERRUN
Overrun error.
Definition: uart.h:49
@ UART_BREAK
Break interrupt.
Definition: uart.h:61
@ UART_ERROR_PARITY
Parity error.
Definition: uart.h:51
@ UART_ERROR_COLLISION
Collision error.
Definition: uart.h:71
@ UART_ERROR_FRAMING
Framing error.
Definition: uart.h:53
@ UART_CFG_STOP_BITS_1_5
Definition: uart.h:89
@ UART_CFG_STOP_BITS_0_5
Definition: uart.h:87
@ UART_CFG_STOP_BITS_1
Definition: uart.h:88
@ UART_CFG_STOP_BITS_2
Definition: uart.h:90
int uart_irq_is_pending(const struct device *dev)
Check if any IRQs is pending.
static int uart_fifo_read_u16(const struct device *dev, uint16_t *rx_data, const int size)
Read wide data from FIFO.
Definition: uart.h:833
void uart_irq_rx_enable(const struct device *dev)
Enable RX interrupt.
static int uart_irq_tx_ready(const struct device *dev)
Check if UART TX buffer can accept a new char.
Definition: uart.h:914
static int uart_irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb)
Set the IRQ callback function pointer (legacy).
Definition: uart.h:1206
void(* uart_irq_config_func_t)(const struct device *dev)
For configuring IRQ on each individual UART device.
Definition: uart.h:153
void uart_irq_err_enable(const struct device *dev)
Enable error interrupt.
static int uart_irq_tx_complete(const struct device *dev)
Check if UART TX block finished transmission.
Definition: uart.h:992
void uart_irq_tx_enable(const struct device *dev)
Enable TX interrupt in IER.
void uart_irq_rx_disable(const struct device *dev)
Disable RX interrupt.
static int uart_fifo_fill_u16(const struct device *dev, const uint16_t *tx_data, int size)
Fill FIFO with wide data.
Definition: uart.h:744
void uart_irq_err_disable(const struct device *dev)
Disable error interrupt.
static int uart_fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
Read data from FIFO.
Definition: uart.h:789
int uart_irq_update(const struct device *dev)
Start processing interrupts in ISR.
static int uart_irq_rx_ready(const struct device *dev)
Check if UART RX buffer has a received char.
Definition: uart.h:1028
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:145
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.
Definition: uart.h:1171
void uart_irq_tx_disable(const struct device *dev)
Disable TX interrupt in IER.
static int uart_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
Fill FIFO with data.
Definition: uart.h:703
void uart_poll_out(const struct device *dev, unsigned char out_char)
Write a character to the device for output.
void uart_poll_out_u16(const struct device *dev, uint16_t out_u16)
Write a 16-bit datum to the device for output.
int uart_poll_in_u16(const struct device *dev, uint16_t *p_u16)
Read a 16-bit datum from the device for input.
int uart_poll_in(const struct device *dev, unsigned char *p_char)
Read a character from the device for input.
struct k_pipe p
Definition: kobject.c:1322
__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:380
const void * api
Definition: device.h:386
UART controller configuration structure.
Definition: uart.h:125
uint8_t stop_bits
Definition: uart.h:128
uint8_t parity
Definition: uart.h:127
uint8_t data_bits
Definition: uart.h:129
uint32_t baudrate
Definition: uart.h:126
uint8_t flow_ctrl
Definition: uart.h:130
UART RX buffer released event data.
Definition: uart.h:287
uint8_t * buf
Definition: uart.h:289
UART RX stopped data.
Definition: uart.h:293
struct uart_event_rx data
Last received data.
Definition: uart.h:297
enum uart_rx_stop_reason reason
Reason why receiving stopped.
Definition: uart.h:295
UART RX event data.
Definition: uart.h:277
uint8_t * buf
Pointer to current buffer.
Definition: uart.h:279
size_t len
Number of new bytes received.
Definition: uart.h:283
size_t offset
Currently received data offset in bytes.
Definition: uart.h:281
UART TX event data.
Definition: uart.h:264
const uint8_t * buf
Pointer to current buffer.
Definition: uart.h:266
size_t len
Number of bytes sent.
Definition: uart.h:268
Structure containing information about current event.
Definition: uart.h:301
union uart_event::uart_event_data data
enum uart_event_type type
Type of event.
Definition: uart.h:303
static const intptr_t user_data[5]
Definition: main.c:588
Event data.
Definition: uart.h:305
struct uart_event_tx tx
UART_TX_DONE and UART_TX_ABORTED events data.
Definition: uart.h:307
struct uart_event_rx_stop rx_stop
UART_RX_STOPPED event data.
Definition: uart.h:313
struct uart_event_rx_buf rx_buf
UART_RX_BUF_RELEASED event data.
Definition: uart.h:311
struct uart_event_rx rx
UART_RX_RDY event data.
Definition: uart.h:309