subsys: console: tty: Allow to specify receive timeout
This allows to specify receive timeout, instead of previously
hardcoded K_FOREVER value. K_FOREVER is still the default, and can
be changes after tty initialization using tty_set_rx_timeout() call,
and timeout is stored as a property of tty. (Instead of e.g. being
a param of each receive call. Handling like that is required for
POSIX-like behavior of tty).
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
diff --git a/subsys/console/tty.c b/subsys/console/tty.c
index 5f004f5..0d916c7 100644
--- a/subsys/console/tty.c
+++ b/subsys/console/tty.c
@@ -91,12 +91,16 @@
return 0;
}
-u8_t tty_getchar(struct tty_serial *tty)
+int tty_getchar(struct tty_serial *tty)
{
unsigned int key;
u8_t c;
+ int res;
- k_sem_take(&tty->rx_sem, K_FOREVER);
+ res = k_sem_take(&tty->rx_sem, tty->rx_timeout);
+ if (res < 0) {
+ return res;
+ }
key = irq_lock();
c = tty->rx_ringbuf[tty->rx_get++];
@@ -120,6 +124,8 @@
tty->rx_get = tty->rx_put = tty->tx_get = tty->tx_put = 0;
k_sem_init(&tty->rx_sem, 0, UINT_MAX);
+ tty->rx_timeout = K_FOREVER;
+
uart_irq_callback_user_data_set(uart_dev, tty_uart_isr, tty);
uart_irq_rx_enable(uart_dev);
}