Zephyr Project API  3.3.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
260};
261
265 const uint8_t *buf;
267 size_t len;
268};
269
280 size_t offset;
282 size_t len;
283};
284
287 /* @brief Pointer to buffer that is no longer in use. */
289};
290
297};
298
314};
315
325typedef void (*uart_callback_t)(const struct device *dev,
326 struct uart_event *evt, void *user_data);
327
339__subsystem struct uart_driver_api {
340
341#ifdef CONFIG_UART_ASYNC_API
342
343 int (*callback_set)(const struct device *dev,
344 uart_callback_t callback,
345 void *user_data);
346
347 int (*tx)(const struct device *dev, const uint8_t *buf, size_t len,
349 int (*tx_abort)(const struct device *dev);
350
351 int (*rx_enable)(const struct device *dev, uint8_t *buf, size_t len,
353 int (*rx_buf_rsp)(const struct device *dev, uint8_t *buf, size_t len);
354 int (*rx_disable)(const struct device *dev);
355
356#ifdef CONFIG_UART_WIDE_DATA
357 int (*tx_u16)(const struct device *dev, const uint16_t *buf,
358 size_t len, int32_t timeout);
359 int (*rx_enable_u16)(const struct device *dev, uint16_t *buf,
360 size_t len, int32_t timeout);
361 int (*rx_buf_rsp_u16)(const struct device *dev, uint16_t *buf,
362 size_t len);
363#endif
364
365#endif
366
368 int (*poll_in)(const struct device *dev, unsigned char *p_char);
369 void (*poll_out)(const struct device *dev, unsigned char out_char);
370
371#ifdef CONFIG_UART_WIDE_DATA
372 int (*poll_in_u16)(const struct device *dev, uint16_t *p_u16);
373 void (*poll_out_u16)(const struct device *dev, uint16_t out_u16);
374#endif
375
377 int (*err_check)(const struct device *dev);
378
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
384#ifdef CONFIG_UART_INTERRUPT_DRIVEN
385
387 int (*fifo_fill)(const struct device *dev, const uint8_t *tx_data,
388 int len);
389
390#ifdef CONFIG_UART_WIDE_DATA
391 int (*fifo_fill_u16)(const struct device *dev, const uint16_t *tx_data,
392 int len);
393#endif
394
396 int (*fifo_read)(const struct device *dev, uint8_t *rx_data,
397 const int size);
398
399#ifdef CONFIG_UART_WIDE_DATA
400 int (*fifo_read_u16)(const struct device *dev, uint16_t *rx_data,
401 const int size);
402#endif
403
405 void (*irq_tx_enable)(const struct device *dev);
406
408 void (*irq_tx_disable)(const struct device *dev);
409
411 int (*irq_tx_ready)(const struct device *dev);
412
414 void (*irq_rx_enable)(const struct device *dev);
415
417 void (*irq_rx_disable)(const struct device *dev);
418
420 int (*irq_tx_complete)(const struct device *dev);
421
423 int (*irq_rx_ready)(const struct device *dev);
424
426 void (*irq_err_enable)(const struct device *dev);
427
429 void (*irq_err_disable)(const struct device *dev);
430
432 int (*irq_is_pending)(const struct device *dev);
433
435 int (*irq_update)(const struct device *dev);
436
438 void (*irq_callback_set)(const struct device *dev,
440 void *user_data);
441
442#endif
443
444#ifdef CONFIG_UART_LINE_CTRL
445 int (*line_ctrl_set)(const struct device *dev, uint32_t ctrl,
446 uint32_t val);
447 int (*line_ctrl_get)(const struct device *dev, uint32_t ctrl,
448 uint32_t *val);
449#endif
450
451#ifdef CONFIG_UART_DRV_CMD
452 int (*drv_cmd)(const struct device *dev, uint32_t cmd, uint32_t p);
453#endif
454
455};
456
468__syscall int uart_err_check(const struct device *dev);
469
470static inline int z_impl_uart_err_check(const struct device *dev)
471{
472 const struct uart_driver_api *api =
473 (const struct uart_driver_api *)dev->api;
474
475 if (api->err_check == NULL) {
476 return -ENOSYS;
477 }
478
479 return api->err_check(dev);
480}
481
505__syscall int uart_poll_in(const struct device *dev, unsigned char *p_char);
506
507static inline int z_impl_uart_poll_in(const struct device *dev,
508 unsigned char *p_char)
509{
510 const struct uart_driver_api *api =
511 (const struct uart_driver_api *)dev->api;
512
513 if (api->poll_in == NULL) {
514 return -ENOSYS;
515 }
516
517 return api->poll_in(dev, p_char);
518}
519
539__syscall int uart_poll_in_u16(const struct device *dev, uint16_t *p_u16);
540
541static inline int z_impl_uart_poll_in_u16(const struct device *dev,
542 uint16_t *p_u16)
543{
544#ifdef CONFIG_UART_WIDE_DATA
545 const struct uart_driver_api *api =
546 (const struct uart_driver_api *)dev->api;
547
548 if (api->poll_in_u16 == NULL) {
549 return -ENOSYS;
550 }
551
552 return api->poll_in_u16(dev, p_u16);
553#else
554 ARG_UNUSED(dev);
555 ARG_UNUSED(p_u16);
556 return -ENOTSUP;
557#endif
558}
559
574__syscall void uart_poll_out(const struct device *dev,
575 unsigned char out_char);
576
577static inline void z_impl_uart_poll_out(const struct device *dev,
578 unsigned char out_char)
579{
580 const struct uart_driver_api *api =
581 (const struct uart_driver_api *)dev->api;
582
583 api->poll_out(dev, out_char);
584}
585
600__syscall void uart_poll_out_u16(const struct device *dev, uint16_t out_u16);
601
602static inline void z_impl_uart_poll_out_u16(const struct device *dev,
603 uint16_t out_u16)
604{
605#ifdef CONFIG_UART_WIDE_DATA
606 const struct uart_driver_api *api =
607 (const struct uart_driver_api *)dev->api;
608
609 api->poll_out_u16(dev, out_u16);
610#else
611 ARG_UNUSED(dev);
612 ARG_UNUSED(out_u16);
613#endif
614}
615
633__syscall int uart_configure(const struct device *dev,
634 const struct uart_config *cfg);
635
636static inline int z_impl_uart_configure(const struct device *dev,
637 const struct uart_config *cfg)
638{
639 const struct uart_driver_api *api =
640 (const struct uart_driver_api *)dev->api;
641
642 if (api->configure == NULL) {
643 return -ENOSYS;
644 }
645 return api->configure(dev, cfg);
646}
647
661__syscall int uart_config_get(const struct device *dev,
662 struct uart_config *cfg);
663
664static inline int z_impl_uart_config_get(const struct device *dev,
665 struct uart_config *cfg)
666{
667 const struct uart_driver_api *api =
668 (const struct uart_driver_api *)dev->api;
669
670 if (api->config_get == NULL) {
671 return -ENOSYS;
672 }
673
674 return api->config_get(dev, cfg);
675}
676
702static inline int uart_fifo_fill(const struct device *dev,
703 const uint8_t *tx_data,
704 int size)
705{
706#ifdef CONFIG_UART_INTERRUPT_DRIVEN
707 const struct uart_driver_api *api =
708 (const struct uart_driver_api *)dev->api;
709
710 if (api->fifo_fill == NULL) {
711 return -ENOSYS;
712 }
713
714 return api->fifo_fill(dev, tx_data, size);
715#else
716 ARG_UNUSED(dev);
717 ARG_UNUSED(tx_data);
718 ARG_UNUSED(size);
719 return -ENOTSUP;
720#endif
721}
722
743static inline int uart_fifo_fill_u16(const struct device *dev,
744 const uint16_t *tx_data,
745 int size)
746{
747#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
748 const struct uart_driver_api *api =
749 (const struct uart_driver_api *)dev->api;
750
751 if (api->fifo_fill_u16 == NULL) {
752 return -ENOSYS;
753 }
754
755 return api->fifo_fill_u16(dev, tx_data, size);
756#else
757 ARG_UNUSED(dev);
758 ARG_UNUSED(tx_data);
759 ARG_UNUSED(size);
760 return -ENOTSUP;
761#endif
762}
763
788static inline int uart_fifo_read(const struct device *dev, uint8_t *rx_data,
789 const int size)
790{
791#ifdef CONFIG_UART_INTERRUPT_DRIVEN
792 const struct uart_driver_api *api =
793 (const struct uart_driver_api *)dev->api;
794
795 if (api->fifo_read == NULL) {
796 return -ENOSYS;
797 }
798
799 return api->fifo_read(dev, rx_data, size);
800#else
801 ARG_UNUSED(dev);
802 ARG_UNUSED(rx_data);
803 ARG_UNUSED(size);
804 return -ENOTSUP;
805#endif
806}
807
832static inline int uart_fifo_read_u16(const struct device *dev,
833 uint16_t *rx_data,
834 const int size)
835{
836#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
837 const struct uart_driver_api *api =
838 (const struct uart_driver_api *)dev->api;
839
840 if (api->fifo_read_u16 == NULL) {
841 return -ENOSYS;
842 }
843
844 return api->fifo_read_u16(dev, rx_data, size);
845#else
846 ARG_UNUSED(dev);
847 ARG_UNUSED(rx_data);
848 ARG_UNUSED(size);
849 return -ENOTSUP;
850#endif
851}
852
858__syscall void uart_irq_tx_enable(const struct device *dev);
859
860static inline void z_impl_uart_irq_tx_enable(const struct device *dev)
861{
862#ifdef CONFIG_UART_INTERRUPT_DRIVEN
863 const struct uart_driver_api *api =
864 (const struct uart_driver_api *)dev->api;
865
866 if (api->irq_tx_enable != NULL) {
867 api->irq_tx_enable(dev);
868 }
869#else
870 ARG_UNUSED(dev);
871#endif
872}
873
879__syscall void uart_irq_tx_disable(const struct device *dev);
880
881static inline void z_impl_uart_irq_tx_disable(const struct device *dev)
882{
883#ifdef CONFIG_UART_INTERRUPT_DRIVEN
884 const struct uart_driver_api *api =
885 (const struct uart_driver_api *)dev->api;
886
887 if (api->irq_tx_disable != NULL) {
888 api->irq_tx_disable(dev);
889 }
890#else
891 ARG_UNUSED(dev);
892#endif
893}
894
913static inline int uart_irq_tx_ready(const struct device *dev)
914{
915#ifdef CONFIG_UART_INTERRUPT_DRIVEN
916 const struct uart_driver_api *api =
917 (const struct uart_driver_api *)dev->api;
918
919 if (api->irq_tx_ready == NULL) {
920 return -ENOSYS;
921 }
922
923 return api->irq_tx_ready(dev);
924#else
925 ARG_UNUSED(dev);
926 return -ENOTSUP;
927#endif
928}
929
935__syscall void uart_irq_rx_enable(const struct device *dev);
936
937static inline void z_impl_uart_irq_rx_enable(const struct device *dev)
938{
939#ifdef CONFIG_UART_INTERRUPT_DRIVEN
940 const struct uart_driver_api *api =
941 (const struct uart_driver_api *)dev->api;
942
943 if (api->irq_rx_enable != NULL) {
944 api->irq_rx_enable(dev);
945 }
946#else
947 ARG_UNUSED(dev);
948#endif
949}
950
956__syscall void uart_irq_rx_disable(const struct device *dev);
957
958static inline void z_impl_uart_irq_rx_disable(const struct device *dev)
959{
960#ifdef CONFIG_UART_INTERRUPT_DRIVEN
961 const struct uart_driver_api *api =
962 (const struct uart_driver_api *)dev->api;
963
964 if (api->irq_rx_disable != NULL) {
965 api->irq_rx_disable(dev);
966 }
967#else
968 ARG_UNUSED(dev);
969#endif
970}
971
991static inline int uart_irq_tx_complete(const struct device *dev)
992{
993#ifdef CONFIG_UART_INTERRUPT_DRIVEN
994 const struct uart_driver_api *api =
995 (const struct uart_driver_api *)dev->api;
996
997 if (api->irq_tx_complete == NULL) {
998 return -ENOSYS;
999 }
1000 return api->irq_tx_complete(dev);
1001#else
1002 ARG_UNUSED(dev);
1003 return -ENOTSUP;
1004#endif
1005}
1006
1027static inline int uart_irq_rx_ready(const struct device *dev)
1028{
1029#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1030 const struct uart_driver_api *api =
1031 (const struct uart_driver_api *)dev->api;
1032
1033 if (api->irq_rx_ready == NULL) {
1034 return -ENOSYS;
1035 }
1036 return api->irq_rx_ready(dev);
1037#else
1038 ARG_UNUSED(dev);
1039 return -ENOTSUP;
1040#endif
1041}
1047__syscall void uart_irq_err_enable(const struct device *dev);
1048
1049static inline void z_impl_uart_irq_err_enable(const struct device *dev)
1050{
1051#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1052 const struct uart_driver_api *api =
1053 (const struct uart_driver_api *)dev->api;
1054
1055 if (api->irq_err_enable) {
1056 api->irq_err_enable(dev);
1057 }
1058#else
1059 ARG_UNUSED(dev);
1060#endif
1061}
1062
1068__syscall void uart_irq_err_disable(const struct device *dev);
1069
1070static inline void z_impl_uart_irq_err_disable(const struct device *dev)
1071{
1072#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1073 const struct uart_driver_api *api =
1074 (const struct uart_driver_api *)dev->api;
1075
1076 if (api->irq_err_disable) {
1077 api->irq_err_disable(dev);
1078 }
1079#else
1080 ARG_UNUSED(dev);
1081#endif
1082}
1083
1094__syscall int uart_irq_is_pending(const struct device *dev);
1095
1096static inline int z_impl_uart_irq_is_pending(const struct device *dev)
1097{
1098#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1099 const struct uart_driver_api *api =
1100 (const struct uart_driver_api *)dev->api;
1101
1102 if (api->irq_is_pending == NULL) {
1103 return -ENOSYS;
1104 }
1105 return api->irq_is_pending(dev);
1106#else
1107 ARG_UNUSED(dev);
1108 return -ENOTSUP;
1109#endif
1110}
1111
1137__syscall int uart_irq_update(const struct device *dev);
1138
1139static inline int z_impl_uart_irq_update(const struct device *dev)
1140{
1141#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1142 const struct uart_driver_api *api =
1143 (const struct uart_driver_api *)dev->api;
1144
1145 if (api->irq_update == NULL) {
1146 return -ENOSYS;
1147 }
1148 return api->irq_update(dev);
1149#else
1150 ARG_UNUSED(dev);
1151 return -ENOTSUP;
1152#endif
1153}
1154
1170static inline int uart_irq_callback_user_data_set(const struct device *dev,
1172 void *user_data)
1173{
1174#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1175 const struct uart_driver_api *api =
1176 (const struct uart_driver_api *)dev->api;
1177
1178 if ((api != NULL) && (api->irq_callback_set != NULL)) {
1179 api->irq_callback_set(dev, cb, user_data);
1180 return 0;
1181 } else {
1182 return -ENOSYS;
1183 }
1184#else
1185 ARG_UNUSED(dev);
1186 ARG_UNUSED(cb);
1187 ARG_UNUSED(user_data);
1188 return -ENOTSUP;
1189#endif
1190}
1191
1205static inline int uart_irq_callback_set(const struct device *dev,
1207{
1208 return uart_irq_callback_user_data_set(dev, cb, NULL);
1209}
1210
1235static inline int uart_callback_set(const struct device *dev,
1236 uart_callback_t callback,
1237 void *user_data)
1238{
1239#ifdef CONFIG_UART_ASYNC_API
1240 const struct uart_driver_api *api =
1241 (const struct uart_driver_api *)dev->api;
1242
1243 if (api->callback_set == NULL) {
1244 return -ENOSYS;
1245 }
1246
1247 return api->callback_set(dev, callback, user_data);
1248#else
1249 ARG_UNUSED(dev);
1250 ARG_UNUSED(callback);
1251 ARG_UNUSED(user_data);
1252 return -ENOTSUP;
1253#endif
1254}
1255
1273__syscall int uart_tx(const struct device *dev, const uint8_t *buf,
1274 size_t len,
1276
1277static inline int z_impl_uart_tx(const struct device *dev, const uint8_t *buf,
1278 size_t len, int32_t timeout)
1279
1280{
1281#ifdef CONFIG_UART_ASYNC_API
1282 const struct uart_driver_api *api =
1283 (const struct uart_driver_api *)dev->api;
1284
1285 return api->tx(dev, buf, len, timeout);
1286#else
1287 ARG_UNUSED(dev);
1288 ARG_UNUSED(buf);
1289 ARG_UNUSED(len);
1290 ARG_UNUSED(timeout);
1291 return -ENOTSUP;
1292#endif
1293}
1294
1312__syscall int uart_tx_u16(const struct device *dev, const uint16_t *buf,
1313 size_t len, int32_t timeout);
1314
1315static inline int z_impl_uart_tx_u16(const struct device *dev,
1316 const uint16_t *buf,
1317 size_t len, int32_t timeout)
1318
1319{
1320#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1321 const struct uart_driver_api *api =
1322 (const struct uart_driver_api *)dev->api;
1323
1324 return api->tx_u16(dev, buf, len, timeout);
1325#else
1326 ARG_UNUSED(dev);
1327 ARG_UNUSED(buf);
1328 ARG_UNUSED(len);
1329 ARG_UNUSED(timeout);
1330 return -ENOTSUP;
1331#endif
1332}
1333
1346__syscall int uart_tx_abort(const struct device *dev);
1347
1348static inline int z_impl_uart_tx_abort(const struct device *dev)
1349{
1350#ifdef CONFIG_UART_ASYNC_API
1351 const struct uart_driver_api *api =
1352 (const struct uart_driver_api *)dev->api;
1353
1354 return api->tx_abort(dev);
1355#else
1356 ARG_UNUSED(dev);
1357 return -ENOTSUP;
1358#endif
1359}
1360
1382__syscall int uart_rx_enable(const struct device *dev, uint8_t *buf,
1383 size_t len,
1385
1386static inline int z_impl_uart_rx_enable(const struct device *dev,
1387 uint8_t *buf,
1388 size_t len, int32_t timeout)
1389{
1390#ifdef CONFIG_UART_ASYNC_API
1391 const struct uart_driver_api *api =
1392 (const struct uart_driver_api *)dev->api;
1393
1394 return api->rx_enable(dev, buf, len, timeout);
1395#else
1396 ARG_UNUSED(dev);
1397 ARG_UNUSED(buf);
1398 ARG_UNUSED(len);
1399 ARG_UNUSED(timeout);
1400 return -ENOTSUP;
1401#endif
1402}
1403
1425__syscall int uart_rx_enable_u16(const struct device *dev, uint16_t *buf,
1426 size_t len, int32_t timeout);
1427
1428static inline int z_impl_uart_rx_enable_u16(const struct device *dev,
1429 uint16_t *buf, size_t len,
1431{
1432#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1433 const struct uart_driver_api *api =
1434 (const struct uart_driver_api *)dev->api;
1435
1436 return api->rx_enable_u16(dev, buf, len, timeout);
1437#else
1438 ARG_UNUSED(dev);
1439 ARG_UNUSED(buf);
1440 ARG_UNUSED(len);
1441 ARG_UNUSED(timeout);
1442 return -ENOTSUP;
1443#endif
1444}
1445
1466static inline int uart_rx_buf_rsp(const struct device *dev, uint8_t *buf,
1467 size_t len)
1468{
1469#ifdef CONFIG_UART_ASYNC_API
1470 const struct uart_driver_api *api =
1471 (const struct uart_driver_api *)dev->api;
1472
1473 return api->rx_buf_rsp(dev, buf, len);
1474#else
1475 ARG_UNUSED(dev);
1476 ARG_UNUSED(buf);
1477 ARG_UNUSED(len);
1478 return -ENOTSUP;
1479#endif
1480}
1481
1503static inline int uart_rx_buf_rsp_u16(const struct device *dev, uint16_t *buf,
1504 size_t len)
1505{
1506#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1507 const struct uart_driver_api *api =
1508 (const struct uart_driver_api *)dev->api;
1509
1510 return api->rx_buf_rsp_u16(dev, buf, len);
1511#else
1512 ARG_UNUSED(dev);
1513 ARG_UNUSED(buf);
1514 ARG_UNUSED(len);
1515 return -ENOTSUP;
1516#endif
1517}
1518
1534__syscall int uart_rx_disable(const struct device *dev);
1535
1536static inline int z_impl_uart_rx_disable(const struct device *dev)
1537{
1538#ifdef CONFIG_UART_ASYNC_API
1539 const struct uart_driver_api *api =
1540 (const struct uart_driver_api *)dev->api;
1541
1542 return api->rx_disable(dev);
1543#else
1544 ARG_UNUSED(dev);
1545 return -ENOTSUP;
1546#endif
1547}
1548
1565__syscall int uart_line_ctrl_set(const struct device *dev,
1566 uint32_t ctrl, uint32_t val);
1567
1568static inline int z_impl_uart_line_ctrl_set(const struct device *dev,
1569 uint32_t ctrl, uint32_t val)
1570{
1571#ifdef CONFIG_UART_LINE_CTRL
1572 const struct uart_driver_api *api =
1573 (const struct uart_driver_api *)dev->api;
1574
1575 if (api->line_ctrl_set == NULL) {
1576 return -ENOSYS;
1577 }
1578 return api->line_ctrl_set(dev, ctrl, val);
1579#else
1580 ARG_UNUSED(dev);
1581 ARG_UNUSED(ctrl);
1582 ARG_UNUSED(val);
1583 return -ENOTSUP;
1584#endif
1585}
1586
1599__syscall int uart_line_ctrl_get(const struct device *dev, uint32_t ctrl,
1600 uint32_t *val);
1601
1602static inline int z_impl_uart_line_ctrl_get(const struct device *dev,
1603 uint32_t ctrl, uint32_t *val)
1604{
1605#ifdef CONFIG_UART_LINE_CTRL
1606 const struct uart_driver_api *api =
1607 (const struct uart_driver_api *)dev->api;
1608
1609 if (api->line_ctrl_get == NULL) {
1610 return -ENOSYS;
1611 }
1612 return api->line_ctrl_get(dev, ctrl, val);
1613#else
1614 ARG_UNUSED(dev);
1615 ARG_UNUSED(ctrl);
1616 ARG_UNUSED(val);
1617 return -ENOTSUP;
1618#endif
1619}
1620
1636__syscall int uart_drv_cmd(const struct device *dev, uint32_t cmd, uint32_t p);
1637
1638static inline int z_impl_uart_drv_cmd(const struct device *dev, uint32_t cmd,
1639 uint32_t p)
1640{
1641#ifdef CONFIG_UART_DRV_CMD
1642 const struct uart_driver_api *api =
1643 (const struct uart_driver_api *)dev->api;
1644
1645 if (api->drv_cmd == NULL) {
1646 return -ENOSYS;
1647 }
1648 return api->drv_cmd(dev, cmd, p);
1649#else
1650 ARG_UNUSED(dev);
1651 ARG_UNUSED(cmd);
1652 ARG_UNUSED(p);
1653 return -ENOTSUP;
1654#endif
1655}
1656
1657#ifdef __cplusplus
1658}
1659#endif
1660
1665#include <syscalls/uart.h>
1666
1667#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:1466
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:1503
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:325
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:1235
uart_event_type
Types of events passed to callback in UART_ASYNC_API.
Definition: uart.h:208
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:259
@ UART_TX_ABORTED
Transmitting aborted due to timeout or uart_tx_abort call.
Definition: uart.h:218
@ UART_RX_BUF_REQUEST
Driver requests next buffer for continuous reception.
Definition: uart.h:241
@ UART_TX_DONE
Whole TX buffer was transmitted.
Definition: uart.h:210
@ UART_RX_RDY
Received data is ready for processing.
Definition: uart.h:229
@ UART_RX_DISABLED
RX has been disabled and can be reenabled.
Definition: uart.h:253
@ UART_RX_BUF_RELEASED
Buffer is no longer used by UART driver.
Definition: uart.h:245
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:832
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:913
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:1205
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:991
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:743
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:788
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:1027
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:1170
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:702
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:378
const void * api
Definition: device.h:384
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:286
uint8_t * buf
Definition: uart.h:288
UART RX stopped data.
Definition: uart.h:292
struct uart_event_rx data
Last received data.
Definition: uart.h:296
enum uart_rx_stop_reason reason
Reason why receiving stopped.
Definition: uart.h:294
UART RX event data.
Definition: uart.h:276
uint8_t * buf
Pointer to current buffer.
Definition: uart.h:278
size_t len
Number of new bytes received.
Definition: uart.h:282
size_t offset
Currently received data offset in bytes.
Definition: uart.h:280
UART TX event data.
Definition: uart.h:263
const uint8_t * buf
Pointer to current buffer.
Definition: uart.h:265
size_t len
Number of bytes sent.
Definition: uart.h:267
Structure containing information about current event.
Definition: uart.h:300
union uart_event::uart_event_data data
enum uart_event_type type
Type of event.
Definition: uart.h:302
static const intptr_t user_data[5]
Definition: main.c:588
Event data.
Definition: uart.h:304
struct uart_event_tx tx
UART_TX_DONE and UART_TX_ABORTED events data.
Definition: uart.h:306
struct uart_event_rx_stop rx_stop
UART_RX_STOPPED event data.
Definition: uart.h:312
struct uart_event_rx_buf rx_buf
UART_RX_BUF_RELEASED event data.
Definition: uart.h:310
struct uart_event_rx rx
UART_RX_RDY event data.
Definition: uart.h:308