Skip to content

Commit

Permalink
drivers: serial: uart_cdns: fix interrupt driven
Browse files Browse the repository at this point in the history
Fix interrupt driven for shell

Signed-off-by: Frank Lin <linfrank@meta.com>
  • Loading branch information
frankshuweilin authored and nashif committed Jul 9, 2024
1 parent 49e8c98 commit 6fc525c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions drivers/serial/uart_cdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ static int uart_cdns_fill_fifo(const struct device *dev, const uint8_t *tx_data,

for (i = 0; i < len && (!uart_cdns_is_tx_fifo_full(uart_regs)); i++) {
uart_regs->rx_tx_fifo = tx_data[i];
while (!uart_cdns_is_tx_fifo_empty(uart_regs)) {
}
}
return i;
}
Expand All @@ -108,14 +106,20 @@ void uart_cdns_enable_tx_irq(const struct device *dev)
{
struct uart_cdns_regs *uart_regs = DEV_UART(dev);

uart_regs->intr_enable |= CSR_TTRIG_MASK;
/*
* TX empty interrupt only triggered when TX removes the last byte from the
* TX FIFO. We need another way generate the first interrupt. This is why
* we have the timer involved here
*/
uart_regs->rx_timeout = DEFAULT_RTO_PERIODS_FACTOR;
uart_regs->intr_enable = CSR_TEMPTY_MASK | CSR_TOUT_MASK;
}

void uart_cdns_disable_tx_irq(const struct device *dev)
{
struct uart_cdns_regs *uart_regs = DEV_UART(dev);

uart_regs->intr_disable |= CSR_TTRIG_MASK;
uart_regs->intr_disable = CSR_TEMPTY_MASK | CSR_TOUT_MASK;
}

static int uart_cdns_irq_tx_ready(const struct device *dev)
Expand All @@ -132,16 +136,16 @@ void uart_cdns_enable_rx_irq(const struct device *dev)
{
struct uart_cdns_regs *uart_regs = DEV_UART(dev);

uart_regs->rx_timeout = DEFAULT_RTO_PERIODS_FACTOR;
uart_regs->intr_enable |= (CSR_RTRIG_MASK | CSR_RBRK_MASK | CSR_TOUT_MASK);
uart_regs->rx_fifo_trigger_level = 1;
uart_regs->intr_enable = CSR_RTRIG_MASK;
}

/** Disable RX UART interrupt */
void uart_cdns_disable_rx_irq(const struct device *dev)
{
struct uart_cdns_regs *uart_regs = DEV_UART(dev);

uart_regs->intr_disable |= (CSR_RTRIG_MASK | CSR_RBRK_MASK | CSR_TOUT_MASK);
uart_regs->intr_disable = CSR_RTRIG_MASK;
}

static int uart_cdns_irq_rx_ready(const struct device *dev)
Expand Down Expand Up @@ -204,6 +208,10 @@ static void uart_cdns_irq_handler(const struct device *dev)
/* need to make local copy of the status */
isr_status = uart_regs->channel_intr_status;

if (isr_status & CSR_TOUT_MASK) {
uart_regs->intr_disable = CSR_TOUT_MASK;
}

irq_unlock(key);
}

Expand Down

0 comments on commit 6fc525c

Please sign in to comment.