Lines Matching +full:serial +full:- +full:port
2 * @brief UART Driver for interacting with host serial ports
4 * @note Driver can open and send characters to the host serial ports (such as /dev/ttyUSB0 or
14 * SPDX-License-Identifier: Apache-2.0
40 /* Serial port set from the command line. If NULL, it was not set. */
77 bottom_cfg->baudrate = cfg->baudrate; in native_tty_conv_to_bottom_cfg()
79 switch (cfg->parity) { in native_tty_conv_to_bottom_cfg()
81 bottom_cfg->parity = NTB_PARITY_NONE; in native_tty_conv_to_bottom_cfg()
84 bottom_cfg->parity = NTB_PARITY_ODD; in native_tty_conv_to_bottom_cfg()
87 bottom_cfg->parity = NTB_PARITY_EVEN; in native_tty_conv_to_bottom_cfg()
90 return -ENOTSUP; in native_tty_conv_to_bottom_cfg()
93 switch (cfg->stop_bits) { in native_tty_conv_to_bottom_cfg()
95 bottom_cfg->stop_bits = NTB_STOP_BITS_1; in native_tty_conv_to_bottom_cfg()
98 bottom_cfg->stop_bits = NTB_STOP_BITS_2; in native_tty_conv_to_bottom_cfg()
101 return -ENOTSUP; in native_tty_conv_to_bottom_cfg()
104 switch (cfg->data_bits) { in native_tty_conv_to_bottom_cfg()
106 bottom_cfg->data_bits = NTB_DATA_BITS_5; in native_tty_conv_to_bottom_cfg()
109 bottom_cfg->data_bits = NTB_DATA_BITS_6; in native_tty_conv_to_bottom_cfg()
112 bottom_cfg->data_bits = NTB_DATA_BITS_7; in native_tty_conv_to_bottom_cfg()
115 bottom_cfg->data_bits = NTB_DATA_BITS_8; in native_tty_conv_to_bottom_cfg()
118 return -ENOTSUP; in native_tty_conv_to_bottom_cfg()
121 if (cfg->flow_ctrl != UART_CFG_FLOW_CTRL_NONE) { in native_tty_conv_to_bottom_cfg()
123 return -ENOTSUP; in native_tty_conv_to_bottom_cfg()
126 bottom_cfg->flow_ctrl = NTB_FLOW_CTRL_NONE; in native_tty_conv_to_bottom_cfg()
132 * @brief Output a character towards the serial port
139 struct native_tty_data *data = dev->data; in native_tty_uart_poll_out()
141 int ret = nsi_host_write(data->fd, &out_char, 1); in native_tty_uart_poll_out()
143 if (ret == -1) { in native_tty_uart_poll_out()
144 ERROR("Could not write to %s\n", data->serial_port); in native_tty_uart_poll_out()
155 * @retval -1 If no character was available to read.
159 struct native_tty_data *data = dev->data; in native_tty_uart_poll_in()
161 return nsi_host_read(data->fd, p_char, 1) > 0 ? 0 : -1; in native_tty_uart_poll_in()
166 int fd = ((struct native_tty_data *)dev->data)->fd; in native_tty_configure()
183 struct native_tty_data *data = dev->data; in native_tty_uart_fifo_fill()
185 return nsi_host_write(data->fd, (void *)tx_data, size); in native_tty_uart_fifo_fill()
192 struct native_tty_data *data = dev->data; in native_tty_uart_fifo_read()
194 return nsi_host_read(data->fd, rx_data, size); in native_tty_uart_fifo_read()
199 struct native_tty_data *data = dev->data; in native_tty_uart_irq_tx_ready()
201 return data->tx_irq_enabled ? 1 : 0; in native_tty_uart_irq_tx_ready()
212 struct native_tty_data *data = dev->data; in native_tty_uart_irq_tx_enable()
214 data->tx_irq_enabled = true; in native_tty_uart_irq_tx_enable()
219 struct native_tty_data *data = dev->data; in native_tty_uart_irq_tx_disable()
221 data->tx_irq_enabled = false; in native_tty_uart_irq_tx_disable()
226 struct native_tty_data *data = dev->data; in native_tty_uart_irq_rx_enable()
228 data->rx_irq_enabled = true; in native_tty_uart_irq_rx_enable()
233 struct native_tty_data *data = dev->data; in native_tty_uart_irq_rx_disable()
235 data->rx_irq_enabled = false; in native_tty_uart_irq_rx_disable()
240 struct native_tty_data *data = dev->data; in native_tty_uart_irq_rx_ready()
242 if (data->rx_irq_enabled && native_tty_poll_bottom(data->fd) == 1) { in native_tty_uart_irq_rx_ready()
262 struct native_tty_data *data = dev->data; in native_tty_uart_irq_handler()
264 if (data->callback) { in native_tty_uart_irq_handler()
265 data->callback(dev, data->cb_data); in native_tty_uart_irq_handler()
279 struct native_tty_data *data = dev->data; in native_tty_uart_irq_function()
282 if (data->rx_irq_enabled) { in native_tty_uart_irq_function()
283 int ret = native_tty_poll_bottom(data->fd); in native_tty_uart_irq_function()
293 if (data->tx_irq_enabled) { in native_tty_uart_irq_function()
296 if (data->tx_irq_enabled == false && data->rx_irq_enabled == false) { in native_tty_uart_irq_function()
306 struct native_tty_data *data = dev->data; in native_tty_uart_irq_callback_set()
308 data->callback = cb; in native_tty_uart_irq_callback_set()
309 data->cb_data = cb_data; in native_tty_uart_irq_callback_set()
314 /* Create a thread which will wait for data - replacement for IRQ */ in native_tty_irq_init()
324 struct native_tty_data *data = dev->data; in native_tty_serial_init()
325 struct uart_config uart_config = ((struct native_tty_config *)dev->config)->uart_config; in native_tty_serial_init()
331 if (data->cmd_serial_port) { in native_tty_serial_init()
332 data->serial_port = data->cmd_serial_port; in native_tty_serial_init()
339 if (data->cmd_baudrate != UINT32_MAX) { in native_tty_serial_init()
340 uart_config.baudrate = data->cmd_baudrate; in native_tty_serial_init()
343 /* Serial port needs to be set either in the devicetree or provided via command line in native_tty_serial_init()
346 if (!data->serial_port) { in native_tty_serial_init()
347 ERROR("%s: path to the serial port was not set.\n", dev->name); in native_tty_serial_init()
350 /* Try to open a serial port as with read/write access, also prevent serial port in native_tty_serial_init()
354 data->fd = native_tty_open_tty_bottom(data->serial_port); in native_tty_serial_init()
357 ERROR("%s: could not configure serial port %s\n", dev->name, data->serial_port); in native_tty_serial_init()
360 posix_print_trace("%s connected to the serial port: %s\n", dev->name, data->serial_port); in native_tty_serial_init()
421 .descript = "Set a serial port for " INST_NAME(inst) " uart device, " \
435 * @brief Adds command line options for setting serial port and baud rate for each uart
452 * @brief Cleans up any open serial ports on the exit.