1 /** 2 * @brief "Bottom" of native tty uart driver 3 * 4 * When built with the native_simulator this will be built in the runner context, 5 * that is, with the host C library, and with the host include paths. 6 * 7 * Copyright (c) 2023 Marko Sagadin 8 * SPDX-License-Identifier: Apache-2.0 9 */ 10 11 #ifndef DRIVERS_SERIAL_UART_NATIVE_TTY_BOTTOM_H 12 #define DRIVERS_SERIAL_UART_NATIVE_TTY_BOTTOM_H 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #include <stdint.h> 19 20 /* Below enums are just differently namespaced copies of uart_config_* enums. Options that are not 21 * supported on the host are not listed. 22 */ 23 enum native_tty_bottom_parity { 24 NTB_PARITY_NONE, 25 NTB_PARITY_ODD, 26 NTB_PARITY_EVEN, 27 }; 28 29 enum native_tty_bottom_stop_bits { 30 NTB_STOP_BITS_1, 31 NTB_STOP_BITS_2, 32 }; 33 34 enum native_tty_bottom_data_bits { 35 NTB_DATA_BITS_5, 36 NTB_DATA_BITS_6, 37 NTB_DATA_BITS_7, 38 NTB_DATA_BITS_8, 39 }; 40 41 enum native_tty_bottom_flow_control { 42 NTB_FLOW_CTRL_NONE, 43 }; 44 45 struct native_tty_bottom_cfg { 46 uint32_t baudrate; 47 enum native_tty_bottom_parity parity; 48 enum native_tty_bottom_stop_bits stop_bits; 49 enum native_tty_bottom_data_bits data_bits; 50 enum native_tty_bottom_flow_control flow_ctrl; 51 }; 52 53 /* Note: None of these functions are public interfaces. They are internal to the native tty driver. 54 */ 55 56 /** 57 * @brief Opens tty port on the given pathname 58 * 59 * Returned file descriptor can be then passed to native_tty_configure_bottom to configure it. 60 * 61 * @param pathname 62 * 63 * @return file descriptor 64 */ 65 int native_tty_open_tty_bottom(const char *pathname); 66 67 /** 68 * @brief Configure tty port 69 * 70 * @param fd File descriptor of the tty port. 71 * @param cfg Configuration struct. 72 * 73 * @retval 0 if successful, 74 * @retval -1 otherwise. 75 */ 76 int native_tty_configure_bottom(int fd, struct native_tty_bottom_cfg *cfg); 77 78 #ifdef __cplusplus 79 } 80 #endif 81 82 #endif /* DRIVERS_SERIAL_UART_NATIVE_TTY_BOTTOM_H */ 83