uart-npcx: forward poll requests to fifo when running interrupt mode

Looking at the data sheet for the npcx section 4.15.5 CR_UART Core
Registers, the UICTRL register that is used in the npcx poll
functions is invalid when running in FIFO mode. Instead, calls to
uart_npcx_poll_in and uart_npcx_poll_out should be redirected to
their respective FIFO read/fill functions (when using interrupts).

Changes:
- When calling uart_poll_in: forward the request to uart_fifo_read.
- When calling uart_poll_out: loop until uart_fifo_fill returns
  non-0 (we wrote 1 byte).

Signed-off-by: Yuval Peress <peress@chromium.org>
This commit is contained in:
Yuval Peress 2021-02-25 11:34:18 -07:00 committed by Kumar Gala
commit 7162786f83

View file

@ -213,9 +213,32 @@ static void uart_npcx_isr(const struct device *dev)
data->user_cb(dev, data->user_data);
}
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
/* UART api functions */
/*
* Poll-in implementation for interrupt driven config, forward call to
* uart_npcx_fifo_read().
*/
static int uart_npcx_poll_in(const struct device *dev, unsigned char *c)
{
return uart_npcx_fifo_read(dev, c, 1) ? 0 : -1;
}
/*
* Poll-out implementation for interrupt driven config, forward call to
* uart_npcx_fifo_fill().
*/
static void uart_npcx_poll_out(const struct device *dev, unsigned char c)
{
while (!uart_npcx_fifo_fill(dev, &c, 1))
continue;
}
#else /* !CONFIG_UART_INTERRUPT_DRIVEN */
/*
* Poll-in implementation for byte mode config, read byte from URBUF if
* available.
*/
static int uart_npcx_poll_in(const struct device *dev, unsigned char *c)
{
struct uart_reg *const inst = HAL_INSTANCE(dev);
@ -228,6 +251,9 @@ static int uart_npcx_poll_in(const struct device *dev, unsigned char *c)
return 0;
}
/*
* Poll-out implementation for byte mode config, write byte to UTBUF if empty.
*/
static void uart_npcx_poll_out(const struct device *dev, unsigned char c)
{
struct uart_reg *const inst = HAL_INSTANCE(dev);
@ -238,7 +264,9 @@ static void uart_npcx_poll_out(const struct device *dev, unsigned char c)
inst->UTBUF = c;
}
#endif /* !CONFIG_UART_INTERRUPT_DRIVEN */
/* UART api functions */
static int uart_npcx_err_check(const struct device *dev)
{
struct uart_reg *const inst = HAL_INSTANCE(dev);