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

@ -148,10 +148,6 @@ if UART_CONSOLE
config UART_CONSOLE_ON_DEV_NAME
default "UART_0"
config UART_CONSOLE_IRQ
default 8
config UART_CONSOLE_IRQ_PRI
default 3
endif # UART_CONSOLE

View file

@ -32,11 +32,6 @@
#include <toolchain.h>
#include <sections.h>
#if defined(CONFIG_CONSOLE_HANDLER)
#include <soc.h>
#include <console/uart_console.h>
#endif /* CONFIG_CONSOLE_HANDLER */
extern void _isr_wrapper(void);
typedef void (*vth)(void); /* Vector Table Handler */
@ -50,20 +45,9 @@ vth __irq_vector_table _irq_vector_table[CONFIG_NUM_IRQS] = {
extern void _irq_spurious(void);
#if defined(CONFIG_CONSOLE_HANDLER)
static void _uart_console_isr(void)
{
uart_console_isr(NULL);
_IntExit();
}
#endif /* CONFIG_CONSOLE_HANDLER */
/* placeholders: fill with real ISRs */
vth __irq_vector_table _irq_vector_table[CONFIG_NUM_IRQS] = {
[0 ...(CONFIG_NUM_IRQS - 1)] = _irq_spurious,
#if defined(CONFIG_CONSOLE_HANDLER)
[CONFIG_UART_CONSOLE_IRQ] = _uart_console_isr,
#endif
};
#endif /* CONFIG_SW_ISR_TABLE */

View file

@ -141,10 +141,6 @@ if UART_CONSOLE
config UART_CONSOLE_ON_DEV_NAME
default "UART_0"
config UART_CONSOLE_IRQ
default 31
config UART_CONSOLE_IRQ_PRI
default 3
endif
@ -152,10 +148,6 @@ if BLUETOOTH_UART
config BLUETOOTH_UART_ON_DEV_NAME
default "UART_1"
config BLUETOOTH_UART_IRQ
default 33
config BLUETOOTH_UART_IRQ_PRI
default 3
endif

View file

@ -31,15 +31,8 @@
#include <toolchain.h>
#include <sections.h>
#if defined(CONFIG_CONSOLE_HANDLER)
#include <soc.h>
#include <console/uart_console.h>
#endif /* CONFIG_CONSOLE_HANDLER */
#if defined(CONFIG_BLUETOOTH_UART)
#include <soc.h>
#include <bluetooth/uart.h>
#endif /* CONFIG_BLUETOOTH_UART */
#include <serial/uart_k20.h>
extern void _isr_wrapper(void);
typedef void (*vth)(void); /* Vector Table Handler */
@ -54,10 +47,34 @@ vth __irq_vector_table _irq_vector_table[CONFIG_NUM_IRQS] = {
extern void _irq_spurious(void);
#if defined(CONFIG_CONSOLE_HANDLER)
static void _uart_console_isr(void)
#if defined(CONFIG_UART_INTERRUPT_DRIVEN)
static void _uart_k20_0_isr(void)
{
uart_console_isr(NULL);
uart_k20_isr(DEVICE_GET(uart_k20_0));
_IntExit();
}
static void _uart_k20_1_isr(void)
{
uart_k20_isr(DEVICE_GET(uart_k20_1));
_IntExit();
}
static void _uart_k20_2_isr(void)
{
uart_k20_isr(DEVICE_GET(uart_k20_2));
_IntExit();
}
static void _uart_k20_3_isr(void)
{
uart_k20_isr(DEVICE_GET(uart_k20_3));
_IntExit();
}
static void _uart_k20_4_isr(void)
{
uart_k20_isr(DEVICE_GET(uart_k20_4));
_IntExit();
}
#endif /* CONFIG_CONSOLE_HANDLER */
@ -73,11 +90,13 @@ static void _bt_uart_isr(void)
/* placeholders: fill with real ISRs */
vth __irq_vector_table _irq_vector_table[CONFIG_NUM_IRQS] = {
[0 ...(CONFIG_NUM_IRQS - 1)] = _irq_spurious,
#if defined(CONFIG_CONSOLE_HANDLER)
[CONFIG_UART_CONSOLE_IRQ] = _uart_console_isr,
#endif
#if defined(CONFIG_BLUETOOTH_UART)
[CONFIG_BLUETOOTH_UART_IRQ] = _bt_uart_isr,
#if defined(CONFIG_UART_INTERRUPT_DRIVEN)
[CONFIG_UART_K20_PORT_0_IRQ] = _uart_k20_0_isr,
[CONFIG_UART_K20_PORT_1_IRQ] = _uart_k20_1_isr,
[CONFIG_UART_K20_PORT_2_IRQ] = _uart_k20_2_isr,
[CONFIG_UART_K20_PORT_3_IRQ] = _uart_k20_3_isr,
[CONFIG_UART_K20_PORT_4_IRQ] = _uart_k20_4_isr,
#endif
};

View file

@ -66,7 +66,9 @@ if UART_STELLARIS_PORT_0
config UART_STELLARIS_PORT_0_BASE_ADDR
default 0x4000C000
config UART_STELLARIS_PORT_0_IRQ
default 6
default 5
config UART_STELLARIS_PORT_0_IRQ_PRI
default 3
config UART_STELLARIS_PORT_0_BAUD_RATE
default 115200
config UART_STELLARIS_PORT_0_CLK_FREQ
@ -81,6 +83,8 @@ config UART_STELLARIS_PORT_1_BASE_ADDR
default 0x4000D000
config UART_STELLARIS_PORT_1_IRQ
default 6
config UART_STELLARIS_PORT_1_IRQ_PRI
default 3
config UART_STELLARIS_PORT_1_BAUD_RATE
default 115200
config UART_STELLARIS_PORT_1_CLK_FREQ
@ -94,6 +98,8 @@ config UART_STELLARIS_PORT_2_BASE_ADDR
default 0x4000E000
config UART_STELLARIS_PORT_2_IRQ
default 33
config UART_STELLARIS_PORT_2_IRQ_PRI
default 3
config UART_STELLARIS_PORT_2_BAUD_RATE
default 115200
config UART_STELLARIS_PORT_2_CLK_FREQ
@ -106,10 +112,6 @@ if UART_CONSOLE
config UART_CONSOLE_ON_DEV_NAME
default "UART_0"
config UART_CONSOLE_IRQ
default 5
config UART_CONSOLE_IRQ_PRI
default 3
endif
@ -117,10 +119,6 @@ if BLUETOOTH_UART
config BLUETOOTH_UART_ON_DEV_NAME
default "UART_1"
config BLUETOOTH_UART_IRQ
default 6
config BLUETOOTH_UART_IRQ_PRI
default 3
endif
@ -128,10 +126,6 @@ if UART_PIPE
config UART_PIPE_ON_DEV_NAME
default "UART_2"
config UART_PIPE_IRQ
default 33
config UART_PIPE_IRQ_PRI
default 3
endif

View file

@ -31,15 +31,8 @@
#include <toolchain.h>
#include <sections.h>
#if defined(CONFIG_CONSOLE_HANDLER)
#include <soc.h>
#include <console/uart_console.h>
#endif /* CONFIG_CONSOLE_HANDLER */
#if defined(CONFIG_BLUETOOTH_UART)
#include <soc.h>
#include <bluetooth/uart.h>
#endif /* CONFIG_BLUETOOTH_UART */
#include <serial/uart_stellaris.h>
extern void _isr_wrapper(void);
typedef void (*vth)(void); /* Vector Table Handler */
@ -54,30 +47,34 @@ vth __irq_vector_table _irq_vector_table[CONFIG_NUM_IRQS] = {
extern void _irq_spurious(void);
#if defined(CONFIG_CONSOLE_HANDLER)
static void _uart_console_isr(void)
#if defined(CONFIG_UART_INTERRUPT_DRIVEN)
static void _uart_stellaris_port_0_isr(void)
{
uart_console_isr(NULL);
uart_stellaris_isr(DEVICE_GET(uart_stellaris0));
_IntExit();
}
#endif /* CONFIG_CONSOLE_HANDLER */
#if defined(CONFIG_BLUETOOTH_UART)
static void _bt_uart_isr(void)
static void _uart_stellaris_port_1_isr(void)
{
bt_uart_isr(NULL);
uart_stellaris_isr(DEVICE_GET(uart_stellaris1));
_IntExit();
}
#endif /* CONFIG_BLUETOOTH_UART */
static void _uart_stellaris_port_2_isr(void)
{
uart_stellaris_isr(DEVICE_GET(uart_stellaris2));
_IntExit();
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
/* placeholders: fill with real ISRs */
vth __irq_vector_table _irq_vector_table[CONFIG_NUM_IRQS] = {
[0 ...(CONFIG_NUM_IRQS - 1)] = _irq_spurious,
#if defined(CONFIG_CONSOLE_HANDLER)
[CONFIG_UART_CONSOLE_IRQ] = _uart_console_isr,
#endif
#if defined(CONFIG_BLUETOOTH_UART)
[CONFIG_BLUETOOTH_UART_IRQ] = _bt_uart_isr,
#if defined(CONFIG_UART_INTERRUPT_DRIVEN)
[UART_STELLARIS_PORT_0_IRQ] = _uart_stellaris_port_0_isr,
[UART_STELLARIS_PORT_1_IRQ] = _uart_stellaris_port_1_isr,
[UART_STELLARIS_PORT_2_IRQ] = _uart_stellaris_port_2_isr,
#endif
};