Lines Matching refs:tty
12 static int tty_irq_input_hook(struct tty_serial *tty, uint8_t c);
13 static int tty_putchar(struct tty_serial *tty, uint8_t c);
17 struct tty_serial *tty = user_data; in tty_uart_isr() local
28 tty_irq_input_hook(tty, c); in tty_uart_isr()
33 if (tty->tx_get == tty->tx_put) { in tty_uart_isr()
39 uart_fifo_fill(dev, &tty->tx_ringbuf[tty->tx_get++], 1); in tty_uart_isr()
40 if (tty->tx_get >= tty->tx_ringbuf_sz) { in tty_uart_isr()
41 tty->tx_get = 0U; in tty_uart_isr()
43 k_sem_give(&tty->tx_sem); in tty_uart_isr()
48 static int tty_irq_input_hook(struct tty_serial *tty, uint8_t c) in tty_irq_input_hook() argument
50 int rx_next = tty->rx_put + 1; in tty_irq_input_hook()
52 if (rx_next >= tty->rx_ringbuf_sz) { in tty_irq_input_hook()
56 if (rx_next == tty->rx_get) { in tty_irq_input_hook()
58 tty_putchar(tty, '~'); in tty_irq_input_hook()
62 tty->rx_ringbuf[tty->rx_put] = c; in tty_irq_input_hook()
63 tty->rx_put = rx_next; in tty_irq_input_hook()
64 k_sem_give(&tty->rx_sem); in tty_irq_input_hook()
69 static int tty_putchar(struct tty_serial *tty, uint8_t c) in tty_putchar() argument
75 res = k_sem_take(&tty->tx_sem, in tty_putchar()
77 SYS_TIMEOUT_MS(tty->tx_timeout)); in tty_putchar()
83 tx_next = tty->tx_put + 1; in tty_putchar()
84 if (tx_next >= tty->tx_ringbuf_sz) { in tty_putchar()
87 if (tx_next == tty->tx_get) { in tty_putchar()
92 tty->tx_ringbuf[tty->tx_put] = c; in tty_putchar()
93 tty->tx_put = tx_next; in tty_putchar()
96 uart_irq_tx_enable(tty->uart_dev); in tty_putchar()
100 ssize_t tty_write(struct tty_serial *tty, const void *buf, size_t size) in tty_write() argument
106 if (tty->tx_ringbuf_sz == 0U) { in tty_write()
111 uart_poll_out(tty->uart_dev, *p++); in tty_write()
118 res = tty_putchar(tty, *p++); in tty_write()
141 static int tty_getchar(struct tty_serial *tty) in tty_getchar() argument
147 res = k_sem_take(&tty->rx_sem, SYS_TIMEOUT_MS(tty->rx_timeout)); in tty_getchar()
153 c = tty->rx_ringbuf[tty->rx_get++]; in tty_getchar()
154 if (tty->rx_get >= tty->rx_ringbuf_sz) { in tty_getchar()
155 tty->rx_get = 0U; in tty_getchar()
162 static ssize_t tty_read_unbuf(struct tty_serial *tty, void *buf, size_t size) in tty_read_unbuf() argument
167 uint32_t timeout = tty->rx_timeout; in tty_read_unbuf()
171 res = uart_poll_in(tty->uart_dev, &c); in tty_read_unbuf()
206 ssize_t tty_read(struct tty_serial *tty, void *buf, size_t size) in tty_read() argument
212 if (tty->rx_ringbuf_sz == 0U) { in tty_read()
213 return tty_read_unbuf(tty, buf, size); in tty_read()
217 res = tty_getchar(tty); in tty_read()
241 int tty_init(struct tty_serial *tty, const struct device *uart_dev) in tty_init() argument
247 tty->uart_dev = uart_dev; in tty_init()
250 tty->rx_ringbuf = NULL; in tty_init()
251 tty->rx_ringbuf_sz = 0U; in tty_init()
252 tty->tx_ringbuf = NULL; in tty_init()
253 tty->tx_ringbuf_sz = 0U; in tty_init()
255 tty->rx_get = tty->rx_put = tty->tx_get = tty->tx_put = 0U; in tty_init()
257 tty->rx_timeout = SYS_FOREVER_MS; in tty_init()
258 tty->tx_timeout = SYS_FOREVER_MS; in tty_init()
260 uart_irq_callback_user_data_set(uart_dev, tty_uart_isr, tty); in tty_init()
265 int tty_set_rx_buf(struct tty_serial *tty, void *buf, size_t size) in tty_set_rx_buf() argument
267 uart_irq_rx_disable(tty->uart_dev); in tty_set_rx_buf()
269 tty->rx_ringbuf = buf; in tty_set_rx_buf()
270 tty->rx_ringbuf_sz = size; in tty_set_rx_buf()
273 k_sem_init(&tty->rx_sem, 0, K_SEM_MAX_LIMIT); in tty_set_rx_buf()
274 uart_irq_rx_enable(tty->uart_dev); in tty_set_rx_buf()
280 int tty_set_tx_buf(struct tty_serial *tty, void *buf, size_t size) in tty_set_tx_buf() argument
282 uart_irq_tx_disable(tty->uart_dev); in tty_set_tx_buf()
284 tty->tx_ringbuf = buf; in tty_set_tx_buf()
285 tty->tx_ringbuf_sz = size; in tty_set_tx_buf()
287 k_sem_init(&tty->tx_sem, size - 1, K_SEM_MAX_LIMIT); in tty_set_tx_buf()