Zephyr API Documentation  3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
25#include <errno.h>
26#include <stddef.h>
27
28#include <zephyr/device.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
41};
42
63 UART_BREAK = (1 << 3),
75 UART_ERROR_NOISE = (1 << 5),
76};
77
85};
86
93};
94
102};
103
116};
117
127};
128
141typedef void (*uart_irq_callback_user_data_t)(const struct device *dev,
142 void *user_data);
143
149typedef void (*uart_irq_config_func_t)(const struct device *dev);
150
259};
260
264 const uint8_t *buf;
266 size_t len;
267};
268
279 size_t offset;
281 size_t len;
282};
283
288};
289
296};
297
313};
314
324typedef void (*uart_callback_t)(const struct device *dev,
325 struct uart_event *evt, void *user_data);
326
338__subsystem struct uart_driver_api {
339
340#ifdef CONFIG_UART_ASYNC_API
341
342 int (*callback_set)(const struct device *dev,
343 uart_callback_t callback,
344 void *user_data);
345
346 int (*tx)(const struct device *dev, const uint8_t *buf, size_t len,
347 int32_t timeout);
348 int (*tx_abort)(const struct device *dev);
349
350 int (*rx_enable)(const struct device *dev, uint8_t *buf, size_t len,
351 int32_t timeout);
352 int (*rx_buf_rsp)(const struct device *dev, uint8_t *buf, size_t len);
353 int (*rx_disable)(const struct device *dev);
354
355#ifdef CONFIG_UART_WIDE_DATA
356 int (*tx_u16)(const struct device *dev, const uint16_t *buf,
357 size_t len, int32_t timeout);
358 int (*rx_enable_u16)(const struct device *dev, uint16_t *buf,
359 size_t len, int32_t timeout);
360 int (*rx_buf_rsp_u16)(const struct device *dev, uint16_t *buf,
361 size_t len);
362#endif
363
364#endif
365
367 int (*poll_in)(const struct device *dev, unsigned char *p_char);
368 void (*poll_out)(const struct device *dev, unsigned char out_char);
369
370#ifdef CONFIG_UART_WIDE_DATA
371 int (*poll_in_u16)(const struct device *dev, uint16_t *p_u16);
372 void (*poll_out_u16)(const struct device *dev, uint16_t out_u16);
373#endif
374
376 int (*err_check)(const struct device *dev);
377
378#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
380 int (*configure)(const struct device *dev,
381 const struct uart_config *cfg);
382 int (*config_get)(const struct device *dev, struct uart_config *cfg);
383#endif
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
635__syscall int uart_configure(const struct device *dev,
636 const struct uart_config *cfg);
637
638static inline int z_impl_uart_configure(const struct device *dev,
639 const struct uart_config *cfg)
640{
641#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
642 const struct uart_driver_api *api =
643 (const struct uart_driver_api *)dev->api;
644
645 if (api->configure == NULL) {
646 return -ENOSYS;
647 }
648 return api->configure(dev, cfg);
649#else
650 ARG_UNUSED(dev);
651 ARG_UNUSED(cfg);
652 return -ENOTSUP;
653#endif
654}
655
670__syscall int uart_config_get(const struct device *dev,
671 struct uart_config *cfg);
672
673static inline int z_impl_uart_config_get(const struct device *dev,
674 struct uart_config *cfg)
675{
676#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
677 const struct uart_driver_api *api =
678 (const struct uart_driver_api *)dev->api;
679
680 if (api->config_get == NULL) {
681 return -ENOSYS;
682 }
683
684 return api->config_get(dev, cfg);
685#else
686 ARG_UNUSED(dev);
687 ARG_UNUSED(cfg);
688 return -ENOTSUP;
689#endif
690}
691
717static inline int uart_fifo_fill(const struct device *dev,
718 const uint8_t *tx_data,
719 int size)
720{
721#ifdef CONFIG_UART_INTERRUPT_DRIVEN
722 const struct uart_driver_api *api =
723 (const struct uart_driver_api *)dev->api;
724
725 if (api->fifo_fill == NULL) {
726 return -ENOSYS;
727 }
728
729 return api->fifo_fill(dev, tx_data, size);
730#else
731 ARG_UNUSED(dev);
732 ARG_UNUSED(tx_data);
733 ARG_UNUSED(size);
734 return -ENOTSUP;
735#endif
736}
737
758static inline int uart_fifo_fill_u16(const struct device *dev,
759 const uint16_t *tx_data,
760 int size)
761{
762#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
763 const struct uart_driver_api *api =
764 (const struct uart_driver_api *)dev->api;
765
766 if (api->fifo_fill_u16 == NULL) {
767 return -ENOSYS;
768 }
769
770 return api->fifo_fill_u16(dev, tx_data, size);
771#else
772 ARG_UNUSED(dev);
773 ARG_UNUSED(tx_data);
774 ARG_UNUSED(size);
775 return -ENOTSUP;
776#endif
777}
778
800static inline int uart_fifo_read(const struct device *dev, uint8_t *rx_data,
801 const int size)
802{
803#ifdef CONFIG_UART_INTERRUPT_DRIVEN
804 const struct uart_driver_api *api =
805 (const struct uart_driver_api *)dev->api;
806
807 if (api->fifo_read == NULL) {
808 return -ENOSYS;
809 }
810
811 return api->fifo_read(dev, rx_data, size);
812#else
813 ARG_UNUSED(dev);
814 ARG_UNUSED(rx_data);
815 ARG_UNUSED(size);
816 return -ENOTSUP;
817#endif
818}
819
841static inline int uart_fifo_read_u16(const struct device *dev,
842 uint16_t *rx_data,
843 const int size)
844{
845#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
846 const struct uart_driver_api *api =
847 (const struct uart_driver_api *)dev->api;
848
849 if (api->fifo_read_u16 == NULL) {
850 return -ENOSYS;
851 }
852
853 return api->fifo_read_u16(dev, rx_data, size);
854#else
855 ARG_UNUSED(dev);
856 ARG_UNUSED(rx_data);
857 ARG_UNUSED(size);
858 return -ENOTSUP;
859#endif
860}
861
867__syscall void uart_irq_tx_enable(const struct device *dev);
868
869static inline void z_impl_uart_irq_tx_enable(const struct device *dev)
870{
871#ifdef CONFIG_UART_INTERRUPT_DRIVEN
872 const struct uart_driver_api *api =
873 (const struct uart_driver_api *)dev->api;
874
875 if (api->irq_tx_enable != NULL) {
876 api->irq_tx_enable(dev);
877 }
878#else
879 ARG_UNUSED(dev);
880#endif
881}
882
888__syscall void uart_irq_tx_disable(const struct device *dev);
889
890static inline void z_impl_uart_irq_tx_disable(const struct device *dev)
891{
892#ifdef CONFIG_UART_INTERRUPT_DRIVEN
893 const struct uart_driver_api *api =
894 (const struct uart_driver_api *)dev->api;
895
896 if (api->irq_tx_disable != NULL) {
897 api->irq_tx_disable(dev);
898 }
899#else
900 ARG_UNUSED(dev);
901#endif
902}
903
922static inline int uart_irq_tx_ready(const struct device *dev)
923{
924#ifdef CONFIG_UART_INTERRUPT_DRIVEN
925 const struct uart_driver_api *api =
926 (const struct uart_driver_api *)dev->api;
927
928 if (api->irq_tx_ready == NULL) {
929 return -ENOSYS;
930 }
931
932 return api->irq_tx_ready(dev);
933#else
934 ARG_UNUSED(dev);
935 return -ENOTSUP;
936#endif
937}
938
944__syscall void uart_irq_rx_enable(const struct device *dev);
945
946static inline void z_impl_uart_irq_rx_enable(const struct device *dev)
947{
948#ifdef CONFIG_UART_INTERRUPT_DRIVEN
949 const struct uart_driver_api *api =
950 (const struct uart_driver_api *)dev->api;
951
952 if (api->irq_rx_enable != NULL) {
953 api->irq_rx_enable(dev);
954 }
955#else
956 ARG_UNUSED(dev);
957#endif
958}
959
965__syscall void uart_irq_rx_disable(const struct device *dev);
966
967static inline void z_impl_uart_irq_rx_disable(const struct device *dev)
968{
969#ifdef CONFIG_UART_INTERRUPT_DRIVEN
970 const struct uart_driver_api *api =
971 (const struct uart_driver_api *)dev->api;
972
973 if (api->irq_rx_disable != NULL) {
974 api->irq_rx_disable(dev);
975 }
976#else
977 ARG_UNUSED(dev);
978#endif
979}
980
1000static inline int uart_irq_tx_complete(const struct device *dev)
1001{
1002#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1003 const struct uart_driver_api *api =
1004 (const struct uart_driver_api *)dev->api;
1005
1006 if (api->irq_tx_complete == NULL) {
1007 return -ENOSYS;
1008 }
1009 return api->irq_tx_complete(dev);
1010#else
1011 ARG_UNUSED(dev);
1012 return -ENOTSUP;
1013#endif
1014}
1015
1036static inline int uart_irq_rx_ready(const struct device *dev)
1037{
1038#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1039 const struct uart_driver_api *api =
1040 (const struct uart_driver_api *)dev->api;
1041
1042 if (api->irq_rx_ready == NULL) {
1043 return -ENOSYS;
1044 }
1045 return api->irq_rx_ready(dev);
1046#else
1047 ARG_UNUSED(dev);
1048 return -ENOTSUP;
1049#endif
1050}
1056__syscall void uart_irq_err_enable(const struct device *dev);
1057
1058static inline void z_impl_uart_irq_err_enable(const struct device *dev)
1059{
1060#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1061 const struct uart_driver_api *api =
1062 (const struct uart_driver_api *)dev->api;
1063
1064 if (api->irq_err_enable) {
1065 api->irq_err_enable(dev);
1066 }
1067#else
1068 ARG_UNUSED(dev);
1069#endif
1070}
1071
1077__syscall void uart_irq_err_disable(const struct device *dev);
1078
1079static inline void z_impl_uart_irq_err_disable(const struct device *dev)
1080{
1081#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1082 const struct uart_driver_api *api =
1083 (const struct uart_driver_api *)dev->api;
1084
1085 if (api->irq_err_disable) {
1086 api->irq_err_disable(dev);
1087 }
1088#else
1089 ARG_UNUSED(dev);
1090#endif
1091}
1092
1103__syscall int uart_irq_is_pending(const struct device *dev);
1104
1105static inline int z_impl_uart_irq_is_pending(const struct device *dev)
1106{
1107#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1108 const struct uart_driver_api *api =
1109 (const struct uart_driver_api *)dev->api;
1110
1111 if (api->irq_is_pending == NULL) {
1112 return -ENOSYS;
1113 }
1114 return api->irq_is_pending(dev);
1115#else
1116 ARG_UNUSED(dev);
1117 return -ENOTSUP;
1118#endif
1119}
1120
1146__syscall int uart_irq_update(const struct device *dev);
1147
1148static inline int z_impl_uart_irq_update(const struct device *dev)
1149{
1150#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1151 const struct uart_driver_api *api =
1152 (const struct uart_driver_api *)dev->api;
1153
1154 if (api->irq_update == NULL) {
1155 return -ENOSYS;
1156 }
1157 return api->irq_update(dev);
1158#else
1159 ARG_UNUSED(dev);
1160 return -ENOTSUP;
1161#endif
1162}
1163
1179static inline int uart_irq_callback_user_data_set(const struct device *dev,
1181 void *user_data)
1182{
1183#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1184 const struct uart_driver_api *api =
1185 (const struct uart_driver_api *)dev->api;
1186
1187 if ((api != NULL) && (api->irq_callback_set != NULL)) {
1188 api->irq_callback_set(dev, cb, user_data);
1189 return 0;
1190 } else {
1191 return -ENOSYS;
1192 }
1193#else
1194 ARG_UNUSED(dev);
1195 ARG_UNUSED(cb);
1196 ARG_UNUSED(user_data);
1197 return -ENOTSUP;
1198#endif
1199}
1200
1214static inline int uart_irq_callback_set(const struct device *dev,
1216{
1217 return uart_irq_callback_user_data_set(dev, cb, NULL);
1218}
1219
1244static inline int uart_callback_set(const struct device *dev,
1245 uart_callback_t callback,
1246 void *user_data)
1247{
1248#ifdef CONFIG_UART_ASYNC_API
1249 const struct uart_driver_api *api =
1250 (const struct uart_driver_api *)dev->api;
1251
1252 if (api->callback_set == NULL) {
1253 return -ENOSYS;
1254 }
1255
1256 return api->callback_set(dev, callback, user_data);
1257#else
1258 ARG_UNUSED(dev);
1259 ARG_UNUSED(callback);
1260 ARG_UNUSED(user_data);
1261 return -ENOTSUP;
1262#endif
1263}
1264
1282__syscall int uart_tx(const struct device *dev, const uint8_t *buf,
1283 size_t len,
1284 int32_t timeout);
1285
1286static inline int z_impl_uart_tx(const struct device *dev, const uint8_t *buf,
1287 size_t len, int32_t timeout)
1288
1289{
1290#ifdef CONFIG_UART_ASYNC_API
1291 const struct uart_driver_api *api =
1292 (const struct uart_driver_api *)dev->api;
1293
1294 return api->tx(dev, buf, len, timeout);
1295#else
1296 ARG_UNUSED(dev);
1297 ARG_UNUSED(buf);
1298 ARG_UNUSED(len);
1299 ARG_UNUSED(timeout);
1300 return -ENOTSUP;
1301#endif
1302}
1303
1321__syscall int uart_tx_u16(const struct device *dev, const uint16_t *buf,
1322 size_t len, int32_t timeout);
1323
1324static inline int z_impl_uart_tx_u16(const struct device *dev,
1325 const uint16_t *buf,
1326 size_t len, int32_t timeout)
1327
1328{
1329#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1330 const struct uart_driver_api *api =
1331 (const struct uart_driver_api *)dev->api;
1332
1333 return api->tx_u16(dev, buf, len, timeout);
1334#else
1335 ARG_UNUSED(dev);
1336 ARG_UNUSED(buf);
1337 ARG_UNUSED(len);
1338 ARG_UNUSED(timeout);
1339 return -ENOTSUP;
1340#endif
1341}
1342
1355__syscall int uart_tx_abort(const struct device *dev);
1356
1357static inline int z_impl_uart_tx_abort(const struct device *dev)
1358{
1359#ifdef CONFIG_UART_ASYNC_API
1360 const struct uart_driver_api *api =
1361 (const struct uart_driver_api *)dev->api;
1362
1363 return api->tx_abort(dev);
1364#else
1365 ARG_UNUSED(dev);
1366 return -ENOTSUP;
1367#endif
1368}
1369
1391__syscall int uart_rx_enable(const struct device *dev, uint8_t *buf,
1392 size_t len,
1393 int32_t timeout);
1394
1395static inline int z_impl_uart_rx_enable(const struct device *dev,
1396 uint8_t *buf,
1397 size_t len, int32_t timeout)
1398{
1399#ifdef CONFIG_UART_ASYNC_API
1400 const struct uart_driver_api *api =
1401 (const struct uart_driver_api *)dev->api;
1402
1403 return api->rx_enable(dev, buf, len, timeout);
1404#else
1405 ARG_UNUSED(dev);
1406 ARG_UNUSED(buf);
1407 ARG_UNUSED(len);
1408 ARG_UNUSED(timeout);
1409 return -ENOTSUP;
1410#endif
1411}
1412
1434__syscall int uart_rx_enable_u16(const struct device *dev, uint16_t *buf,
1435 size_t len, int32_t timeout);
1436
1437static inline int z_impl_uart_rx_enable_u16(const struct device *dev,
1438 uint16_t *buf, size_t len,
1439 int32_t timeout)
1440{
1441#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1442 const struct uart_driver_api *api =
1443 (const struct uart_driver_api *)dev->api;
1444
1445 return api->rx_enable_u16(dev, buf, len, timeout);
1446#else
1447 ARG_UNUSED(dev);
1448 ARG_UNUSED(buf);
1449 ARG_UNUSED(len);
1450 ARG_UNUSED(timeout);
1451 return -ENOTSUP;
1452#endif
1453}
1454
1475static inline int uart_rx_buf_rsp(const struct device *dev, uint8_t *buf,
1476 size_t len)
1477{
1478#ifdef CONFIG_UART_ASYNC_API
1479 const struct uart_driver_api *api =
1480 (const struct uart_driver_api *)dev->api;
1481
1482 return api->rx_buf_rsp(dev, buf, len);
1483#else
1484 ARG_UNUSED(dev);
1485 ARG_UNUSED(buf);
1486 ARG_UNUSED(len);
1487 return -ENOTSUP;
1488#endif
1489}
1490
1512static inline int uart_rx_buf_rsp_u16(const struct device *dev, uint16_t *buf,
1513 size_t len)
1514{
1515#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1516 const struct uart_driver_api *api =
1517 (const struct uart_driver_api *)dev->api;
1518
1519 return api->rx_buf_rsp_u16(dev, buf, len);
1520#else
1521 ARG_UNUSED(dev);
1522 ARG_UNUSED(buf);
1523 ARG_UNUSED(len);
1524 return -ENOTSUP;
1525#endif
1526}
1527
1543__syscall int uart_rx_disable(const struct device *dev);
1544
1545static inline int z_impl_uart_rx_disable(const struct device *dev)
1546{
1547#ifdef CONFIG_UART_ASYNC_API
1548 const struct uart_driver_api *api =
1549 (const struct uart_driver_api *)dev->api;
1550
1551 return api->rx_disable(dev);
1552#else
1553 ARG_UNUSED(dev);
1554 return -ENOTSUP;
1555#endif
1556}
1557
1574__syscall int uart_line_ctrl_set(const struct device *dev,
1575 uint32_t ctrl, uint32_t val);
1576
1577static inline int z_impl_uart_line_ctrl_set(const struct device *dev,
1578 uint32_t ctrl, uint32_t val)
1579{
1580#ifdef CONFIG_UART_LINE_CTRL
1581 const struct uart_driver_api *api =
1582 (const struct uart_driver_api *)dev->api;
1583
1584 if (api->line_ctrl_set == NULL) {
1585 return -ENOSYS;
1586 }
1587 return api->line_ctrl_set(dev, ctrl, val);
1588#else
1589 ARG_UNUSED(dev);
1590 ARG_UNUSED(ctrl);
1591 ARG_UNUSED(val);
1592 return -ENOTSUP;
1593#endif
1594}
1595
1608__syscall int uart_line_ctrl_get(const struct device *dev, uint32_t ctrl,
1609 uint32_t *val);
1610
1611static inline int z_impl_uart_line_ctrl_get(const struct device *dev,
1612 uint32_t ctrl, uint32_t *val)
1613{
1614#ifdef CONFIG_UART_LINE_CTRL
1615 const struct uart_driver_api *api =
1616 (const struct uart_driver_api *)dev->api;
1617
1618 if (api->line_ctrl_get == NULL) {
1619 return -ENOSYS;
1620 }
1621 return api->line_ctrl_get(dev, ctrl, val);
1622#else
1623 ARG_UNUSED(dev);
1624 ARG_UNUSED(ctrl);
1625 ARG_UNUSED(val);
1626 return -ENOTSUP;
1627#endif
1628}
1629
1645__syscall int uart_drv_cmd(const struct device *dev, uint32_t cmd, uint32_t p);
1646
1647static inline int z_impl_uart_drv_cmd(const struct device *dev, uint32_t cmd,
1648 uint32_t p)
1649{
1650#ifdef CONFIG_UART_DRV_CMD
1651 const struct uart_driver_api *api =
1652 (const struct uart_driver_api *)dev->api;
1653
1654 if (api->drv_cmd == NULL) {
1655 return -ENOSYS;
1656 }
1657 return api->drv_cmd(dev, cmd, p);
1658#else
1659 ARG_UNUSED(dev);
1660 ARG_UNUSED(cmd);
1661 ARG_UNUSED(p);
1662 return -ENOTSUP;
1663#endif
1664}
1665
1666#ifdef __cplusplus
1667}
1668#endif
1669
1674#include <zephyr/syscalls/uart.h>
1675
1676#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:82
#define ENOTSUP
Unsupported value.
Definition: errno.h:114
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:1475
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:1512
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:324
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:1244
uart_event_type
Types of events passed to callback in UART_ASYNC_API.
Definition: uart.h:207
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:258
@ UART_TX_ABORTED
Transmitting aborted due to timeout or uart_tx_abort call.
Definition: uart.h:217
@ UART_RX_BUF_REQUEST
Driver requests next buffer for continuous reception.
Definition: uart.h:240
@ UART_TX_DONE
Whole TX buffer was transmitted.
Definition: uart.h:209
@ UART_RX_RDY
Received data is ready for processing.
Definition: uart.h:228
@ UART_RX_DISABLED
RX has been disabled and can be reenabled.
Definition: uart.h:252
@ UART_RX_BUF_RELEASED
Buffer is no longer used by UART driver.
Definition: uart.h:244
uart_line_ctrl
Line control signals.
Definition: uart.h:35
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:111
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:79
uart_config_data_bits
Number of data bits.
Definition: uart.h:96
uart_rx_stop_reason
Reception stop reasons.
Definition: uart.h:49
uart_config_stop_bits
Number of stop bits.
Definition: uart.h:88
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:38
@ UART_LINE_CTRL_RTS
Request To Send (RTS)
Definition: uart.h:37
@ UART_LINE_CTRL_BAUD_RATE
Baud rate.
Definition: uart.h:36
@ UART_LINE_CTRL_DCD
Data Carrier Detect (DCD)
Definition: uart.h:39
@ UART_LINE_CTRL_DSR
Data Set Ready (DSR)
Definition: uart.h:40
@ UART_CFG_FLOW_CTRL_DTR_DSR
DTR/DSR flow control.
Definition: uart.h:114
@ UART_CFG_FLOW_CTRL_NONE
No flow control.
Definition: uart.h:112
@ UART_CFG_FLOW_CTRL_RS485
RS485 flow control.
Definition: uart.h:115
@ UART_CFG_FLOW_CTRL_RTS_CTS
RTS/CTS flow control.
Definition: uart.h:113
@ UART_CFG_PARITY_MARK
Mark parity.
Definition: uart.h:83
@ UART_CFG_PARITY_NONE
No parity.
Definition: uart.h:80
@ UART_CFG_PARITY_ODD
Odd parity.
Definition: uart.h:81
@ UART_CFG_PARITY_SPACE
Space parity.
Definition: uart.h:84
@ UART_CFG_PARITY_EVEN
Even parity.
Definition: uart.h:82
@ UART_CFG_DATA_BITS_5
5 data bits
Definition: uart.h:97
@ UART_CFG_DATA_BITS_8
8 data bits
Definition: uart.h:100
@ UART_CFG_DATA_BITS_7
7 data bits
Definition: uart.h:99
@ UART_CFG_DATA_BITS_6
6 data bits
Definition: uart.h:98
@ UART_CFG_DATA_BITS_9
9 data bits
Definition: uart.h:101
@ UART_ERROR_NOISE
Noise error.
Definition: uart.h:75
@ UART_ERROR_OVERRUN
Overrun error.
Definition: uart.h:51
@ UART_BREAK
Break interrupt.
Definition: uart.h:63
@ UART_ERROR_PARITY
Parity error.
Definition: uart.h:53
@ UART_ERROR_COLLISION
Collision error.
Definition: uart.h:73
@ UART_ERROR_FRAMING
Framing error.
Definition: uart.h:55
@ UART_CFG_STOP_BITS_1_5
1.5 stop bits
Definition: uart.h:91
@ UART_CFG_STOP_BITS_0_5
0.5 stop bit
Definition: uart.h:89
@ UART_CFG_STOP_BITS_1
1 stop bit
Definition: uart.h:90
@ UART_CFG_STOP_BITS_2
2 stop bits
Definition: uart.h:92
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:841
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:922
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:1214
void(* uart_irq_config_func_t)(const struct device *dev)
For configuring IRQ on each individual UART device.
Definition: uart.h:149
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:1000
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:758
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:800
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:1036
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:141
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:1179
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:717
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:403
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:409
UART controller configuration structure.
Definition: uart.h:121
uint8_t stop_bits
Stop bits, use uart_config_stop_bits.
Definition: uart.h:124
uint8_t parity
Parity bit, use uart_config_parity.
Definition: uart.h:123
uint8_t data_bits
Data bits, use uart_config_data_bits.
Definition: uart.h:125
uint32_t baudrate
Baudrate setting in bps.
Definition: uart.h:122
uint8_t flow_ctrl
Flow control setting, use uart_config_flow_control.
Definition: uart.h:126
UART RX buffer released event data.
Definition: uart.h:285
uint8_t * buf
Pointer to buffer that is no longer in use.
Definition: uart.h:287
UART RX stopped data.
Definition: uart.h:291
struct uart_event_rx data
Last received data.
Definition: uart.h:295
enum uart_rx_stop_reason reason
Reason why receiving stopped.
Definition: uart.h:293
UART RX event data.
Definition: uart.h:275
uint8_t * buf
Pointer to current buffer.
Definition: uart.h:277
size_t len
Number of new bytes received.
Definition: uart.h:281
size_t offset
Currently received data offset in bytes.
Definition: uart.h:279
UART TX event data.
Definition: uart.h:262
const uint8_t * buf
Pointer to current buffer.
Definition: uart.h:264
size_t len
Number of bytes sent.
Definition: uart.h:266
Structure containing information about current event.
Definition: uart.h:299
union uart_event::uart_event_data data
enum uart_event_type type
Type of event.
Definition: uart.h:301
Event data.
Definition: uart.h:303
struct uart_event_tx tx
UART_TX_DONE and UART_TX_ABORTED events data.
Definition: uart.h:305
struct uart_event_rx_stop rx_stop
UART_RX_STOPPED event data.
Definition: uart.h:311
struct uart_event_rx_buf rx_buf
UART_RX_BUF_RELEASED event data.
Definition: uart.h:309
struct uart_event_rx rx
UART_RX_RDY event data.
Definition: uart.h:307