From d1b27186875f38a1bba225833795c6135eff1158 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 25 Jun 2019 15:54:01 -0400 Subject: [PATCH] cleanup: include/: move uart.h to drivers/uart.h move uart.h to drivers/uart.h and create a shim for backward-compatibility. No functional changes to the headers. A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES. Related to #16539 Signed-off-by: Anas Nashif --- boards/arm/nrf9160_pca10090/nrf52840_reset.c | 2 +- boards/x86/arduino_101/nrf51_pm.c | 2 +- boards/x86/quark_se_c1000_devboard/board.c | 2 +- drivers/bluetooth/hci/h4.c | 2 +- drivers/bluetooth/hci/h5.c | 2 +- drivers/console/uart_console.c | 2 +- drivers/console/uart_mcumgr.c | 2 +- drivers/console/uart_pipe.c | 2 +- drivers/modem/modem_receiver.c | 2 +- drivers/sensor/pms7003/pms7003.c | 2 +- drivers/serial/leuart_gecko.c | 2 +- drivers/serial/uart_altera_jtag_hal.c | 2 +- drivers/serial/uart_cc13xx_cc26xx.c | 2 +- drivers/serial/uart_cc32xx.c | 2 +- drivers/serial/uart_cmsdk_apb.c | 2 +- drivers/serial/uart_esp32.c | 2 +- drivers/serial/uart_gecko.c | 2 +- drivers/serial/uart_handlers.c | 2 +- drivers/serial/uart_imx.c | 2 +- drivers/serial/uart_liteuart.c | 2 +- drivers/serial/uart_mcux.c | 2 +- drivers/serial/uart_mcux_lpsci.c | 2 +- drivers/serial/uart_mcux_lpuart.c | 2 +- drivers/serial/uart_miv.c | 2 +- drivers/serial/uart_msp432p4xx.c | 2 +- drivers/serial/uart_native_posix.c | 2 +- drivers/serial/uart_nrfx_uart.c | 2 +- drivers/serial/uart_nrfx_uarte.c | 2 +- drivers/serial/uart_ns16550.c | 2 +- drivers/serial/uart_nsim.c | 2 +- drivers/serial/uart_pl011.c | 2 +- drivers/serial/uart_psoc6.c | 2 +- drivers/serial/uart_qmsi.c | 2 +- drivers/serial/uart_rv32m1_lpuart.c | 2 +- drivers/serial/uart_sam.c | 2 +- drivers/serial/uart_sam0.c | 2 +- drivers/serial/uart_sifive.c | 2 +- drivers/serial/uart_stellaris.c | 2 +- drivers/serial/uart_stm32.c | 2 +- drivers/serial/usart_mcux_lpc.c | 2 +- drivers/serial/usart_sam.c | 2 +- include/drivers/uart.h | 1162 +++++++++++++++++ include/uart.h | 1155 +--------------- samples/bluetooth/hci_uart/src/main.c | 2 +- samples/net/wpan_serial/src/main.c | 2 +- samples/nfc/nfc_hello/src/main.c | 2 +- samples/subsys/usb/cdc_acm/src/main.c | 2 +- .../subsys/usb/cdc_acm_composite/src/main.c | 2 +- samples/subsys/usb/hid-cdc/src/main.c | 2 +- soc/arm/nxp_kinetis/k6x/soc.c | 2 +- soc/arm/nxp_kinetis/kwx/soc_kw2xd.c | 2 +- soc/arm/nxp_kinetis/kwx/soc_kw4xz.c | 2 +- soc/arm/nxp_lpc/lpc54xxx/soc.c | 2 +- soc/arm/nxp_lpc/lpc55xxx/soc.c | 2 +- soc/arm/ti_lm3s6965/soc_config.c | 2 +- soc/x86/apollo_lake/soc.c | 2 +- soc/x86/atom/soc.c | 2 +- soc/x86/ia32/soc.c | 2 +- soc/x86/intel_quark/quark_se/soc.c | 2 +- soc/x86/intel_quark/quark_se/soc.h | 2 +- soc/x86/intel_quark/quark_x1000/soc.c | 2 +- subsys/bluetooth/host/monitor.c | 2 +- subsys/console/getline.c | 2 +- subsys/console/tty.c | 2 +- subsys/logging/log_backend_uart.c | 2 +- subsys/shell/shell_uart.c | 2 +- subsys/usb/class/cdc_acm.c | 2 +- .../application_development/cpp/src/main.cpp | 2 +- .../uart/uart_async_api/src/test_uart.h | 2 +- .../uart/uart_basic_api/src/test_uart.h | 2 +- 70 files changed, 1234 insertions(+), 1219 deletions(-) create mode 100644 include/drivers/uart.h diff --git a/boards/arm/nrf9160_pca10090/nrf52840_reset.c b/boards/arm/nrf9160_pca10090/nrf52840_reset.c index 099c703d11..dd7ded9f0e 100644 --- a/boards/arm/nrf9160_pca10090/nrf52840_reset.c +++ b/boards/arm/nrf9160_pca10090/nrf52840_reset.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #define RESET_PIN CONFIG_BOARD_NRF52840_GPIO_RESET_PIN diff --git a/boards/x86/arduino_101/nrf51_pm.c b/boards/x86/arduino_101/nrf51_pm.c index d03a5c9c5f..9e0b1ee6bc 100644 --- a/boards/x86/arduino_101/nrf51_pm.c +++ b/boards/x86/arduino_101/nrf51_pm.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include diff --git a/boards/x86/quark_se_c1000_devboard/board.c b/boards/x86/quark_se_c1000_devboard/board.c index dd0cac8708..0bc370f5f8 100644 --- a/boards/x86/quark_se_c1000_devboard/board.c +++ b/boards/x86/quark_se_c1000_devboard/board.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include diff --git a/drivers/bluetooth/hci/h4.c b/drivers/bluetooth/hci/h4.c index 39d923818a..95ceac8fd3 100644 --- a/drivers/bluetooth/hci/h4.c +++ b/drivers/bluetooth/hci/h4.c @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/bluetooth/hci/h5.c b/drivers/bluetooth/hci/h5.c index 34ee0b19b2..7ab9feaeee 100644 --- a/drivers/bluetooth/hci/h5.c +++ b/drivers/bluetooth/hci/h5.c @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/console/uart_console.c b/drivers/console/uart_console.c index e0f6245828..35c37ba7e9 100644 --- a/drivers/console/uart_console.c +++ b/drivers/console/uart_console.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/console/uart_mcumgr.c b/drivers/console/uart_mcumgr.c index dd53861d9f..aa0cd5441e 100644 --- a/drivers/console/uart_mcumgr.c +++ b/drivers/console/uart_mcumgr.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/console/uart_pipe.c b/drivers/console/uart_pipe.c index cf7b1eb658..cdd9051414 100644 --- a/drivers/console/uart_pipe.c +++ b/drivers/console/uart_pipe.c @@ -16,7 +16,7 @@ LOG_MODULE_REGISTER(uart_pipe, CONFIG_UART_CONSOLE_LOG_LEVEL); #include -#include +#include #include #include diff --git a/drivers/modem/modem_receiver.c b/drivers/modem/modem_receiver.c index 181ad82cdd..1a26cb696e 100644 --- a/drivers/modem/modem_receiver.c +++ b/drivers/modem/modem_receiver.c @@ -13,7 +13,7 @@ #include #include -#include +#include #include diff --git a/drivers/sensor/pms7003/pms7003.c b/drivers/sensor/pms7003/pms7003.c index 0ede96070d..1e223c866a 100644 --- a/drivers/sensor/pms7003/pms7003.c +++ b/drivers/sensor/pms7003/pms7003.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL diff --git a/drivers/serial/leuart_gecko.c b/drivers/serial/leuart_gecko.c index 0eecb09bbb..3f5f464471 100644 --- a/drivers/serial/leuart_gecko.c +++ b/drivers/serial/leuart_gecko.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/drivers/serial/uart_altera_jtag_hal.c b/drivers/serial/uart_altera_jtag_hal.c index 03936f5e09..bb4bdc7e78 100644 --- a/drivers/serial/uart_altera_jtag_hal.c +++ b/drivers/serial/uart_altera_jtag_hal.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include "altera_avalon_jtag_uart.h" diff --git a/drivers/serial/uart_cc13xx_cc26xx.c b/drivers/serial/uart_cc13xx_cc26xx.c index 909f44557a..d847a452ab 100644 --- a/drivers/serial/uart_cc13xx_cc26xx.c +++ b/drivers/serial/uart_cc13xx_cc26xx.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/serial/uart_cc32xx.c b/drivers/serial/uart_cc32xx.c index 54a6cf342e..1e0d4fe92f 100644 --- a/drivers/serial/uart_cc32xx.c +++ b/drivers/serial/uart_cc32xx.c @@ -6,7 +6,7 @@ #include #include -#include +#include /* Driverlib includes */ #include diff --git a/drivers/serial/uart_cmsdk_apb.c b/drivers/serial/uart_cmsdk_apb.c index 1107c898ce..c279efb7ec 100644 --- a/drivers/serial/uart_cmsdk_apb.c +++ b/drivers/serial/uart_cmsdk_apb.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include /* UART registers struct */ diff --git a/drivers/serial/uart_esp32.c b/drivers/serial/uart_esp32.c index 7a34c4fd8b..c34048f235 100644 --- a/drivers/serial/uart_esp32.c +++ b/drivers/serial/uart_esp32.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include static void esp32_uart_tx(struct device *dev, diff --git a/drivers/serial/uart_gecko.c b/drivers/serial/uart_gecko.c index aa3f8b1f91..2552a3e205 100644 --- a/drivers/serial/uart_gecko.c +++ b/drivers/serial/uart_gecko.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/drivers/serial/uart_handlers.c b/drivers/serial/uart_handlers.c index 1b80d5c6d1..075876b930 100644 --- a/drivers/serial/uart_handlers.c +++ b/drivers/serial/uart_handlers.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #define UART_SIMPLE(op_) \ diff --git a/drivers/serial/uart_imx.c b/drivers/serial/uart_imx.c index 523196fad0..577ba2a23d 100644 --- a/drivers/serial/uart_imx.c +++ b/drivers/serial/uart_imx.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #define DEV_CFG(dev) \ diff --git a/drivers/serial/uart_liteuart.c b/drivers/serial/uart_liteuart.c index 035c294225..45ea782c78 100644 --- a/drivers/serial/uart_liteuart.c +++ b/drivers/serial/uart_liteuart.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #define UART_EV_TX (1 << 0) diff --git a/drivers/serial/uart_mcux.c b/drivers/serial/uart_mcux.c index ddb4dc882a..4be055b73e 100644 --- a/drivers/serial/uart_mcux.c +++ b/drivers/serial/uart_mcux.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/serial/uart_mcux_lpsci.c b/drivers/serial/uart_mcux_lpsci.c index c7f450b5c3..f3c79f53df 100644 --- a/drivers/serial/uart_mcux_lpsci.c +++ b/drivers/serial/uart_mcux_lpsci.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/serial/uart_mcux_lpuart.c b/drivers/serial/uart_mcux_lpuart.c index c00cc1dbf9..900233bcbc 100644 --- a/drivers/serial/uart_mcux_lpuart.c +++ b/drivers/serial/uart_mcux_lpuart.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/serial/uart_miv.c b/drivers/serial/uart_miv.c index cc09204ddd..9cf323f0cd 100644 --- a/drivers/serial/uart_miv.c +++ b/drivers/serial/uart_miv.c @@ -6,7 +6,7 @@ #include #include -#include +#include /* UART REGISTERS DEFINITIONS */ diff --git a/drivers/serial/uart_msp432p4xx.c b/drivers/serial/uart_msp432p4xx.c index 1b19b9138c..daa3a12a8f 100644 --- a/drivers/serial/uart_msp432p4xx.c +++ b/drivers/serial/uart_msp432p4xx.c @@ -10,7 +10,7 @@ * that the definition of BIT is not overridden */ #include -#include +#include /* Driverlib includes */ #include diff --git a/drivers/serial/uart_native_posix.c b/drivers/serial/uart_native_posix.c index 351d7b7831..5d4eed73aa 100644 --- a/drivers/serial/uart_native_posix.c +++ b/drivers/serial/uart_native_posix.c @@ -14,7 +14,7 @@ #include #include -#include "uart.h" +#include #include "cmdline.h" /* native_posix command line options header */ #include "soc.h" diff --git a/drivers/serial/uart_nrfx_uart.c b/drivers/serial/uart_nrfx_uart.c index 13f1304905..ec1f7b1db7 100644 --- a/drivers/serial/uart_nrfx_uart.c +++ b/drivers/serial/uart_nrfx_uart.c @@ -8,7 +8,7 @@ * @brief Driver for Nordic Semiconductor nRF5X UART */ -#include +#include #include #include diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index 34ae19dfed..5f993c5e46 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -8,7 +8,7 @@ * @brief Driver for Nordic Semiconductor nRF UARTE */ -#include +#include #include #include #include diff --git a/drivers/serial/uart_ns16550.c b/drivers/serial/uart_ns16550.c index 41c64f8091..575c3399fd 100644 --- a/drivers/serial/uart_ns16550.c +++ b/drivers/serial/uart_ns16550.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include "uart_ns16550.h" diff --git a/drivers/serial/uart_nsim.c b/drivers/serial/uart_nsim.c index 24e40fa4e7..593cafa6fc 100644 --- a/drivers/serial/uart_nsim.c +++ b/drivers/serial/uart_nsim.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include /* * for nsimdrv, "nsim_mem-dev=uart0,base=0xf0000000,irq=24" is diff --git a/drivers/serial/uart_pl011.c b/drivers/serial/uart_pl011.c index 744d0f7ced..1ead87637c 100644 --- a/drivers/serial/uart_pl011.c +++ b/drivers/serial/uart_pl011.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include diff --git a/drivers/serial/uart_psoc6.c b/drivers/serial/uart_psoc6.c index 515655ed8d..05ba75a823 100644 --- a/drivers/serial/uart_psoc6.c +++ b/drivers/serial/uart_psoc6.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include "cy_syslib.h" #include "cy_sysclk.h" diff --git a/drivers/serial/uart_qmsi.c b/drivers/serial/uart_qmsi.c index 7dcb8154df..34e9caf466 100644 --- a/drivers/serial/uart_qmsi.c +++ b/drivers/serial/uart_qmsi.c @@ -9,7 +9,7 @@ #if defined(CONFIG_IOAPIC) #include #endif -#include +#include #include #include "qm_uart.h" diff --git a/drivers/serial/uart_rv32m1_lpuart.c b/drivers/serial/uart_rv32m1_lpuart.c index a4a6b94391..e4a10f552b 100644 --- a/drivers/serial/uart_rv32m1_lpuart.c +++ b/drivers/serial/uart_rv32m1_lpuart.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/serial/uart_sam.c b/drivers/serial/uart_sam.c index 0cb80a1380..2f983ba336 100644 --- a/drivers/serial/uart_sam.c +++ b/drivers/serial/uart_sam.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include /* * Verify Kconfig configuration diff --git a/drivers/serial/uart_sam0.c b/drivers/serial/uart_sam0.c index 1292636410..4653c5eea2 100644 --- a/drivers/serial/uart_sam0.c +++ b/drivers/serial/uart_sam0.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include /* Device constant configuration parameters */ diff --git a/drivers/serial/uart_sifive.c b/drivers/serial/uart_sifive.c index 3c6279ad46..8627171eba 100644 --- a/drivers/serial/uart_sifive.c +++ b/drivers/serial/uart_sifive.c @@ -10,7 +10,7 @@ #include #include -#include +#include #define RXDATA_EMPTY (1 << 31) /* Receive FIFO Empty */ #define RXDATA_MASK 0xFF /* Receive Data Mask */ diff --git a/drivers/serial/uart_stellaris.c b/drivers/serial/uart_stellaris.c index a2f8e92fba..1cecdd37a4 100644 --- a/drivers/serial/uart_stellaris.c +++ b/drivers/serial/uart_stellaris.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include /* definitions */ diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c index f1e5bcbf5a..41e5f77955 100644 --- a/drivers/serial/uart_stm32.c +++ b/drivers/serial/uart_stm32.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/serial/usart_mcux_lpc.c b/drivers/serial/usart_mcux_lpc.c index da346a7f05..c95bdaebbf 100644 --- a/drivers/serial/usart_mcux_lpc.c +++ b/drivers/serial/usart_mcux_lpc.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/serial/usart_sam.c b/drivers/serial/usart_sam.c index 1c52236793..6f0a85f0df 100644 --- a/drivers/serial/usart_sam.c +++ b/drivers/serial/usart_sam.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include /* * Verify Kconfig configuration diff --git a/include/drivers/uart.h b/include/drivers/uart.h new file mode 100644 index 0000000000..5edcdb71af --- /dev/null +++ b/include/drivers/uart.h @@ -0,0 +1,1162 @@ +/* + * Copyright (c) 2018-2019 Nordic Semiconductor ASA + * Copyright (c) 2015 Wind River Systems, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Public APIs for UART drivers + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_UART_H_ +#define ZEPHYR_INCLUDE_DRIVERS_UART_H_ + +/** + * @brief UART Interface + * @defgroup uart_interface UART Interface + * @ingroup io_interfaces + * @{ + */ + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief Line control signals. */ +enum uart_line_ctrl { + UART_LINE_CTRL_RTS = BIT(1), + UART_LINE_CTRL_DTR = BIT(2), + UART_LINE_CTRL_DCD = BIT(3), + UART_LINE_CTRL_DSR = BIT(4), +}; + +/** + * @brief Types of events passed to callback in UART_ASYNC_API + * + * Receiving: + * 1. To start receiving, uart_rx_enable has to be called with first buffer + * 2. When receiving starts to current buffer, UART_RX_BUF_REQUEST will be + * generated, in response to that user can either: + * + * - Provide second buffer using uart_rx_buf_rsp, when first buffer is + * filled, receiving will automatically start to second buffer. + * - Ignore the event, this way when current buffer is filled UART_RX_DONE + * event will be generated and receiving will be stopped. + * + * 3. If some data was received and timeout occurred UART_RX_RDY event will be + * generated. It can happen multiples times for the same buffer. RX timeout + * is counted from last byte received i.e. if no data was received, there + * won't be any timeout event. + * 4. After buffer is filled UART_RX_RDY will be generated, immediately + * followed by UART_RX_BUF_RELEASED indicating that current buffer is no + * longer used. + * 5. If there was second buffer provided, it will become current buffer and + * we start again at point 2. + * If no second buffer was specified receiving is stopped and + * UART_RX_DISABLED event is generated. After that whole process can be + * repeated. + * + * Any time during reception UART_RX_STOPPED event can occur. It will be + * followed by UART_RX_BUF_RELEASED event for every buffer currently passed to + * driver and finally by UART_RX_DISABLED event. + * + * Receiving can be disabled using uart_rx_disable, after calling that + * function any data received will be lost, UART_RX_BUF_RELEASED event will be + * generated for every buffer currently passed to driver and UART_RX_DISABLED + * event will occur. + * + * Transmitting: + * 1. Transmitting starts by uart_tx function. + * 2. If whole buffer was transmitted UART_TX_DONE is generated. + * If timeout occurred UART_TX_ABORTED will be generated. + * + * Transmitting can be aborted using uart_tx_abort, after calling that + * function UART_TX_ABORTED event will be generated. + * + */ +enum uart_event_type { + /** @brief Whole TX buffer was transmitted. */ + UART_TX_DONE, + /** + * @brief Transmitting aborted due to timeout or uart_tx_abort call + * + * When flow control is enabled, there is a possibility that TX transfer + * won't finish in the allotted time. Some data may have been + * transferred, information about it can be found in event data. + */ + UART_TX_ABORTED, + /** + * @brief Received data is ready for processing. + * + * This event is generated in two cases: + * - When RX timeout occurred, and data was stored in provided buffer. + * This can happen multiple times in the same buffer. + * - When provided buffer is full. + */ + UART_RX_RDY, + /** + * @brief Driver requests next buffer for continuous reception. + * + * This event is triggered when receiving has started for a new buffer, + * i.e. it's time to provide a next buffer for a seamless switchover to + * it. For continuous reliable receiving, user should provide another RX + * buffer in response to this event, using uart_rx_buf_rsp function + * + * If uart_rx_buf_rsp is not called before current buffer + * is filled up, receiving will stop. + */ + UART_RX_BUF_REQUEST, + /** + * @brief Buffer is no longer used by UART driver. + */ + UART_RX_BUF_RELEASED, + /** + * @brief RX has been disabled and can be reenabled. + * + * This event is generated whenever receiver has been stopped, disabled + * or finished its operation and can be enabled again using + * uart_rx_enable + */ + UART_RX_DISABLED, + /** + * @brief RX has stopped due to external event. + * + * Reason is one of uart_rx_stop_reason. + */ + UART_RX_STOPPED, +}; + + +/** + * @brief Reception stop reasons. + * + * Values that correspond to events or errors responsible for stopping + * receiving. + */ +enum uart_rx_stop_reason { + /** @brief Overrun error */ + UART_ERROR_OVERRUN = (1 << 0), + /** @brief Parity error */ + UART_ERROR_PARITY = (1 << 1), + /** @brief Framing error */ + UART_ERROR_FRAMING = (1 << 2), + /** + * @brief Break interrupt + * + * A break interrupt was received. This happens when the serial input + * is held at a logic '0' state for longer than the sum of + * start time + data bits + parity + stop bits. + */ + UART_BREAK = (1 << 3), +}; + +/** @brief Backward compatibility defines, deprecated */ +#define UART_ERROR_BREAK UART_BREAK +#define LINE_CTRL_BAUD_RATE (1 << 0) +#define LINE_CTRL_RTS UART_LINE_CTRL_RTS +#define LINE_CTRL_DTR UART_LINE_CTRL_DTR +#define LINE_CTRL_DCD UART_LINE_CTRL_DCD +#define LINE_CTRL_DSR UART_LINE_CTRL_DSR + + +/** @brief UART TX event data. */ +struct uart_event_tx { + /** @brief Pointer to current buffer. */ + const u8_t *buf; + /** @brief Number of bytes sent. */ + size_t len; +}; + +/** + * @brief UART RX event data. + * + * The data represented by the event is stored in rx.buf[rx.offset] to + * rx.buf[rx.offset+rx.len]. That is, the length is relative to the offset. + */ +struct uart_event_rx { + /** @brief Pointer to current buffer. */ + u8_t *buf; + /** @brief Currently received data offset in bytes. */ + size_t offset; + /** @brief Number of new bytes received. */ + size_t len; +}; + +/** @brief UART RX buffer released event data. */ +struct uart_event_rx_buf { + /* @brief Pointer to buffer that is no longer in use. */ + u8_t *buf; +}; + +/** @brief UART RX stopped data. */ +struct uart_event_rx_stop { + /** @brief Reason why receiving stopped */ + enum uart_rx_stop_reason reason; + /** @brief Last received data. */ + struct uart_event_rx data; +}; + +/** @brief Structure containing information about current event. */ +struct uart_event { + /** @brief Type of event */ + enum uart_event_type type; + /** @brief Event data */ + union { + /** @brief UART_TX_DONE and UART_TX_ABORTED events data. */ + struct uart_event_tx tx; + /** @brief UART_RX_RDY event data. */ + struct uart_event_rx rx; + /** @brief UART_RX_BUF_RELEASED event data. */ + struct uart_event_rx_buf rx_buf; + /** @brief UART_RX_STOPPED event data. */ + struct uart_event_rx_stop rx_stop; + } data; +}; + +/** + * @typedef uart_callback_t + * @brief Define the application callback function signature for + * uart_callback_set() function. + * + * @param evt Pointer to uart_event structure. + * @param user_data Pointer to data specified by user. + */ +typedef void (*uart_callback_t)(struct uart_event *evt, void *user_data); + +/** + * @brief Options for @a UART initialization. + */ +#define UART_OPTION_AFCE 0x01 + +/** + * @brief UART controller configuration structure + * + * @param baudrate Baudrate setting in bps + * @param parity Parity bit, use @ref uart_config_parity + * @param stop_bits Stop bits, use @ref uart_config_stop_bits + * @param data_bits Data bits, use @ref uart_config_data_bits + * @param flow_ctrl Flow control setting, use @ref uart_config_flow_control + */ +struct uart_config { + u32_t baudrate; + u8_t parity; + u8_t stop_bits; + u8_t data_bits; + u8_t flow_ctrl; +}; + +/** @brief Parity modes */ +enum uart_config_parity { + UART_CFG_PARITY_NONE, + UART_CFG_PARITY_ODD, + UART_CFG_PARITY_EVEN, + UART_CFG_PARITY_MARK, + UART_CFG_PARITY_SPACE, +}; + +/** @brief Number of stop bits. */ +enum uart_config_stop_bits { + UART_CFG_STOP_BITS_0_5, + UART_CFG_STOP_BITS_1, + UART_CFG_STOP_BITS_1_5, + UART_CFG_STOP_BITS_2, +}; + +/** @brief Number of data bits. */ +enum uart_config_data_bits { + UART_CFG_DATA_BITS_5, + UART_CFG_DATA_BITS_6, + UART_CFG_DATA_BITS_7, + UART_CFG_DATA_BITS_8, + UART_CFG_DATA_BITS_9, +}; + +/** + * @brief Hardware flow control options. + * + * With flow control set to none, any operations related to flow control + * signals can be managed by user with uart_line_ctrl functions. + * In other cases, flow control is managed by hardware/driver. + */ +enum uart_config_flow_control { + UART_CFG_FLOW_CTRL_NONE, + UART_CFG_FLOW_CTRL_RTS_CTS, + UART_CFG_FLOW_CTRL_DTR_DSR, +}; + +/** + * @typedef uart_irq_callback_user_data_t + * @brief Define the application callback function signature for + * uart_irq_callback_user_data_set() function. + * + * @param user_data Arbitrary user data. + */ +typedef void (*uart_irq_callback_user_data_t)(void *user_data); + +/** + * @typedef uart_irq_callback_t + * @brief Define the application callback function signature for legacy + * uart_irq_callback_set(). + * + * @param port Device struct for the UART device. + */ +typedef void (*uart_irq_callback_t)(struct device *port); + +/** + * @typedef uart_irq_config_func_t + * @brief For configuring IRQ on each individual UART device. + * + * @internal + */ +typedef void (*uart_irq_config_func_t)(struct device *port); + +/** + * @brief UART device configuration. + * + * @param port Base port number + * @param base Memory mapped base address + * @param regs Register address + * @param sys_clk_freq System clock frequency in Hz + */ +struct uart_device_config { + union { + u32_t port; + u8_t *base; + u32_t regs; + }; + + u32_t sys_clk_freq; + +#if defined(CONFIG_UART_INTERRUPT_DRIVEN) || defined(CONFIG_UART_ASYNC_API) + uart_irq_config_func_t irq_config_func; +#endif +}; + +/** @brief Driver API structure. */ +struct uart_driver_api { + +#ifdef CONFIG_UART_ASYNC_API + + int (*callback_set)(struct device *dev, uart_callback_t callback, + void *user_data); + + int (*tx)(struct device *dev, const u8_t *buf, size_t len, + u32_t timeout); + int (*tx_abort)(struct device *dev); + + int (*rx_enable)(struct device *dev, u8_t *buf, size_t len, + u32_t timeout); + int (*rx_buf_rsp)(struct device *dev, u8_t *buf, size_t len); + int (*rx_disable)(struct device *dev); + +#endif + + /** Console I/O function */ + int (*poll_in)(struct device *dev, unsigned char *p_char); + void (*poll_out)(struct device *dev, unsigned char out_char); + + /** Console I/O function */ + int (*err_check)(struct device *dev); + + /** UART configuration functions */ + int (*configure)(struct device *dev, const struct uart_config *cfg); + int (*config_get)(struct device *dev, struct uart_config *cfg); + +#ifdef CONFIG_UART_INTERRUPT_DRIVEN + + /** Interrupt driven FIFO fill function */ + int (*fifo_fill)(struct device *dev, const u8_t *tx_data, int len); + + /** Interrupt driven FIFO read function */ + int (*fifo_read)(struct device *dev, u8_t *rx_data, const int size); + + /** Interrupt driven transfer enabling function */ + void (*irq_tx_enable)(struct device *dev); + + /** Interrupt driven transfer disabling function */ + void (*irq_tx_disable)(struct device *dev); + + /** Interrupt driven transfer ready function */ + int (*irq_tx_ready)(struct device *dev); + + /** Interrupt driven receiver enabling function */ + void (*irq_rx_enable)(struct device *dev); + + /** Interrupt driven receiver disabling function */ + void (*irq_rx_disable)(struct device *dev); + + /** Interrupt driven transfer complete function */ + int (*irq_tx_complete)(struct device *dev); + + /** Interrupt driven receiver ready function */ + int (*irq_rx_ready)(struct device *dev); + + /** Interrupt driven error enabling function */ + void (*irq_err_enable)(struct device *dev); + + /** Interrupt driven error disabling function */ + void (*irq_err_disable)(struct device *dev); + + /** Interrupt driven pending status function */ + int (*irq_is_pending)(struct device *dev); + + /** Interrupt driven interrupt update function */ + int (*irq_update)(struct device *dev); + + /** Set the irq callback function */ + void (*irq_callback_set)(struct device *dev, + uart_irq_callback_user_data_t cb, + void *user_data); + +#endif + +#ifdef CONFIG_UART_LINE_CTRL + int (*line_ctrl_set)(struct device *dev, u32_t ctrl, u32_t val); + int (*line_ctrl_get)(struct device *dev, u32_t ctrl, u32_t *val); +#endif + +#ifdef CONFIG_UART_DRV_CMD + int (*drv_cmd)(struct device *dev, u32_t cmd, u32_t p); +#endif + +}; + +#ifdef CONFIG_UART_ASYNC_API + +/** + * @brief Set event handler function. + * + * @param dev UART device structure. + * @param callback Event handler. + * @param user_data Data to pass to event handler function. + * + * @retval 0 If successful, negative errno code otherwise. + */ +static inline int uart_callback_set(struct device *dev, + uart_callback_t callback, + void *user_data) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + return api->callback_set(dev, callback, user_data); +} + +/** + * @brief Send given number of bytes from buffer through UART. + * + * Function returns immediately and event handler, + * set using @ref uart_callback_set, is called after transfer is finished. + * + * @param dev UART device structure. + * @param buf Pointer to transmit buffer. + * @param len Length of transmit buffer. + * @param timeout Timeout in milliseconds. Valid only if flow control is enabled + * + * @retval -EBUSY There is already an ongoing transfer. + * @retval 0 If successful, negative errno code otherwise. + */ +static inline int uart_tx(struct device *dev, + const u8_t *buf, + size_t len, + u32_t timeout) + +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + return api->tx(dev, buf, len, timeout); +} + +/** + * @brief Abort current TX transmission. + * + * UART_TX_DONE event will be generated with amount of data sent. + * + * @param dev UART device structure. + * + * @retval -EFAULT There is no active transmission. + * @retval 0 If successful, negative errno code otherwise. + */ +static inline int uart_tx_abort(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + return api->tx_abort(dev); +} + +/** + * @brief Start receiving data through UART. + * + * Function sets given buffer as first buffer for receiving and returns + * immediately. After that event handler, set using @ref uart_callback_set, + * is called with UART_RX_RDY or UART_RX_BUF_REQUEST events. + * + * @param dev UART device structure. + * @param buf Pointer to receive buffer. + * @param len Buffer length. + * @param timeout Timeout in milliseconds. + * + * @retval -EBUSY RX already in progress. + * @retval 0 If successful, negative errno code otherwise. + * + */ +static inline int uart_rx_enable(struct device *dev, u8_t *buf, size_t len, + u32_t timeout) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + return api->rx_enable(dev, buf, len, timeout); +} + +/** + * @brief Provide receive buffer in response to UART_RX_BUF_REQUEST event. + * + * Provide pointer to RX buffer, which will be used when current buffer is + * filled. + * + * @note Providing buffer that is already in usage by driver leads to + * undefined behavior. Buffer can be reused when it has been released + * by driver. + * + * @param dev UART device structure. + * @param buf Pointer to receive buffer. + * @param len Buffer length. + * + * @retval -EBUSY Next buffer already set. + * @retval 0 If successful, negative errno code otherwise. + * + */ +static inline int uart_rx_buf_rsp(struct device *dev, u8_t *buf, size_t len) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + return api->rx_buf_rsp(dev, buf, len); +} + +/** + * @brief Disable RX + * + * UART_RX_BUF_RELEASED event will be generated for every buffer scheduled, + * after that UART_RX_DISABLED event will be generated. + * + * @param dev UART device structure. + * + * @retval -EFAULT There is no active reception. + * @retval 0 If successful, negative errno code otherwise. + */ +static inline int uart_rx_disable(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + return api->rx_disable(dev); +} + +#endif + +/** + * @brief Check whether an error was detected. + * + * @param dev UART device structure. + * + * @retval uart_rx_stop_reason If error during receiving occurred. + * @retval 0 Otherwise. + */ +__syscall int uart_err_check(struct device *dev); + +static inline int z_impl_uart_err_check(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->err_check != NULL) { + return api->err_check(dev); + } + return 0; +} + + +/** + * @brief Poll the device for input. + * + * @param dev UART device structure. + * @param p_char Pointer to character. + * + * @retval 0 If a character arrived. + * @retval -1 If no character was available to read (i.e., the UART + * input buffer was empty). + * @retval -ENOTSUP If the operation is not supported. + * @retval -EBUSY If reception was enabled using uart_rx_enabled + */ +__syscall int uart_poll_in(struct device *dev, unsigned char *p_char); + +static inline int z_impl_uart_poll_in(struct device *dev, unsigned char *p_char) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + return api->poll_in(dev, p_char); +} + +/** + * @brief Output a character in polled mode. + * + * This routine checks if the transmitter is empty. + * When the transmitter is empty, it writes a character to the data + * register. + * + * To send a character when hardware flow control is enabled, the handshake + * signal CTS must be asserted. + * + * @param dev UART device structure. + * @param out_char Character to send. + */ +__syscall void uart_poll_out(struct device *dev, + unsigned char out_char); + +static inline void z_impl_uart_poll_out(struct device *dev, + unsigned char out_char) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + api->poll_out(dev, out_char); +} + +/** + * @brief Set UART configuration. + * + * Sets UART configuration using data from *cfg. + * + * @param dev UART device structure. + * @param cfg UART configuration structure. + * + * + * @retval -ENOTSUP If configuration is not supported by device. + * or driver does not support setting configuration in runtime. + * @retval 0 If successful, negative errno code otherwise. + */ +__syscall int uart_configure(struct device *dev, const struct uart_config *cfg); + +static inline int z_impl_uart_configure(struct device *dev, + const struct uart_config *cfg) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->configure != NULL) { + return api->configure(dev, cfg); + } + + return -ENOTSUP; +} + +/** + * @brief Get UART configuration. + * + * Stores current UART configuration to *cfg, can be used to retrieve initial + * configuration after device was initialized using data from DTS. + * + * @param dev UART device structure. + * @param cfg UART configuration structure. + * + * @retval -ENOTSUP If driver does not support getting current configuration. + * @retval 0 If successful, negative errno code otherwise. + */ +__syscall int uart_config_get(struct device *dev, struct uart_config *cfg); + +static inline int z_impl_uart_config_get(struct device *dev, + struct uart_config *cfg) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->config_get != NULL) { + return api->config_get(dev, cfg); + } + + return -ENOTSUP; +} + +#ifdef CONFIG_UART_INTERRUPT_DRIVEN + +/** + * @brief Fill FIFO with data. + * + * @details This function is expected to be called from UART + * interrupt handler (ISR), if uart_irq_tx_ready() returns true. + * Result of calling this function not from an ISR is undefined + * (hardware-dependent). Likewise, *not* calling this function + * from an ISR if uart_irq_tx_ready() returns true may lead to + * undefined behavior, e.g. infinite interrupt loops. It's + * mandatory to test return value of this function, as different + * hardware has different FIFO depth (oftentimes just 1). + * + * @param dev UART device structure. + * @param tx_data Data to transmit. + * @param size Number of bytes to send. + * + * @return Number of bytes sent. + */ +static inline int uart_fifo_fill(struct device *dev, const u8_t *tx_data, + int size) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->fifo_fill) { + return api->fifo_fill(dev, tx_data, size); + } + + return 0; +} + +/** + * @brief Read data from FIFO. + * + * @details This function is expected to be called from UART + * interrupt handler (ISR), if uart_irq_rx_ready() returns true. + * Result of calling this function not from an ISR is undefined + * (hardware-dependent). It's unspecified whether "RX ready" + * condition as returned by uart_irq_rx_ready() is level- or + * edge- triggered. That means that once uart_irq_rx_ready() is + * detected, uart_fifo_read() must be called until it reads all + * available data in the FIFO (i.e. until it returns less data + * than was requested). + * + * Note that the calling context only applies to physical UARTs and + * no to the virtual ones found in USB CDC ACM code. + * + * @param dev UART device structure. + * @param rx_data Data container. + * @param size Container size. + * + * @return Number of bytes read. + */ +static inline int uart_fifo_read(struct device *dev, u8_t *rx_data, + const int size) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->fifo_read) { + return api->fifo_read(dev, rx_data, size); + } + + return 0; +} + +/** + * @brief Enable TX interrupt in IER. + * + * @param dev UART device structure. + * + * @return N/A + */ +__syscall void uart_irq_tx_enable(struct device *dev); + +static inline void z_impl_uart_irq_tx_enable(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_tx_enable) { + api->irq_tx_enable(dev); + } +} +/** + * @brief Disable TX interrupt in IER. + * + * @param dev UART device structure. + * + * @return N/A + */ +__syscall void uart_irq_tx_disable(struct device *dev); + +static inline void z_impl_uart_irq_tx_disable(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_tx_disable) { + api->irq_tx_disable(dev); + } +} + +/** + * @brief Check if UART TX buffer can accept a new char + * + * @details Check if UART TX buffer can accept at least one character + * for transmission (i.e. uart_fifo_fill() will succeed and return + * non-zero). This function must be called in a UART interrupt + * handler, or its result is undefined. Before calling this function + * in the interrupt handler, uart_irq_update() must be called once per + * the handler invocation. + * + * @param dev UART device structure. + * + * @retval 1 If at least one char can be written to UART. + * @retval 0 Otherwise. + */ +static inline int uart_irq_tx_ready(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_tx_ready) { + return api->irq_tx_ready(dev); + } + + return 0; +} + +/** + * @brief Enable RX interrupt. + * + * @param dev UART device structure. + * + * @return N/A + */ +__syscall void uart_irq_rx_enable(struct device *dev); + +static inline void z_impl_uart_irq_rx_enable(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_rx_enable) { + api->irq_rx_enable(dev); + } +} + +/** + * @brief Disable RX interrupt. + * + * @param dev UART device structure. + * + * @return N/A + */ +__syscall void uart_irq_rx_disable(struct device *dev); + +static inline void z_impl_uart_irq_rx_disable(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_rx_disable) { + api->irq_rx_disable(dev); + } +} + +/** + * @brief Check if UART TX block finished transmission + * + * @details Check if any outgoing data buffered in UART TX block was + * fully transmitted and TX block is idle. When this condition is + * true, UART device (or whole system) can be power off. Note that + * this function is *not* useful to check if UART TX can accept more + * data, use uart_irq_tx_ready() for that. This function must be called + * in a UART interrupt handler, or its result is undefined. Before + * calling this function in the interrupt handler, uart_irq_update() + * must be called once per the handler invocation. + * + * @param dev UART device structure. + * + * @retval 1 If nothing remains to be transmitted. + * @retval 0 Otherwise. + * @retval -ENOTSUP if this function is not supported + */ +static inline int uart_irq_tx_complete(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_tx_complete) { + return api->irq_tx_complete(dev); + } + + return -ENOTSUP; +} + +/** + * @brief Check if UART RX buffer has a received char + * + * @details Check if UART RX buffer has at least one pending character + * (i.e. uart_fifo_read() will succeed and return non-zero). This function + * must be called in a UART interrupt handler, or its result is undefined. + * Before calling this function in the interrupt handler, uart_irq_update() + * must be called once per the handler invocation. It's unspecified whether + * condition as returned by this function is level- or edge- triggered (i.e. + * if this function returns true when RX FIFO is non-empty, or when a new + * char was received since last call to it). See description of + * uart_fifo_read() for implication of this. + * + * @param dev UART device structure. + * + * @retval 1 If a received char is ready. + * @retval 0 Otherwise. + * @retval -ENOTSUP if this function is not supported + */ +static inline int uart_irq_rx_ready(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_rx_ready) { + return api->irq_rx_ready(dev); + } + + return 0; +} +/** + * @brief Enable error interrupt. + * + * @param dev UART device structure. + * + * @return N/A + */ +__syscall void uart_irq_err_enable(struct device *dev); + +static inline void z_impl_uart_irq_err_enable(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_err_enable) { + api->irq_err_enable(dev); + } +} + +/** + * @brief Disable error interrupt. + * + * @param dev UART device structure. + * + * @retval 1 If an IRQ is ready. + * @retval 0 Otherwise. + */ +__syscall void uart_irq_err_disable(struct device *dev); + +static inline void z_impl_uart_irq_err_disable(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_err_disable) { + api->irq_err_disable(dev); + } +} + +/** + * @brief Check if any IRQs is pending. + * + * @param dev UART device structure. + * + * @retval 1 If an IRQ is pending. + * @retval 0 Otherwise. + */ +__syscall int uart_irq_is_pending(struct device *dev); + +static inline int z_impl_uart_irq_is_pending(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_is_pending) { + return api->irq_is_pending(dev); + } + + return 0; +} + +/** + * @brief Start processing interrupts in ISR. + * + * This function should be called the first thing in the ISR. Calling + * uart_irq_rx_ready(), uart_irq_tx_ready(), uart_irq_tx_complete() + * allowed only after this. + * + * The purpose of this function is: + * + * * For devices with auto-acknowledge of interrupt status on register + * read to cache the value of this register (rx_ready, etc. then use + * this case). + * * For devices with explicit acknowledgement of interrupts, to ack + * any pending interrupts and likewise to cache the original value. + * * For devices with implicit acknowledgement, this function will be + * empty. But the ISR must perform the actions needs to ack the + * interrupts (usually, call uart_fifo_read() on rx_ready, and + * uart_fifo_fill() on tx_ready). + * + * @param dev UART device structure. + * + * @retval 1 Always. + */ +__syscall int uart_irq_update(struct device *dev); + +static inline int z_impl_uart_irq_update(struct device *dev) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->irq_update) { + return api->irq_update(dev); + } + + return 0; +} + +/** + * @brief Set the IRQ callback function pointer. + * + * This sets up the callback for IRQ. When an IRQ is triggered, + * the specified function will be called with specified user data. + * See description of uart_irq_update() for the requirements on ISR. + * + * @param dev UART device structure. + * @param cb Pointer to the callback function. + * @param user_data Data to pass to callback function. + * + * @return N/A + */ +static inline void uart_irq_callback_user_data_set( + struct device *dev, + uart_irq_callback_user_data_t cb, + void *user_data) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if ((api != NULL) && (api->irq_callback_set != NULL)) { + api->irq_callback_set(dev, cb, user_data); + } +} + +/** + * @brief Set the IRQ callback function pointer (legacy). + * + * This sets up the callback for IRQ. When an IRQ is triggered, + * the specified function will be called with the device pointer. + * + * @param dev UART device structure. + * @param cb Pointer to the callback function. + * + * @return N/A + */ +static inline void uart_irq_callback_set(struct device *dev, + uart_irq_callback_t cb) +{ + uart_irq_callback_user_data_set(dev, (uart_irq_callback_user_data_t)cb, + dev); +} + +#endif + +#ifdef CONFIG_UART_LINE_CTRL + +/** + * @brief Manipulate line control for UART. + * + * @param dev UART device structure. + * @param ctrl The line control to manipulate. + * @param val Value to set to the line control. + * + * @retval 0 If successful. + * @retval failed Otherwise. + */ +__syscall int uart_line_ctrl_set(struct device *dev, + u32_t ctrl, u32_t val); + +static inline int z_impl_uart_line_ctrl_set(struct device *dev, + u32_t ctrl, u32_t val) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->line_ctrl_set) { + return api->line_ctrl_set(dev, ctrl, val); + } + + return -ENOTSUP; +} + +/** + * @brief Retrieve line control for UART. + * + * @param dev UART device structure. + * @param ctrl The line control to manipulate. + * @param val Value to get for the line control. + * + * @retval 0 If successful. + * @retval failed Otherwise. + */ +__syscall int uart_line_ctrl_get(struct device *dev, u32_t ctrl, u32_t *val); + +static inline int z_impl_uart_line_ctrl_get(struct device *dev, + u32_t ctrl, u32_t *val) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api && api->line_ctrl_get) { + return api->line_ctrl_get(dev, ctrl, val); + } + + return -ENOTSUP; +} + +#endif /* CONFIG_UART_LINE_CTRL */ + +#ifdef CONFIG_UART_DRV_CMD + +/** + * @brief Send extra command to driver. + * + * Implementation and accepted commands are driver specific. + * Refer to the drivers for more information. + * + * @param dev UART device structure. + * @param cmd Command to driver. + * @param p Parameter to the command. + * + * @retval 0 If successful. + * @retval failed Otherwise. + */ +__syscall int uart_drv_cmd(struct device *dev, u32_t cmd, u32_t p); + +static inline int z_impl_uart_drv_cmd(struct device *dev, u32_t cmd, u32_t p) +{ + const struct uart_driver_api *api = + (const struct uart_driver_api *)dev->driver_api; + + if (api->drv_cmd) { + return api->drv_cmd(dev, cmd, p); + } + + return -ENOTSUP; +} + +#endif /* CONFIG_UART_DRV_CMD */ + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#include + +#endif /* ZEPHYR_INCLUDE_DRIVERS_UART_H_ */ diff --git a/include/uart.h b/include/uart.h index a56f492bf6..3bf0e8caf8 100644 --- a/include/uart.h +++ b/include/uart.h @@ -1,1162 +1,15 @@ /* - * Copyright (c) 2018-2019 Nordic Semiconductor ASA - * Copyright (c) 2015 Wind River Systems, Inc. + * Copyright (c) 2019 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ - -/** - * @file - * @brief Public APIs for UART drivers - */ - #ifndef ZEPHYR_INCLUDE_UART_H_ #define ZEPHYR_INCLUDE_UART_H_ -/** - * @brief UART Interface - * @defgroup uart_interface UART Interface - * @ingroup io_interfaces - * @{ - */ - -#include -#include - -#include - -#ifdef __cplusplus -extern "C" { +#ifndef CONFIG_COMPAT_INCLUDES +#warning "This header file has moved, include instead." #endif -/** @brief Line control signals. */ -enum uart_line_ctrl { - UART_LINE_CTRL_RTS = BIT(1), - UART_LINE_CTRL_DTR = BIT(2), - UART_LINE_CTRL_DCD = BIT(3), - UART_LINE_CTRL_DSR = BIT(4), -}; - -/** - * @brief Types of events passed to callback in UART_ASYNC_API - * - * Receiving: - * 1. To start receiving, uart_rx_enable has to be called with first buffer - * 2. When receiving starts to current buffer, UART_RX_BUF_REQUEST will be - * generated, in response to that user can either: - * - * - Provide second buffer using uart_rx_buf_rsp, when first buffer is - * filled, receiving will automatically start to second buffer. - * - Ignore the event, this way when current buffer is filled UART_RX_DONE - * event will be generated and receiving will be stopped. - * - * 3. If some data was received and timeout occurred UART_RX_RDY event will be - * generated. It can happen multiples times for the same buffer. RX timeout - * is counted from last byte received i.e. if no data was received, there - * won't be any timeout event. - * 4. After buffer is filled UART_RX_RDY will be generated, immediately - * followed by UART_RX_BUF_RELEASED indicating that current buffer is no - * longer used. - * 5. If there was second buffer provided, it will become current buffer and - * we start again at point 2. - * If no second buffer was specified receiving is stopped and - * UART_RX_DISABLED event is generated. After that whole process can be - * repeated. - * - * Any time during reception UART_RX_STOPPED event can occur. It will be - * followed by UART_RX_BUF_RELEASED event for every buffer currently passed to - * driver and finally by UART_RX_DISABLED event. - * - * Receiving can be disabled using uart_rx_disable, after calling that - * function any data received will be lost, UART_RX_BUF_RELEASED event will be - * generated for every buffer currently passed to driver and UART_RX_DISABLED - * event will occur. - * - * Transmitting: - * 1. Transmitting starts by uart_tx function. - * 2. If whole buffer was transmitted UART_TX_DONE is generated. - * If timeout occurred UART_TX_ABORTED will be generated. - * - * Transmitting can be aborted using uart_tx_abort, after calling that - * function UART_TX_ABORTED event will be generated. - * - */ -enum uart_event_type { - /** @brief Whole TX buffer was transmitted. */ - UART_TX_DONE, - /** - * @brief Transmitting aborted due to timeout or uart_tx_abort call - * - * When flow control is enabled, there is a possibility that TX transfer - * won't finish in the allotted time. Some data may have been - * transferred, information about it can be found in event data. - */ - UART_TX_ABORTED, - /** - * @brief Received data is ready for processing. - * - * This event is generated in two cases: - * - When RX timeout occurred, and data was stored in provided buffer. - * This can happen multiple times in the same buffer. - * - When provided buffer is full. - */ - UART_RX_RDY, - /** - * @brief Driver requests next buffer for continuous reception. - * - * This event is triggered when receiving has started for a new buffer, - * i.e. it's time to provide a next buffer for a seamless switchover to - * it. For continuous reliable receiving, user should provide another RX - * buffer in response to this event, using uart_rx_buf_rsp function - * - * If uart_rx_buf_rsp is not called before current buffer - * is filled up, receiving will stop. - */ - UART_RX_BUF_REQUEST, - /** - * @brief Buffer is no longer used by UART driver. - */ - UART_RX_BUF_RELEASED, - /** - * @brief RX has been disabled and can be reenabled. - * - * This event is generated whenever receiver has been stopped, disabled - * or finished its operation and can be enabled again using - * uart_rx_enable - */ - UART_RX_DISABLED, - /** - * @brief RX has stopped due to external event. - * - * Reason is one of uart_rx_stop_reason. - */ - UART_RX_STOPPED, -}; - - -/** - * @brief Reception stop reasons. - * - * Values that correspond to events or errors responsible for stopping - * receiving. - */ -enum uart_rx_stop_reason { - /** @brief Overrun error */ - UART_ERROR_OVERRUN = (1 << 0), - /** @brief Parity error */ - UART_ERROR_PARITY = (1 << 1), - /** @brief Framing error */ - UART_ERROR_FRAMING = (1 << 2), - /** - * @brief Break interrupt - * - * A break interrupt was received. This happens when the serial input - * is held at a logic '0' state for longer than the sum of - * start time + data bits + parity + stop bits. - */ - UART_BREAK = (1 << 3), -}; - -/** @brief Backward compatibility defines, deprecated */ -#define UART_ERROR_BREAK UART_BREAK -#define LINE_CTRL_BAUD_RATE (1 << 0) -#define LINE_CTRL_RTS UART_LINE_CTRL_RTS -#define LINE_CTRL_DTR UART_LINE_CTRL_DTR -#define LINE_CTRL_DCD UART_LINE_CTRL_DCD -#define LINE_CTRL_DSR UART_LINE_CTRL_DSR - - -/** @brief UART TX event data. */ -struct uart_event_tx { - /** @brief Pointer to current buffer. */ - const u8_t *buf; - /** @brief Number of bytes sent. */ - size_t len; -}; - -/** - * @brief UART RX event data. - * - * The data represented by the event is stored in rx.buf[rx.offset] to - * rx.buf[rx.offset+rx.len]. That is, the length is relative to the offset. - */ -struct uart_event_rx { - /** @brief Pointer to current buffer. */ - u8_t *buf; - /** @brief Currently received data offset in bytes. */ - size_t offset; - /** @brief Number of new bytes received. */ - size_t len; -}; - -/** @brief UART RX buffer released event data. */ -struct uart_event_rx_buf { - /* @brief Pointer to buffer that is no longer in use. */ - u8_t *buf; -}; - -/** @brief UART RX stopped data. */ -struct uart_event_rx_stop { - /** @brief Reason why receiving stopped */ - enum uart_rx_stop_reason reason; - /** @brief Last received data. */ - struct uart_event_rx data; -}; - -/** @brief Structure containing information about current event. */ -struct uart_event { - /** @brief Type of event */ - enum uart_event_type type; - /** @brief Event data */ - union { - /** @brief UART_TX_DONE and UART_TX_ABORTED events data. */ - struct uart_event_tx tx; - /** @brief UART_RX_RDY event data. */ - struct uart_event_rx rx; - /** @brief UART_RX_BUF_RELEASED event data. */ - struct uart_event_rx_buf rx_buf; - /** @brief UART_RX_STOPPED event data. */ - struct uart_event_rx_stop rx_stop; - } data; -}; - -/** - * @typedef uart_callback_t - * @brief Define the application callback function signature for - * uart_callback_set() function. - * - * @param evt Pointer to uart_event structure. - * @param user_data Pointer to data specified by user. - */ -typedef void (*uart_callback_t)(struct uart_event *evt, void *user_data); - -/** - * @brief Options for @a UART initialization. - */ -#define UART_OPTION_AFCE 0x01 - -/** - * @brief UART controller configuration structure - * - * @param baudrate Baudrate setting in bps - * @param parity Parity bit, use @ref uart_config_parity - * @param stop_bits Stop bits, use @ref uart_config_stop_bits - * @param data_bits Data bits, use @ref uart_config_data_bits - * @param flow_ctrl Flow control setting, use @ref uart_config_flow_control - */ -struct uart_config { - u32_t baudrate; - u8_t parity; - u8_t stop_bits; - u8_t data_bits; - u8_t flow_ctrl; -}; - -/** @brief Parity modes */ -enum uart_config_parity { - UART_CFG_PARITY_NONE, - UART_CFG_PARITY_ODD, - UART_CFG_PARITY_EVEN, - UART_CFG_PARITY_MARK, - UART_CFG_PARITY_SPACE, -}; - -/** @brief Number of stop bits. */ -enum uart_config_stop_bits { - UART_CFG_STOP_BITS_0_5, - UART_CFG_STOP_BITS_1, - UART_CFG_STOP_BITS_1_5, - UART_CFG_STOP_BITS_2, -}; - -/** @brief Number of data bits. */ -enum uart_config_data_bits { - UART_CFG_DATA_BITS_5, - UART_CFG_DATA_BITS_6, - UART_CFG_DATA_BITS_7, - UART_CFG_DATA_BITS_8, - UART_CFG_DATA_BITS_9, -}; - -/** - * @brief Hardware flow control options. - * - * With flow control set to none, any operations related to flow control - * signals can be managed by user with uart_line_ctrl functions. - * In other cases, flow control is managed by hardware/driver. - */ -enum uart_config_flow_control { - UART_CFG_FLOW_CTRL_NONE, - UART_CFG_FLOW_CTRL_RTS_CTS, - UART_CFG_FLOW_CTRL_DTR_DSR, -}; - -/** - * @typedef uart_irq_callback_user_data_t - * @brief Define the application callback function signature for - * uart_irq_callback_user_data_set() function. - * - * @param user_data Arbitrary user data. - */ -typedef void (*uart_irq_callback_user_data_t)(void *user_data); - -/** - * @typedef uart_irq_callback_t - * @brief Define the application callback function signature for legacy - * uart_irq_callback_set(). - * - * @param port Device struct for the UART device. - */ -typedef void (*uart_irq_callback_t)(struct device *port); - -/** - * @typedef uart_irq_config_func_t - * @brief For configuring IRQ on each individual UART device. - * - * @internal - */ -typedef void (*uart_irq_config_func_t)(struct device *port); - -/** - * @brief UART device configuration. - * - * @param port Base port number - * @param base Memory mapped base address - * @param regs Register address - * @param sys_clk_freq System clock frequency in Hz - */ -struct uart_device_config { - union { - u32_t port; - u8_t *base; - u32_t regs; - }; - - u32_t sys_clk_freq; - -#if defined(CONFIG_UART_INTERRUPT_DRIVEN) || defined(CONFIG_UART_ASYNC_API) - uart_irq_config_func_t irq_config_func; -#endif -}; - -/** @brief Driver API structure. */ -struct uart_driver_api { - -#ifdef CONFIG_UART_ASYNC_API - - int (*callback_set)(struct device *dev, uart_callback_t callback, - void *user_data); - - int (*tx)(struct device *dev, const u8_t *buf, size_t len, - u32_t timeout); - int (*tx_abort)(struct device *dev); - - int (*rx_enable)(struct device *dev, u8_t *buf, size_t len, - u32_t timeout); - int (*rx_buf_rsp)(struct device *dev, u8_t *buf, size_t len); - int (*rx_disable)(struct device *dev); - -#endif - - /** Console I/O function */ - int (*poll_in)(struct device *dev, unsigned char *p_char); - void (*poll_out)(struct device *dev, unsigned char out_char); - - /** Console I/O function */ - int (*err_check)(struct device *dev); - - /** UART configuration functions */ - int (*configure)(struct device *dev, const struct uart_config *cfg); - int (*config_get)(struct device *dev, struct uart_config *cfg); - -#ifdef CONFIG_UART_INTERRUPT_DRIVEN - - /** Interrupt driven FIFO fill function */ - int (*fifo_fill)(struct device *dev, const u8_t *tx_data, int len); - - /** Interrupt driven FIFO read function */ - int (*fifo_read)(struct device *dev, u8_t *rx_data, const int size); - - /** Interrupt driven transfer enabling function */ - void (*irq_tx_enable)(struct device *dev); - - /** Interrupt driven transfer disabling function */ - void (*irq_tx_disable)(struct device *dev); - - /** Interrupt driven transfer ready function */ - int (*irq_tx_ready)(struct device *dev); - - /** Interrupt driven receiver enabling function */ - void (*irq_rx_enable)(struct device *dev); - - /** Interrupt driven receiver disabling function */ - void (*irq_rx_disable)(struct device *dev); - - /** Interrupt driven transfer complete function */ - int (*irq_tx_complete)(struct device *dev); - - /** Interrupt driven receiver ready function */ - int (*irq_rx_ready)(struct device *dev); - - /** Interrupt driven error enabling function */ - void (*irq_err_enable)(struct device *dev); - - /** Interrupt driven error disabling function */ - void (*irq_err_disable)(struct device *dev); - - /** Interrupt driven pending status function */ - int (*irq_is_pending)(struct device *dev); - - /** Interrupt driven interrupt update function */ - int (*irq_update)(struct device *dev); - - /** Set the irq callback function */ - void (*irq_callback_set)(struct device *dev, - uart_irq_callback_user_data_t cb, - void *user_data); - -#endif - -#ifdef CONFIG_UART_LINE_CTRL - int (*line_ctrl_set)(struct device *dev, u32_t ctrl, u32_t val); - int (*line_ctrl_get)(struct device *dev, u32_t ctrl, u32_t *val); -#endif - -#ifdef CONFIG_UART_DRV_CMD - int (*drv_cmd)(struct device *dev, u32_t cmd, u32_t p); -#endif - -}; - -#ifdef CONFIG_UART_ASYNC_API - -/** - * @brief Set event handler function. - * - * @param dev UART device structure. - * @param callback Event handler. - * @param user_data Data to pass to event handler function. - * - * @retval 0 If successful, negative errno code otherwise. - */ -static inline int uart_callback_set(struct device *dev, - uart_callback_t callback, - void *user_data) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - return api->callback_set(dev, callback, user_data); -} - -/** - * @brief Send given number of bytes from buffer through UART. - * - * Function returns immediately and event handler, - * set using @ref uart_callback_set, is called after transfer is finished. - * - * @param dev UART device structure. - * @param buf Pointer to transmit buffer. - * @param len Length of transmit buffer. - * @param timeout Timeout in milliseconds. Valid only if flow control is enabled - * - * @retval -EBUSY There is already an ongoing transfer. - * @retval 0 If successful, negative errno code otherwise. - */ -static inline int uart_tx(struct device *dev, - const u8_t *buf, - size_t len, - u32_t timeout) - -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - return api->tx(dev, buf, len, timeout); -} - -/** - * @brief Abort current TX transmission. - * - * UART_TX_DONE event will be generated with amount of data sent. - * - * @param dev UART device structure. - * - * @retval -EFAULT There is no active transmission. - * @retval 0 If successful, negative errno code otherwise. - */ -static inline int uart_tx_abort(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - return api->tx_abort(dev); -} - -/** - * @brief Start receiving data through UART. - * - * Function sets given buffer as first buffer for receiving and returns - * immediately. After that event handler, set using @ref uart_callback_set, - * is called with UART_RX_RDY or UART_RX_BUF_REQUEST events. - * - * @param dev UART device structure. - * @param buf Pointer to receive buffer. - * @param len Buffer length. - * @param timeout Timeout in milliseconds. - * - * @retval -EBUSY RX already in progress. - * @retval 0 If successful, negative errno code otherwise. - * - */ -static inline int uart_rx_enable(struct device *dev, u8_t *buf, size_t len, - u32_t timeout) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - return api->rx_enable(dev, buf, len, timeout); -} - -/** - * @brief Provide receive buffer in response to UART_RX_BUF_REQUEST event. - * - * Provide pointer to RX buffer, which will be used when current buffer is - * filled. - * - * @note Providing buffer that is already in usage by driver leads to - * undefined behavior. Buffer can be reused when it has been released - * by driver. - * - * @param dev UART device structure. - * @param buf Pointer to receive buffer. - * @param len Buffer length. - * - * @retval -EBUSY Next buffer already set. - * @retval 0 If successful, negative errno code otherwise. - * - */ -static inline int uart_rx_buf_rsp(struct device *dev, u8_t *buf, size_t len) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - return api->rx_buf_rsp(dev, buf, len); -} - -/** - * @brief Disable RX - * - * UART_RX_BUF_RELEASED event will be generated for every buffer scheduled, - * after that UART_RX_DISABLED event will be generated. - * - * @param dev UART device structure. - * - * @retval -EFAULT There is no active reception. - * @retval 0 If successful, negative errno code otherwise. - */ -static inline int uart_rx_disable(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - return api->rx_disable(dev); -} - -#endif - -/** - * @brief Check whether an error was detected. - * - * @param dev UART device structure. - * - * @retval uart_rx_stop_reason If error during receiving occurred. - * @retval 0 Otherwise. - */ -__syscall int uart_err_check(struct device *dev); - -static inline int z_impl_uart_err_check(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->err_check != NULL) { - return api->err_check(dev); - } - return 0; -} - - -/** - * @brief Poll the device for input. - * - * @param dev UART device structure. - * @param p_char Pointer to character. - * - * @retval 0 If a character arrived. - * @retval -1 If no character was available to read (i.e., the UART - * input buffer was empty). - * @retval -ENOTSUP If the operation is not supported. - * @retval -EBUSY If reception was enabled using uart_rx_enabled - */ -__syscall int uart_poll_in(struct device *dev, unsigned char *p_char); - -static inline int z_impl_uart_poll_in(struct device *dev, unsigned char *p_char) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - return api->poll_in(dev, p_char); -} - -/** - * @brief Output a character in polled mode. - * - * This routine checks if the transmitter is empty. - * When the transmitter is empty, it writes a character to the data - * register. - * - * To send a character when hardware flow control is enabled, the handshake - * signal CTS must be asserted. - * - * @param dev UART device structure. - * @param out_char Character to send. - */ -__syscall void uart_poll_out(struct device *dev, - unsigned char out_char); - -static inline void z_impl_uart_poll_out(struct device *dev, - unsigned char out_char) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - api->poll_out(dev, out_char); -} - -/** - * @brief Set UART configuration. - * - * Sets UART configuration using data from *cfg. - * - * @param dev UART device structure. - * @param cfg UART configuration structure. - * - * - * @retval -ENOTSUP If configuration is not supported by device. - * or driver does not support setting configuration in runtime. - * @retval 0 If successful, negative errno code otherwise. - */ -__syscall int uart_configure(struct device *dev, const struct uart_config *cfg); - -static inline int z_impl_uart_configure(struct device *dev, - const struct uart_config *cfg) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->configure != NULL) { - return api->configure(dev, cfg); - } - - return -ENOTSUP; -} - -/** - * @brief Get UART configuration. - * - * Stores current UART configuration to *cfg, can be used to retrieve initial - * configuration after device was initialized using data from DTS. - * - * @param dev UART device structure. - * @param cfg UART configuration structure. - * - * @retval -ENOTSUP If driver does not support getting current configuration. - * @retval 0 If successful, negative errno code otherwise. - */ -__syscall int uart_config_get(struct device *dev, struct uart_config *cfg); - -static inline int z_impl_uart_config_get(struct device *dev, - struct uart_config *cfg) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->config_get != NULL) { - return api->config_get(dev, cfg); - } - - return -ENOTSUP; -} - -#ifdef CONFIG_UART_INTERRUPT_DRIVEN - -/** - * @brief Fill FIFO with data. - * - * @details This function is expected to be called from UART - * interrupt handler (ISR), if uart_irq_tx_ready() returns true. - * Result of calling this function not from an ISR is undefined - * (hardware-dependent). Likewise, *not* calling this function - * from an ISR if uart_irq_tx_ready() returns true may lead to - * undefined behavior, e.g. infinite interrupt loops. It's - * mandatory to test return value of this function, as different - * hardware has different FIFO depth (oftentimes just 1). - * - * @param dev UART device structure. - * @param tx_data Data to transmit. - * @param size Number of bytes to send. - * - * @return Number of bytes sent. - */ -static inline int uart_fifo_fill(struct device *dev, const u8_t *tx_data, - int size) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->fifo_fill) { - return api->fifo_fill(dev, tx_data, size); - } - - return 0; -} - -/** - * @brief Read data from FIFO. - * - * @details This function is expected to be called from UART - * interrupt handler (ISR), if uart_irq_rx_ready() returns true. - * Result of calling this function not from an ISR is undefined - * (hardware-dependent). It's unspecified whether "RX ready" - * condition as returned by uart_irq_rx_ready() is level- or - * edge- triggered. That means that once uart_irq_rx_ready() is - * detected, uart_fifo_read() must be called until it reads all - * available data in the FIFO (i.e. until it returns less data - * than was requested). - * - * Note that the calling context only applies to physical UARTs and - * no to the virtual ones found in USB CDC ACM code. - * - * @param dev UART device structure. - * @param rx_data Data container. - * @param size Container size. - * - * @return Number of bytes read. - */ -static inline int uart_fifo_read(struct device *dev, u8_t *rx_data, - const int size) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->fifo_read) { - return api->fifo_read(dev, rx_data, size); - } - - return 0; -} - -/** - * @brief Enable TX interrupt in IER. - * - * @param dev UART device structure. - * - * @return N/A - */ -__syscall void uart_irq_tx_enable(struct device *dev); - -static inline void z_impl_uart_irq_tx_enable(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_tx_enable) { - api->irq_tx_enable(dev); - } -} -/** - * @brief Disable TX interrupt in IER. - * - * @param dev UART device structure. - * - * @return N/A - */ -__syscall void uart_irq_tx_disable(struct device *dev); - -static inline void z_impl_uart_irq_tx_disable(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_tx_disable) { - api->irq_tx_disable(dev); - } -} - -/** - * @brief Check if UART TX buffer can accept a new char - * - * @details Check if UART TX buffer can accept at least one character - * for transmission (i.e. uart_fifo_fill() will succeed and return - * non-zero). This function must be called in a UART interrupt - * handler, or its result is undefined. Before calling this function - * in the interrupt handler, uart_irq_update() must be called once per - * the handler invocation. - * - * @param dev UART device structure. - * - * @retval 1 If at least one char can be written to UART. - * @retval 0 Otherwise. - */ -static inline int uart_irq_tx_ready(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_tx_ready) { - return api->irq_tx_ready(dev); - } - - return 0; -} - -/** - * @brief Enable RX interrupt. - * - * @param dev UART device structure. - * - * @return N/A - */ -__syscall void uart_irq_rx_enable(struct device *dev); - -static inline void z_impl_uart_irq_rx_enable(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_rx_enable) { - api->irq_rx_enable(dev); - } -} - -/** - * @brief Disable RX interrupt. - * - * @param dev UART device structure. - * - * @return N/A - */ -__syscall void uart_irq_rx_disable(struct device *dev); - -static inline void z_impl_uart_irq_rx_disable(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_rx_disable) { - api->irq_rx_disable(dev); - } -} - -/** - * @brief Check if UART TX block finished transmission - * - * @details Check if any outgoing data buffered in UART TX block was - * fully transmitted and TX block is idle. When this condition is - * true, UART device (or whole system) can be power off. Note that - * this function is *not* useful to check if UART TX can accept more - * data, use uart_irq_tx_ready() for that. This function must be called - * in a UART interrupt handler, or its result is undefined. Before - * calling this function in the interrupt handler, uart_irq_update() - * must be called once per the handler invocation. - * - * @param dev UART device structure. - * - * @retval 1 If nothing remains to be transmitted. - * @retval 0 Otherwise. - * @retval -ENOTSUP if this function is not supported - */ -static inline int uart_irq_tx_complete(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_tx_complete) { - return api->irq_tx_complete(dev); - } - - return -ENOTSUP; -} - -/** - * @brief Check if UART RX buffer has a received char - * - * @details Check if UART RX buffer has at least one pending character - * (i.e. uart_fifo_read() will succeed and return non-zero). This function - * must be called in a UART interrupt handler, or its result is undefined. - * Before calling this function in the interrupt handler, uart_irq_update() - * must be called once per the handler invocation. It's unspecified whether - * condition as returned by this function is level- or edge- triggered (i.e. - * if this function returns true when RX FIFO is non-empty, or when a new - * char was received since last call to it). See description of - * uart_fifo_read() for implication of this. - * - * @param dev UART device structure. - * - * @retval 1 If a received char is ready. - * @retval 0 Otherwise. - * @retval -ENOTSUP if this function is not supported - */ -static inline int uart_irq_rx_ready(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_rx_ready) { - return api->irq_rx_ready(dev); - } - - return 0; -} -/** - * @brief Enable error interrupt. - * - * @param dev UART device structure. - * - * @return N/A - */ -__syscall void uart_irq_err_enable(struct device *dev); - -static inline void z_impl_uart_irq_err_enable(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_err_enable) { - api->irq_err_enable(dev); - } -} - -/** - * @brief Disable error interrupt. - * - * @param dev UART device structure. - * - * @retval 1 If an IRQ is ready. - * @retval 0 Otherwise. - */ -__syscall void uart_irq_err_disable(struct device *dev); - -static inline void z_impl_uart_irq_err_disable(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_err_disable) { - api->irq_err_disable(dev); - } -} - -/** - * @brief Check if any IRQs is pending. - * - * @param dev UART device structure. - * - * @retval 1 If an IRQ is pending. - * @retval 0 Otherwise. - */ -__syscall int uart_irq_is_pending(struct device *dev); - -static inline int z_impl_uart_irq_is_pending(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_is_pending) { - return api->irq_is_pending(dev); - } - - return 0; -} - -/** - * @brief Start processing interrupts in ISR. - * - * This function should be called the first thing in the ISR. Calling - * uart_irq_rx_ready(), uart_irq_tx_ready(), uart_irq_tx_complete() - * allowed only after this. - * - * The purpose of this function is: - * - * * For devices with auto-acknowledge of interrupt status on register - * read to cache the value of this register (rx_ready, etc. then use - * this case). - * * For devices with explicit acknowledgement of interrupts, to ack - * any pending interrupts and likewise to cache the original value. - * * For devices with implicit acknowledgement, this function will be - * empty. But the ISR must perform the actions needs to ack the - * interrupts (usually, call uart_fifo_read() on rx_ready, and - * uart_fifo_fill() on tx_ready). - * - * @param dev UART device structure. - * - * @retval 1 Always. - */ -__syscall int uart_irq_update(struct device *dev); - -static inline int z_impl_uart_irq_update(struct device *dev) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->irq_update) { - return api->irq_update(dev); - } - - return 0; -} - -/** - * @brief Set the IRQ callback function pointer. - * - * This sets up the callback for IRQ. When an IRQ is triggered, - * the specified function will be called with specified user data. - * See description of uart_irq_update() for the requirements on ISR. - * - * @param dev UART device structure. - * @param cb Pointer to the callback function. - * @param user_data Data to pass to callback function. - * - * @return N/A - */ -static inline void uart_irq_callback_user_data_set( - struct device *dev, - uart_irq_callback_user_data_t cb, - void *user_data) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if ((api != NULL) && (api->irq_callback_set != NULL)) { - api->irq_callback_set(dev, cb, user_data); - } -} - -/** - * @brief Set the IRQ callback function pointer (legacy). - * - * This sets up the callback for IRQ. When an IRQ is triggered, - * the specified function will be called with the device pointer. - * - * @param dev UART device structure. - * @param cb Pointer to the callback function. - * - * @return N/A - */ -static inline void uart_irq_callback_set(struct device *dev, - uart_irq_callback_t cb) -{ - uart_irq_callback_user_data_set(dev, (uart_irq_callback_user_data_t)cb, - dev); -} - -#endif - -#ifdef CONFIG_UART_LINE_CTRL - -/** - * @brief Manipulate line control for UART. - * - * @param dev UART device structure. - * @param ctrl The line control to manipulate. - * @param val Value to set to the line control. - * - * @retval 0 If successful. - * @retval failed Otherwise. - */ -__syscall int uart_line_ctrl_set(struct device *dev, - u32_t ctrl, u32_t val); - -static inline int z_impl_uart_line_ctrl_set(struct device *dev, - u32_t ctrl, u32_t val) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->line_ctrl_set) { - return api->line_ctrl_set(dev, ctrl, val); - } - - return -ENOTSUP; -} - -/** - * @brief Retrieve line control for UART. - * - * @param dev UART device structure. - * @param ctrl The line control to manipulate. - * @param val Value to get for the line control. - * - * @retval 0 If successful. - * @retval failed Otherwise. - */ -__syscall int uart_line_ctrl_get(struct device *dev, u32_t ctrl, u32_t *val); - -static inline int z_impl_uart_line_ctrl_get(struct device *dev, - u32_t ctrl, u32_t *val) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api && api->line_ctrl_get) { - return api->line_ctrl_get(dev, ctrl, val); - } - - return -ENOTSUP; -} - -#endif /* CONFIG_UART_LINE_CTRL */ - -#ifdef CONFIG_UART_DRV_CMD - -/** - * @brief Send extra command to driver. - * - * Implementation and accepted commands are driver specific. - * Refer to the drivers for more information. - * - * @param dev UART device structure. - * @param cmd Command to driver. - * @param p Parameter to the command. - * - * @retval 0 If successful. - * @retval failed Otherwise. - */ -__syscall int uart_drv_cmd(struct device *dev, u32_t cmd, u32_t p); - -static inline int z_impl_uart_drv_cmd(struct device *dev, u32_t cmd, u32_t p) -{ - const struct uart_driver_api *api = - (const struct uart_driver_api *)dev->driver_api; - - if (api->drv_cmd) { - return api->drv_cmd(dev, cmd, p); - } - - return -ENOTSUP; -} - -#endif /* CONFIG_UART_DRV_CMD */ - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#include +#include #endif /* ZEPHYR_INCLUDE_UART_H_ */ diff --git a/samples/bluetooth/hci_uart/src/main.c b/samples/bluetooth/hci_uart/src/main.c index 95517275d2..17f19ccebc 100644 --- a/samples/bluetooth/hci_uart/src/main.c +++ b/samples/bluetooth/hci_uart/src/main.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include diff --git a/samples/net/wpan_serial/src/main.c b/samples/net/wpan_serial/src/main.c index 7ec867d17b..1379884ad7 100644 --- a/samples/net/wpan_serial/src/main.c +++ b/samples/net/wpan_serial/src/main.c @@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(net_wpan_serial_sample, LOG_LEVEL_DBG); #include #include -#include +#include #include #include diff --git a/samples/nfc/nfc_hello/src/main.c b/samples/nfc/nfc_hello/src/main.c index 0f2f6fa358..06bf7a7b50 100644 --- a/samples/nfc/nfc_hello/src/main.c +++ b/samples/nfc/nfc_hello/src/main.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #define BUF_MAXSIZE 256 diff --git a/samples/subsys/usb/cdc_acm/src/main.c b/samples/subsys/usb/cdc_acm/src/main.c index c0dfc0bb02..c5f578c14c 100644 --- a/samples/subsys/usb/cdc_acm/src/main.c +++ b/samples/subsys/usb/cdc_acm/src/main.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include diff --git a/samples/subsys/usb/cdc_acm_composite/src/main.c b/samples/subsys/usb/cdc_acm_composite/src/main.c index f012339fb4..9ffb1f37d5 100644 --- a/samples/subsys/usb/cdc_acm_composite/src/main.c +++ b/samples/subsys/usb/cdc_acm_composite/src/main.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include diff --git a/samples/subsys/usb/hid-cdc/src/main.c b/samples/subsys/usb/hid-cdc/src/main.c index 0a8cea7dea..f4d90c6326 100644 --- a/samples/subsys/usb/hid-cdc/src/main.c +++ b/samples/subsys/usb/hid-cdc/src/main.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include diff --git a/soc/arm/nxp_kinetis/k6x/soc.c b/soc/arm/nxp_kinetis/k6x/soc.c index f327fc046c..b8b93a4798 100644 --- a/soc/arm/nxp_kinetis/k6x/soc.c +++ b/soc/arm/nxp_kinetis/k6x/soc.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c b/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c index 21c03a676f..f989ab3232 100644 --- a/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c +++ b/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/soc/arm/nxp_kinetis/kwx/soc_kw4xz.c b/soc/arm/nxp_kinetis/kwx/soc_kw4xz.c index d866f39a47..f57c69bc34 100644 --- a/soc/arm/nxp_kinetis/kwx/soc_kw4xz.c +++ b/soc/arm/nxp_kinetis/kwx/soc_kw4xz.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/soc/arm/nxp_lpc/lpc54xxx/soc.c b/soc/arm/nxp_lpc/lpc54xxx/soc.c index 354094ce89..fe1d123a5c 100644 --- a/soc/arm/nxp_lpc/lpc54xxx/soc.c +++ b/soc/arm/nxp_lpc/lpc54xxx/soc.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/soc/arm/nxp_lpc/lpc55xxx/soc.c b/soc/arm/nxp_lpc/lpc55xxx/soc.c index 510a5435ec..c838109f63 100644 --- a/soc/arm/nxp_lpc/lpc55xxx/soc.c +++ b/soc/arm/nxp_lpc/lpc55xxx/soc.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/soc/arm/ti_lm3s6965/soc_config.c b/soc/arm/ti_lm3s6965/soc_config.c index f154bd5270..4743bfd177 100644 --- a/soc/arm/ti_lm3s6965/soc_config.c +++ b/soc/arm/ti_lm3s6965/soc_config.c @@ -16,7 +16,7 @@ #include "soc.h" #ifdef CONFIG_UART_STELLARIS -#include +#include #define RCGC1 (*((volatile u32_t *)0x400FE104)) diff --git a/soc/x86/apollo_lake/soc.c b/soc/x86/apollo_lake/soc.c index 7fb30be803..47b5aa333e 100644 --- a/soc/x86/apollo_lake/soc.c +++ b/soc/x86/apollo_lake/soc.c @@ -15,7 +15,7 @@ #include #include "soc.h" -#include +#include #include #include diff --git a/soc/x86/atom/soc.c b/soc/x86/atom/soc.c index 45a9aa8e8d..5a4204fbf2 100644 --- a/soc/x86/atom/soc.c +++ b/soc/x86/atom/soc.c @@ -14,7 +14,7 @@ #include #include "soc.h" -#include +#include #include #include diff --git a/soc/x86/ia32/soc.c b/soc/x86/ia32/soc.c index b740191af4..b03eff64c1 100644 --- a/soc/x86/ia32/soc.c +++ b/soc/x86/ia32/soc.c @@ -14,7 +14,7 @@ #include #include "soc.h" -#include +#include #include #include #include diff --git a/soc/x86/intel_quark/quark_se/soc.c b/soc/x86/intel_quark/quark_se/soc.c index ca236259a8..a5d9b0eab1 100644 --- a/soc/x86/intel_quark/quark_se/soc.c +++ b/soc/x86/intel_quark/quark_se/soc.c @@ -18,7 +18,7 @@ #include #include #include "soc.h" -#include +#include #include #include "shared_mem.h" #include diff --git a/soc/x86/intel_quark/quark_se/soc.h b/soc/x86/intel_quark/quark_se/soc.h index c5fae98272..888de5003a 100644 --- a/soc/x86/intel_quark/quark_se/soc.h +++ b/soc/x86/intel_quark/quark_se/soc.h @@ -15,7 +15,7 @@ #include #include -#include +#include #ifdef CONFIG_IOAPIC #include diff --git a/soc/x86/intel_quark/quark_x1000/soc.c b/soc/x86/intel_quark/quark_x1000/soc.c index f7826d00db..76fa7d68f9 100644 --- a/soc/x86/intel_quark/quark_x1000/soc.c +++ b/soc/x86/intel_quark/quark_x1000/soc.c @@ -21,7 +21,7 @@ #include #include #include "soc.h" -#include +#include #include #include #include diff --git a/subsys/bluetooth/host/monitor.c b/subsys/bluetooth/host/monitor.c index 6fc96f4b17..12453ca83d 100644 --- a/subsys/bluetooth/host/monitor.c +++ b/subsys/bluetooth/host/monitor.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/console/getline.c b/subsys/console/getline.c index d38f965fe2..84c1130e9e 100644 --- a/subsys/console/getline.c +++ b/subsys/console/getline.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include diff --git a/subsys/console/tty.c b/subsys/console/tty.c index e8b92aa8f3..2f33732ca3 100644 --- a/subsys/console/tty.c +++ b/subsys/console/tty.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include diff --git a/subsys/logging/log_backend_uart.c b/subsys/logging/log_backend_uart.c index 040fab1d7a..ab2a5804a7 100644 --- a/subsys/logging/log_backend_uart.c +++ b/subsys/logging/log_backend_uart.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include static int char_out(u8_t *data, size_t length, void *ctx) diff --git a/subsys/shell/shell_uart.c b/subsys/shell/shell_uart.c index 5886726938..6203ed8d3c 100644 --- a/subsys/shell/shell_uart.c +++ b/subsys/shell/shell_uart.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include diff --git a/subsys/usb/class/cdc_acm.c b/subsys/usb/class/cdc_acm.c index ea39d5e0d6..937470e9fb 100644 --- a/subsys/usb/class/cdc_acm.c +++ b/subsys/usb/class/cdc_acm.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/application_development/cpp/src/main.cpp b/tests/application_development/cpp/src/main.cpp index ca9ca1d85b..a0a906b4f3 100644 --- a/tests/application_development/cpp/src/main.cpp +++ b/tests/application_development/cpp/src/main.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/drivers/uart/uart_async_api/src/test_uart.h b/tests/drivers/uart/uart_async_api/src/test_uart.h index 50cf1097ea..ed3778a86b 100644 --- a/tests/drivers/uart/uart_async_api/src/test_uart.h +++ b/tests/drivers/uart/uart_async_api/src/test_uart.h @@ -14,7 +14,7 @@ #ifndef __TEST_UART_H__ #define __TEST_UART_H__ -#include +#include #include /* RX and TX pins have to be connected together*/ diff --git a/tests/drivers/uart/uart_basic_api/src/test_uart.h b/tests/drivers/uart/uart_basic_api/src/test_uart.h index 089a23d52d..46777228bf 100644 --- a/tests/drivers/uart/uart_basic_api/src/test_uart.h +++ b/tests/drivers/uart/uart_basic_api/src/test_uart.h @@ -14,7 +14,7 @@ #ifndef __TEST_UART_H__ #define __TEST_UART_H__ -#include +#include #include #define UART_DEVICE_NAME CONFIG_UART_CONSOLE_ON_DEV_NAME