Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
125};
126
139typedef void (*uart_irq_callback_user_data_t)(const struct device *dev,
140 void *user_data);
141
147typedef void (*uart_irq_config_func_t)(const struct device *dev);
148
255};
256
260 const uint8_t *buf;
262 size_t len;
263};
264
275 size_t offset;
277 size_t len;
278};
279
284};
285
292};
293
309};
310
320typedef void (*uart_callback_t)(const struct device *dev,
321 struct uart_event *evt, void *user_data);
322
334__subsystem struct uart_driver_api {
335
336#ifdef CONFIG_UART_ASYNC_API
337
338 int (*callback_set)(const struct device *dev,
339 uart_callback_t callback,
340 void *user_data);
341
342 int (*tx)(const struct device *dev, const uint8_t *buf, size_t len,
343 int32_t timeout);
344 int (*tx_abort)(const struct device *dev);
345
346 int (*rx_enable)(const struct device *dev, uint8_t *buf, size_t len,
347 int32_t timeout);
348 int (*rx_buf_rsp)(const struct device *dev, uint8_t *buf, size_t len);
349 int (*rx_disable)(const struct device *dev);
350
351#ifdef CONFIG_UART_WIDE_DATA
352 int (*tx_u16)(const struct device *dev, const uint16_t *buf,
353 size_t len, int32_t timeout);
354 int (*rx_enable_u16)(const struct device *dev, uint16_t *buf,
355 size_t len, int32_t timeout);
356 int (*rx_buf_rsp_u16)(const struct device *dev, uint16_t *buf,
357 size_t len);
358#endif
359
360#endif
361
363 int (*poll_in)(const struct device *dev, unsigned char *p_char);
364 void (*poll_out)(const struct device *dev, unsigned char out_char);
365
366#ifdef CONFIG_UART_WIDE_DATA
367 int (*poll_in_u16)(const struct device *dev, uint16_t *p_u16);
368 void (*poll_out_u16)(const struct device *dev, uint16_t out_u16);
369#endif
370
372 int (*err_check)(const struct device *dev);
373
374#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
376 int (*configure)(const struct device *dev,
377 const struct uart_config *cfg);
378 int (*config_get)(const struct device *dev, struct uart_config *cfg);
379#endif
380
381#ifdef CONFIG_UART_INTERRUPT_DRIVEN
382
384 int (*fifo_fill)(const struct device *dev, const uint8_t *tx_data,
385 int len);
386
387#ifdef CONFIG_UART_WIDE_DATA
388 int (*fifo_fill_u16)(const struct device *dev, const uint16_t *tx_data,
389 int len);
390#endif
391
393 int (*fifo_read)(const struct device *dev, uint8_t *rx_data,
394 const int size);
395
396#ifdef CONFIG_UART_WIDE_DATA
397 int (*fifo_read_u16)(const struct device *dev, uint16_t *rx_data,
398 const int size);
399#endif
400
402 void (*irq_tx_enable)(const struct device *dev);
403
405 void (*irq_tx_disable)(const struct device *dev);
406
408 int (*irq_tx_ready)(const struct device *dev);
409
411 void (*irq_rx_enable)(const struct device *dev);
412
414 void (*irq_rx_disable)(const struct device *dev);
415
417 int (*irq_tx_complete)(const struct device *dev);
418
420 int (*irq_rx_ready)(const struct device *dev);
421
423 void (*irq_err_enable)(const struct device *dev);
424
426 void (*irq_err_disable)(const struct device *dev);
427
429 int (*irq_is_pending)(const struct device *dev);
430
432 int (*irq_update)(const struct device *dev);
433
435 void (*irq_callback_set)(const struct device *dev,
437 void *user_data);
438
439#endif
440
441#ifdef CONFIG_UART_LINE_CTRL
442 int (*line_ctrl_set)(const struct device *dev, uint32_t ctrl,
443 uint32_t val);
444 int (*line_ctrl_get)(const struct device *dev, uint32_t ctrl,
445 uint32_t *val);
446#endif
447
448#ifdef CONFIG_UART_DRV_CMD
449 int (*drv_cmd)(const struct device *dev, uint32_t cmd, uint32_t p);
450#endif
451
452};
453
465__syscall int uart_err_check(const struct device *dev);
466
467static inline int z_impl_uart_err_check(const struct device *dev)
468{
469 const struct uart_driver_api *api =
470 (const struct uart_driver_api *)dev->api;
471
472 if (api->err_check == NULL) {
473 return -ENOSYS;
474 }
475
476 return api->err_check(dev);
477}
478
502__syscall int uart_poll_in(const struct device *dev, unsigned char *p_char);
503
504static inline int z_impl_uart_poll_in(const struct device *dev,
505 unsigned char *p_char)
506{
507 const struct uart_driver_api *api =
508 (const struct uart_driver_api *)dev->api;
509
510 if (api->poll_in == NULL) {
511 return -ENOSYS;
512 }
513
514 return api->poll_in(dev, p_char);
515}
516
536__syscall int uart_poll_in_u16(const struct device *dev, uint16_t *p_u16);
537
538static inline int z_impl_uart_poll_in_u16(const struct device *dev,
539 uint16_t *p_u16)
540{
541#ifdef CONFIG_UART_WIDE_DATA
542 const struct uart_driver_api *api =
543 (const struct uart_driver_api *)dev->api;
544
545 if (api->poll_in_u16 == NULL) {
546 return -ENOSYS;
547 }
548
549 return api->poll_in_u16(dev, p_u16);
550#else
551 ARG_UNUSED(dev);
552 ARG_UNUSED(p_u16);
553 return -ENOTSUP;
554#endif
555}
556
571__syscall void uart_poll_out(const struct device *dev,
572 unsigned char out_char);
573
574static inline void z_impl_uart_poll_out(const struct device *dev,
575 unsigned char out_char)
576{
577 const struct uart_driver_api *api =
578 (const struct uart_driver_api *)dev->api;
579
580 api->poll_out(dev, out_char);
581}
582
597__syscall void uart_poll_out_u16(const struct device *dev, uint16_t out_u16);
598
599static inline void z_impl_uart_poll_out_u16(const struct device *dev,
600 uint16_t out_u16)
601{
602#ifdef CONFIG_UART_WIDE_DATA
603 const struct uart_driver_api *api =
604 (const struct uart_driver_api *)dev->api;
605
606 api->poll_out_u16(dev, out_u16);
607#else
608 ARG_UNUSED(dev);
609 ARG_UNUSED(out_u16);
610#endif
611}
612
631__syscall int uart_configure(const struct device *dev,
632 const struct uart_config *cfg);
633
634static inline int z_impl_uart_configure(const struct device *dev,
635 const struct uart_config *cfg)
636{
637#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
638 const struct uart_driver_api *api =
639 (const struct uart_driver_api *)dev->api;
640
641 if (api->configure == NULL) {
642 return -ENOSYS;
643 }
644 return api->configure(dev, cfg);
645#else
646 ARG_UNUSED(dev);
647 ARG_UNUSED(cfg);
648 return -ENOTSUP;
649#endif
650}
651
666__syscall int uart_config_get(const struct device *dev,
667 struct uart_config *cfg);
668
669static inline int z_impl_uart_config_get(const struct device *dev,
670 struct uart_config *cfg)
671{
672#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
673 const struct uart_driver_api *api =
674 (const struct uart_driver_api *)dev->api;
675
676 if (api->config_get == NULL) {
677 return -ENOSYS;
678 }
679
680 return api->config_get(dev, cfg);
681#else
682 ARG_UNUSED(dev);
683 ARG_UNUSED(cfg);
684 return -ENOTSUP;
685#endif
686}
687
713static inline int uart_fifo_fill(const struct device *dev,
714 const uint8_t *tx_data,
715 int size)
716{
717#ifdef CONFIG_UART_INTERRUPT_DRIVEN
718 const struct uart_driver_api *api =
719 (const struct uart_driver_api *)dev->api;
720
721 if (api->fifo_fill == NULL) {
722 return -ENOSYS;
723 }
724
725 return api->fifo_fill(dev, tx_data, size);
726#else
727 ARG_UNUSED(dev);
728 ARG_UNUSED(tx_data);
729 ARG_UNUSED(size);
730 return -ENOTSUP;
731#endif
732}
733
754static inline int uart_fifo_fill_u16(const struct device *dev,
755 const uint16_t *tx_data,
756 int size)
757{
758#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
759 const struct uart_driver_api *api =
760 (const struct uart_driver_api *)dev->api;
761
762 if (api->fifo_fill_u16 == NULL) {
763 return -ENOSYS;
764 }
765
766 return api->fifo_fill_u16(dev, tx_data, size);
767#else
768 ARG_UNUSED(dev);
769 ARG_UNUSED(tx_data);
770 ARG_UNUSED(size);
771 return -ENOTSUP;
772#endif
773}
774
796static inline int uart_fifo_read(const struct device *dev, uint8_t *rx_data,
797 const int size)
798{
799#ifdef CONFIG_UART_INTERRUPT_DRIVEN
800 const struct uart_driver_api *api =
801 (const struct uart_driver_api *)dev->api;
802
803 if (api->fifo_read == NULL) {
804 return -ENOSYS;
805 }
806
807 return api->fifo_read(dev, rx_data, size);
808#else
809 ARG_UNUSED(dev);
810 ARG_UNUSED(rx_data);
811 ARG_UNUSED(size);
812 return -ENOTSUP;
813#endif
814}
815
837static inline int uart_fifo_read_u16(const struct device *dev,
838 uint16_t *rx_data,
839 const int size)
840{
841#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
842 const struct uart_driver_api *api =
843 (const struct uart_driver_api *)dev->api;
844
845 if (api->fifo_read_u16 == NULL) {
846 return -ENOSYS;
847 }
848
849 return api->fifo_read_u16(dev, rx_data, size);
850#else
851 ARG_UNUSED(dev);
852 ARG_UNUSED(rx_data);
853 ARG_UNUSED(size);
854 return -ENOTSUP;
855#endif
856}
857
863__syscall void uart_irq_tx_enable(const struct device *dev);
864
865static inline void z_impl_uart_irq_tx_enable(const struct device *dev)
866{
867#ifdef CONFIG_UART_INTERRUPT_DRIVEN
868 const struct uart_driver_api *api =
869 (const struct uart_driver_api *)dev->api;
870
871 if (api->irq_tx_enable != NULL) {
872 api->irq_tx_enable(dev);
873 }
874#else
875 ARG_UNUSED(dev);
876#endif
877}
878
884__syscall void uart_irq_tx_disable(const struct device *dev);
885
886static inline void z_impl_uart_irq_tx_disable(const struct device *dev)
887{
888#ifdef CONFIG_UART_INTERRUPT_DRIVEN
889 const struct uart_driver_api *api =
890 (const struct uart_driver_api *)dev->api;
891
892 if (api->irq_tx_disable != NULL) {
893 api->irq_tx_disable(dev);
894 }
895#else
896 ARG_UNUSED(dev);
897#endif
898}
899
918static inline int uart_irq_tx_ready(const struct device *dev)
919{
920#ifdef CONFIG_UART_INTERRUPT_DRIVEN
921 const struct uart_driver_api *api =
922 (const struct uart_driver_api *)dev->api;
923
924 if (api->irq_tx_ready == NULL) {
925 return -ENOSYS;
926 }
927
928 return api->irq_tx_ready(dev);
929#else
930 ARG_UNUSED(dev);
931 return -ENOTSUP;
932#endif
933}
934
940__syscall void uart_irq_rx_enable(const struct device *dev);
941
942static inline void z_impl_uart_irq_rx_enable(const struct device *dev)
943{
944#ifdef CONFIG_UART_INTERRUPT_DRIVEN
945 const struct uart_driver_api *api =
946 (const struct uart_driver_api *)dev->api;
947
948 if (api->irq_rx_enable != NULL) {
949 api->irq_rx_enable(dev);
950 }
951#else
952 ARG_UNUSED(dev);
953#endif
954}
955
961__syscall void uart_irq_rx_disable(const struct device *dev);
962
963static inline void z_impl_uart_irq_rx_disable(const struct device *dev)
964{
965#ifdef CONFIG_UART_INTERRUPT_DRIVEN
966 const struct uart_driver_api *api =
967 (const struct uart_driver_api *)dev->api;
968
969 if (api->irq_rx_disable != NULL) {
970 api->irq_rx_disable(dev);
971 }
972#else
973 ARG_UNUSED(dev);
974#endif
975}
976
996static inline int uart_irq_tx_complete(const struct device *dev)
997{
998#ifdef CONFIG_UART_INTERRUPT_DRIVEN
999 const struct uart_driver_api *api =
1000 (const struct uart_driver_api *)dev->api;
1001
1002 if (api->irq_tx_complete == NULL) {
1003 return -ENOSYS;
1004 }
1005 return api->irq_tx_complete(dev);
1006#else
1007 ARG_UNUSED(dev);
1008 return -ENOTSUP;
1009#endif
1010}
1011
1032static inline int uart_irq_rx_ready(const struct device *dev)
1033{
1034#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1035 const struct uart_driver_api *api =
1036 (const struct uart_driver_api *)dev->api;
1037
1038 if (api->irq_rx_ready == NULL) {
1039 return -ENOSYS;
1040 }
1041 return api->irq_rx_ready(dev);
1042#else
1043 ARG_UNUSED(dev);
1044 return -ENOTSUP;
1045#endif
1046}
1052__syscall void uart_irq_err_enable(const struct device *dev);
1053
1054static inline void z_impl_uart_irq_err_enable(const struct device *dev)
1055{
1056#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1057 const struct uart_driver_api *api =
1058 (const struct uart_driver_api *)dev->api;
1059
1060 if (api->irq_err_enable) {
1061 api->irq_err_enable(dev);
1062 }
1063#else
1064 ARG_UNUSED(dev);
1065#endif
1066}
1067
1073__syscall void uart_irq_err_disable(const struct device *dev);
1074
1075static inline void z_impl_uart_irq_err_disable(const struct device *dev)
1076{
1077#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1078 const struct uart_driver_api *api =
1079 (const struct uart_driver_api *)dev->api;
1080
1081 if (api->irq_err_disable) {
1082 api->irq_err_disable(dev);
1083 }
1084#else
1085 ARG_UNUSED(dev);
1086#endif
1087}
1088
1099__syscall int uart_irq_is_pending(const struct device *dev);
1100
1101static inline int z_impl_uart_irq_is_pending(const struct device *dev)
1102{
1103#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1104 const struct uart_driver_api *api =
1105 (const struct uart_driver_api *)dev->api;
1106
1107 if (api->irq_is_pending == NULL) {
1108 return -ENOSYS;
1109 }
1110 return api->irq_is_pending(dev);
1111#else
1112 ARG_UNUSED(dev);
1113 return -ENOTSUP;
1114#endif
1115}
1116
1142__syscall int uart_irq_update(const struct device *dev);
1143
1144static inline int z_impl_uart_irq_update(const struct device *dev)
1145{
1146#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1147 const struct uart_driver_api *api =
1148 (const struct uart_driver_api *)dev->api;
1149
1150 if (api->irq_update == NULL) {
1151 return -ENOSYS;
1152 }
1153 return api->irq_update(dev);
1154#else
1155 ARG_UNUSED(dev);
1156 return -ENOTSUP;
1157#endif
1158}
1159
1175static inline int uart_irq_callback_user_data_set(const struct device *dev,
1177 void *user_data)
1178{
1179#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1180 const struct uart_driver_api *api =
1181 (const struct uart_driver_api *)dev->api;
1182
1183 if ((api != NULL) && (api->irq_callback_set != NULL)) {
1184 api->irq_callback_set(dev, cb, user_data);
1185 return 0;
1186 } else {
1187 return -ENOSYS;
1188 }
1189#else
1190 ARG_UNUSED(dev);
1191 ARG_UNUSED(cb);
1192 ARG_UNUSED(user_data);
1193 return -ENOTSUP;
1194#endif
1195}
1196
1210static inline int uart_irq_callback_set(const struct device *dev,
1212{
1213 return uart_irq_callback_user_data_set(dev, cb, NULL);
1214}
1215
1240static inline int uart_callback_set(const struct device *dev,
1241 uart_callback_t callback,
1242 void *user_data)
1243{
1244#ifdef CONFIG_UART_ASYNC_API
1245 const struct uart_driver_api *api =
1246 (const struct uart_driver_api *)dev->api;
1247
1248 if (api->callback_set == NULL) {
1249 return -ENOSYS;
1250 }
1251
1252 return api->callback_set(dev, callback, user_data);
1253#else
1254 ARG_UNUSED(dev);
1255 ARG_UNUSED(callback);
1256 ARG_UNUSED(user_data);
1257 return -ENOTSUP;
1258#endif
1259}
1260
1278__syscall int uart_tx(const struct device *dev, const uint8_t *buf,
1279 size_t len,
1280 int32_t timeout);
1281
1282static inline int z_impl_uart_tx(const struct device *dev, const uint8_t *buf,
1283 size_t len, int32_t timeout)
1284
1285{
1286#ifdef CONFIG_UART_ASYNC_API
1287 const struct uart_driver_api *api =
1288 (const struct uart_driver_api *)dev->api;
1289
1290 return api->tx(dev, buf, len, timeout);
1291#else
1292 ARG_UNUSED(dev);
1293 ARG_UNUSED(buf);
1294 ARG_UNUSED(len);
1295 ARG_UNUSED(timeout);
1296 return -ENOTSUP;
1297#endif
1298}
1299
1317__syscall int uart_tx_u16(const struct device *dev, const uint16_t *buf,
1318 size_t len, int32_t timeout);
1319
1320static inline int z_impl_uart_tx_u16(const struct device *dev,
1321 const uint16_t *buf,
1322 size_t len, int32_t timeout)
1323
1324{
1325#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1326 const struct uart_driver_api *api =
1327 (const struct uart_driver_api *)dev->api;
1328
1329 return api->tx_u16(dev, buf, len, timeout);
1330#else
1331 ARG_UNUSED(dev);
1332 ARG_UNUSED(buf);
1333 ARG_UNUSED(len);
1334 ARG_UNUSED(timeout);
1335 return -ENOTSUP;
1336#endif
1337}
1338
1351__syscall int uart_tx_abort(const struct device *dev);
1352
1353static inline int z_impl_uart_tx_abort(const struct device *dev)
1354{
1355#ifdef CONFIG_UART_ASYNC_API
1356 const struct uart_driver_api *api =
1357 (const struct uart_driver_api *)dev->api;
1358
1359 return api->tx_abort(dev);
1360#else
1361 ARG_UNUSED(dev);
1362 return -ENOTSUP;
1363#endif
1364}
1365
1387__syscall int uart_rx_enable(const struct device *dev, uint8_t *buf,
1388 size_t len,
1389 int32_t timeout);
1390
1391static inline int z_impl_uart_rx_enable(const struct device *dev,
1392 uint8_t *buf,
1393 size_t len, int32_t timeout)
1394{
1395#ifdef CONFIG_UART_ASYNC_API
1396 const struct uart_driver_api *api =
1397 (const struct uart_driver_api *)dev->api;
1398
1399 return api->rx_enable(dev, buf, len, timeout);
1400#else
1401 ARG_UNUSED(dev);
1402 ARG_UNUSED(buf);
1403 ARG_UNUSED(len);
1404 ARG_UNUSED(timeout);
1405 return -ENOTSUP;
1406#endif
1407}
1408
1430__syscall int uart_rx_enable_u16(const struct device *dev, uint16_t *buf,
1431 size_t len, int32_t timeout);
1432
1433static inline int z_impl_uart_rx_enable_u16(const struct device *dev,
1434 uint16_t *buf, size_t len,
1435 int32_t timeout)
1436{
1437#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1438 const struct uart_driver_api *api =
1439 (const struct uart_driver_api *)dev->api;
1440
1441 return api->rx_enable_u16(dev, buf, len, timeout);
1442#else
1443 ARG_UNUSED(dev);
1444 ARG_UNUSED(buf);
1445 ARG_UNUSED(len);
1446 ARG_UNUSED(timeout);
1447 return -ENOTSUP;
1448#endif
1449}
1450
1471static inline int uart_rx_buf_rsp(const struct device *dev, uint8_t *buf,
1472 size_t len)
1473{
1474#ifdef CONFIG_UART_ASYNC_API
1475 const struct uart_driver_api *api =
1476 (const struct uart_driver_api *)dev->api;
1477
1478 return api->rx_buf_rsp(dev, buf, len);
1479#else
1480 ARG_UNUSED(dev);
1481 ARG_UNUSED(buf);
1482 ARG_UNUSED(len);
1483 return -ENOTSUP;
1484#endif
1485}
1486
1508static inline int uart_rx_buf_rsp_u16(const struct device *dev, uint16_t *buf,
1509 size_t len)
1510{
1511#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1512 const struct uart_driver_api *api =
1513 (const struct uart_driver_api *)dev->api;
1514
1515 return api->rx_buf_rsp_u16(dev, buf, len);
1516#else
1517 ARG_UNUSED(dev);
1518 ARG_UNUSED(buf);
1519 ARG_UNUSED(len);
1520 return -ENOTSUP;
1521#endif
1522}
1523
1539__syscall int uart_rx_disable(const struct device *dev);
1540
1541static inline int z_impl_uart_rx_disable(const struct device *dev)
1542{
1543#ifdef CONFIG_UART_ASYNC_API
1544 const struct uart_driver_api *api =
1545 (const struct uart_driver_api *)dev->api;
1546
1547 return api->rx_disable(dev);
1548#else
1549 ARG_UNUSED(dev);
1550 return -ENOTSUP;
1551#endif
1552}
1553
1570__syscall int uart_line_ctrl_set(const struct device *dev,
1571 uint32_t ctrl, uint32_t val);
1572
1573static inline int z_impl_uart_line_ctrl_set(const struct device *dev,
1574 uint32_t ctrl, uint32_t val)
1575{
1576#ifdef CONFIG_UART_LINE_CTRL
1577 const struct uart_driver_api *api =
1578 (const struct uart_driver_api *)dev->api;
1579
1580 if (api->line_ctrl_set == NULL) {
1581 return -ENOSYS;
1582 }
1583 return api->line_ctrl_set(dev, ctrl, val);
1584#else
1585 ARG_UNUSED(dev);
1586 ARG_UNUSED(ctrl);
1587 ARG_UNUSED(val);
1588 return -ENOTSUP;
1589#endif
1590}
1591
1604__syscall int uart_line_ctrl_get(const struct device *dev, uint32_t ctrl,
1605 uint32_t *val);
1606
1607static inline int z_impl_uart_line_ctrl_get(const struct device *dev,
1608 uint32_t ctrl, uint32_t *val)
1609{
1610#ifdef CONFIG_UART_LINE_CTRL
1611 const struct uart_driver_api *api =
1612 (const struct uart_driver_api *)dev->api;
1613
1614 if (api->line_ctrl_get == NULL) {
1615 return -ENOSYS;
1616 }
1617 return api->line_ctrl_get(dev, ctrl, val);
1618#else
1619 ARG_UNUSED(dev);
1620 ARG_UNUSED(ctrl);
1621 ARG_UNUSED(val);
1622 return -ENOTSUP;
1623#endif
1624}
1625
1641__syscall int uart_drv_cmd(const struct device *dev, uint32_t cmd, uint32_t p);
1642
1643static inline int z_impl_uart_drv_cmd(const struct device *dev, uint32_t cmd,
1644 uint32_t p)
1645{
1646#ifdef CONFIG_UART_DRV_CMD
1647 const struct uart_driver_api *api =
1648 (const struct uart_driver_api *)dev->api;
1649
1650 if (api->drv_cmd == NULL) {
1651 return -ENOSYS;
1652 }
1653 return api->drv_cmd(dev, cmd, p);
1654#else
1655 ARG_UNUSED(dev);
1656 ARG_UNUSED(cmd);
1657 ARG_UNUSED(p);
1658 return -ENOTSUP;
1659#endif
1660}
1661
1662#ifdef __cplusplus
1663}
1664#endif
1665
1670#include <syscalls/uart.h>
1671
1672#endif /* ZEPHYR_INCLUDE_DRIVERS_UART_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 BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
#define ENOSYS
Function not implemented.
Definition: errno.h:83
#define ENOTSUP
Unsupported value.
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:1471
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:1508
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:320
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:1240
uart_event_type
Types of events passed to callback in UART_ASYNC_API.
Definition: uart.h:203
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:254
@ UART_TX_ABORTED
Transmitting aborted due to timeout or uart_tx_abort call.
Definition: uart.h:213
@ UART_RX_BUF_REQUEST
Driver requests next buffer for continuous reception.
Definition: uart.h:236
@ UART_TX_DONE
Whole TX buffer was transmitted.
Definition: uart.h:205
@ UART_RX_RDY
Received data is ready for processing.
Definition: uart.h:224
@ UART_RX_DISABLED
RX has been disabled and can be reenabled.
Definition: uart.h:248
@ UART_RX_BUF_RELEASED
Buffer is no longer used by UART driver.
Definition: uart.h:240
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
Data Terminal Ready (DTR)
Definition: uart.h:36
@ UART_LINE_CTRL_RTS
Request To Send (RTS)
Definition: uart.h:35
@ UART_LINE_CTRL_BAUD_RATE
Baud rate.
Definition: uart.h:34
@ UART_LINE_CTRL_DCD
Data Carrier Detect (DCD)
Definition: uart.h:37
@ UART_LINE_CTRL_DSR
Data Set Ready (DSR)
Definition: uart.h:38
@ UART_CFG_FLOW_CTRL_DTR_DSR
DTR/DSR flow control.
Definition: uart.h:112
@ UART_CFG_FLOW_CTRL_NONE
No flow control.
Definition: uart.h:110
@ UART_CFG_FLOW_CTRL_RS485
RS485 flow control.
Definition: uart.h:113
@ UART_CFG_FLOW_CTRL_RTS_CTS
RTS/CTS flow control.
Definition: uart.h:111
@ UART_CFG_PARITY_MARK
Mark parity.
Definition: uart.h:81
@ UART_CFG_PARITY_NONE
No parity.
Definition: uart.h:78
@ UART_CFG_PARITY_ODD
Odd parity.
Definition: uart.h:79
@ UART_CFG_PARITY_SPACE
Space parity.
Definition: uart.h:82
@ UART_CFG_PARITY_EVEN
Even parity.
Definition: uart.h:80
@ UART_CFG_DATA_BITS_5
5 data bits
Definition: uart.h:95
@ UART_CFG_DATA_BITS_8
8 data bits
Definition: uart.h:98
@ UART_CFG_DATA_BITS_7
7 data bits
Definition: uart.h:97
@ UART_CFG_DATA_BITS_6
6 data bits
Definition: uart.h:96
@ UART_CFG_DATA_BITS_9
9 data bits
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
1.5 stop bits
Definition: uart.h:89
@ UART_CFG_STOP_BITS_0_5
0.5 stop bit
Definition: uart.h:87
@ UART_CFG_STOP_BITS_1
1 stop bit
Definition: uart.h:88
@ UART_CFG_STOP_BITS_2
2 stop bits
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:837
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:918
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:1210
void(* uart_irq_config_func_t)(const struct device *dev)
For configuring IRQ on each individual UART device.
Definition: uart.h:147
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:996
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:754
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:796
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:1032
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:139
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:1175
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:713
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.
__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:387
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:393
UART controller configuration structure.
Definition: uart.h:119
uint8_t stop_bits
Stop bits, use uart_config_stop_bits.
Definition: uart.h:122
uint8_t parity
Parity bit, use uart_config_parity.
Definition: uart.h:121
uint8_t data_bits
Data bits, use uart_config_data_bits.
Definition: uart.h:123
uint32_t baudrate
Baudrate setting in bps.
Definition: uart.h:120
uint8_t flow_ctrl
Flow control setting, use uart_config_flow_control.
Definition: uart.h:124
UART RX buffer released event data.
Definition: uart.h:281
uint8_t * buf
Pointer to buffer that is no longer in use.
Definition: uart.h:283
UART RX stopped data.
Definition: uart.h:287
struct uart_event_rx data
Last received data.
Definition: uart.h:291
enum uart_rx_stop_reason reason
Reason why receiving stopped.
Definition: uart.h:289
UART RX event data.
Definition: uart.h:271
uint8_t * buf
Pointer to current buffer.
Definition: uart.h:273
size_t len
Number of new bytes received.
Definition: uart.h:277
size_t offset
Currently received data offset in bytes.
Definition: uart.h:275
UART TX event data.
Definition: uart.h:258
const uint8_t * buf
Pointer to current buffer.
Definition: uart.h:260
size_t len
Number of bytes sent.
Definition: uart.h:262
Structure containing information about current event.
Definition: uart.h:295
union uart_event::uart_event_data data
enum uart_event_type type
Type of event.
Definition: uart.h:297
Event data.
Definition: uart.h:299
struct uart_event_tx tx
UART_TX_DONE and UART_TX_ABORTED events data.
Definition: uart.h:301
struct uart_event_rx_stop rx_stop
UART_RX_STOPPED event data.
Definition: uart.h:307
struct uart_event_rx_buf rx_buf
UART_RX_BUF_RELEASED event data.
Definition: uart.h:305
struct uart_event_rx rx
UART_RX_RDY event data.
Definition: uart.h:303