uart: add ISR callback mechanism for UART drivers

The peripherals utilizing UART were required to register their own
ISR rountines. This means that all those peripherals drivers need
to know which IRQ line is attached to a UART controller, and all
the other config values required to register a ISR. This causes
scalibility issue as every board and peripherals have to define
those values.

Another reason for this patch is to support virtual serial ports.
Virtual serial ports do not have physical interrupt lines to
attach, and thus would not work.

This patch adds a simple callback mechanism, which calls a function
when UART interrupts are triggered. The low level plumbing still needs
to be done by the peripheral drivers, as these drivers may need to
access low level capability of UART to function correctly. This simply
moves the interrupt setup into the UART drivers themselves. By doing
this, the peripheral drivers do not need to know all the config values
to properly setup the interrupts and attaching the ISR. One drawback
is that this adds to the interrupt latency.

Note that this patch breaks backward compatibility in terms of
setting up interrupt for UART controller. How to use UART is still
the same.

This also addresses the following issues:

() UART driver for Atmel SAM3 currently does not support interrupts.
   So remove the code from vector table. This will be updated when
   there is interrupt support for the driver.
() Corrected some config options for Stellaris UART driver.

This was tested with samples/shell on Arduino 101, and on QEMU
(Cortex-M3 and x86).

Origin: original code
Change-Id: Ib4593d8ccd711f4e97d388c7293205d213be1aec
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2016-03-03 10:14:50 -08:00 committed by Anas Nashif
commit e643cede3a
30 changed files with 492 additions and 238 deletions

View file

@ -120,18 +120,4 @@ config NBLE_UART_ON_DEV_NAME
This option specifies the name of UART device to be used
for Nordic BLE.
config NBLE_UART_IRQ
int "IRQ of UART Device for Nordic BLE"
depends on NBLE
help
This option specifies the IRQ of UART device to be used
for Nordic BLE.
config NBLE_UART_IRQ_PRI
int "IRQ Priority of UART Device for Nordic BLE"
depends on NBLE
help
This option specifies the IRQ priority of UART device to be used
for Nordic BLE.
endif

View file

@ -125,7 +125,7 @@ static size_t nble_discard(struct device *uart, size_t len)
return uart_fifo_read(uart, buf, min(len, sizeof(buf)));
}
void bt_uart_isr(void *unused)
static void bt_uart_isr(struct device *unused)
{
static struct net_buf *buf;
@ -206,10 +206,6 @@ int nble_open(void)
uart_irq_rx_disable(nble_dev);
uart_irq_tx_disable(nble_dev);
IRQ_CONNECT(CONFIG_NBLE_UART_IRQ, CONFIG_NBLE_UART_IRQ_PRI,
bt_uart_isr, 0, UART_IRQ_FLAGS);
irq_enable(CONFIG_NBLE_UART_IRQ);
/* Drain the fifo */
while (uart_irq_rx_ready(nble_dev)) {
unsigned char c;
@ -217,6 +213,8 @@ int nble_open(void)
uart_fifo_read(nble_dev, &c, 1);
}
uart_irq_callback_set(nble_dev, bt_uart_isr);
uart_irq_rx_enable(nble_dev);
return 0;