esp32: drivers: interrupt_controller: review UART interrupt usage

Review UART interrupt allocation usage.

Signed-off-by: Glauber Maroto Ferreira <glauber.ferreira@espressif.com>
This commit is contained in:
Glauber Maroto Ferreira 2021-06-09 19:52:31 -03:00 committed by Christopher Friedt
commit 57bf89d65e
2 changed files with 19 additions and 44 deletions

View file

@ -18,6 +18,7 @@
#include <device.h> #include <device.h>
#include <soc.h> #include <soc.h>
#include <drivers/uart.h> #include <drivers/uart.h>
#include <drivers/interrupt_controller/intc_esp32.h>
#include <drivers/clock_control.h> #include <drivers/clock_control.h>
#include <errno.h> #include <errno.h>
#include <sys/util.h> #include <sys/util.h>
@ -83,10 +84,7 @@ struct uart_esp32_config {
const clock_control_subsys_t clock_subsys; const clock_control_subsys_t clock_subsys;
const struct { int irq_source;
int source;
int line;
} irq;
}; };
/* driver data */ /* driver data */
@ -96,6 +94,7 @@ struct uart_esp32_data {
uart_irq_callback_user_data_t irq_cb; uart_irq_callback_user_data_t irq_cb;
void *irq_cb_data; void *irq_cb_data;
#endif #endif
int irq_line;
}; };
#define DEV_CFG(dev) \ #define DEV_CFG(dev) \
@ -131,6 +130,10 @@ struct uart_esp32_data {
#define DPORT_UART0_CLK_EN DPORT_UART_CLK_EN #define DPORT_UART0_CLK_EN DPORT_UART_CLK_EN
#define DPORT_UART0_RST DPORT_UART_RST #define DPORT_UART0_RST DPORT_UART_RST
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
void uart_esp32_isr(void *arg);
#endif
static int uart_esp32_poll_in(const struct device *dev, unsigned char *p_char) static int uart_esp32_poll_in(const struct device *dev, unsigned char *p_char)
{ {
@ -322,7 +325,8 @@ static int uart_esp32_init(const struct device *dev)
uart_esp32_configure(dev, &DEV_DATA(dev)->uart_config); uart_esp32_configure(dev, &DEV_DATA(dev)->uart_config);
#ifdef CONFIG_UART_INTERRUPT_DRIVEN #ifdef CONFIG_UART_INTERRUPT_DRIVEN
DEV_CFG(dev)->dev_conf.irq_config_func(dev); DEV_DATA(dev)->irq_line =
esp_intr_alloc(DEV_CFG(dev)->irq_source, 0, uart_esp32_isr, (void *)dev, NULL);
#endif #endif
return 0; return 0;
} }
@ -428,8 +432,9 @@ static void uart_esp32_irq_callback_set(const struct device *dev,
DEV_DATA(dev)->irq_cb_data = cb_data; DEV_DATA(dev)->irq_cb_data = cb_data;
} }
void uart_esp32_isr(const struct device *dev) void uart_esp32_isr(void *arg)
{ {
const struct device *dev = (const struct device *)arg;
struct uart_esp32_data *data = DEV_DATA(dev); struct uart_esp32_data *data = DEV_DATA(dev);
/* Verify if the callback has been registered */ /* Verify if the callback has been registered */
@ -466,39 +471,11 @@ static const DRAM_ATTR struct uart_driver_api uart_esp32_api = {
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */ #endif /* CONFIG_UART_INTERRUPT_DRIVEN */
}; };
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
#define ESP32_UART_IRQ_HANDLER_DECL(idx) \
static void uart_esp32_irq_config_func_##idx(const struct device *dev)
#define ESP32_UART_IRQ_HANDLER_FUNC(idx) \
.irq_config_func = uart_esp32_irq_config_func_##idx,
#define ESP32_UART_IRQ_HANDLER(idx) \
static void uart_esp32_irq_config_func_##idx(const struct device *dev) \
{ \
esp32_rom_intr_matrix_set(0, ETS_UART##idx##_INTR_SOURCE, \
INST_##idx##_ESPRESSIF_ESP32_UART_IRQ_0); \
IRQ_CONNECT(INST_##idx##_ESPRESSIF_ESP32_UART_IRQ_0, \
1, \
uart_esp32_isr, \
DEVICE_DT_INST_GET(idx), \
0); \
irq_enable(INST_##idx##_ESPRESSIF_ESP32_UART_IRQ_0); \
}
#else
#define ESP32_UART_IRQ_HANDLER_DECL(idx)
#define ESP32_UART_IRQ_HANDLER_FUNC(idx)
#define ESP32_UART_IRQ_HANDLER(idx)
#endif
#define ESP32_UART_INIT(idx) \ #define ESP32_UART_INIT(idx) \
ESP32_UART_IRQ_HANDLER_DECL(idx); \
static const DRAM_ATTR struct uart_esp32_config uart_esp32_cfg_port_##idx = { \ static const DRAM_ATTR struct uart_esp32_config uart_esp32_cfg_port_##idx = { \
.dev_conf = { \ .dev_conf = { \
.base = \ .base = \
(uint8_t *)DT_REG_ADDR(DT_NODELABEL(uart##idx)), \ (uint8_t *)DT_REG_ADDR(DT_NODELABEL(uart##idx)), \
ESP32_UART_IRQ_HANDLER_FUNC(idx) \
}, \ }, \
\ \
.clock_dev = DEVICE_DT_GET(DT_CLOCKS_CTLR(DT_NODELABEL(uart##idx))), \ .clock_dev = DEVICE_DT_GET(DT_CLOCKS_CTLR(DT_NODELABEL(uart##idx))), \
@ -521,10 +498,7 @@ static const DRAM_ATTR struct uart_esp32_config uart_esp32_cfg_port_##idx = {
}, \ }, \
\ \
.clock_subsys = (clock_control_subsys_t)DT_CLOCKS_CELL(DT_NODELABEL(uart##idx), offset), \ .clock_subsys = (clock_control_subsys_t)DT_CLOCKS_CELL(DT_NODELABEL(uart##idx), offset), \
.irq = { \ .irq_source = DT_IRQN(DT_NODELABEL(uart##idx)) \
.source = ETS_UART##idx##_INTR_SOURCE, \
.line = INST_##idx##_ESPRESSIF_ESP32_UART_IRQ_0, \
} \
}; \ }; \
\ \
static struct uart_esp32_data uart_esp32_data_##idx = { \ static struct uart_esp32_data uart_esp32_data_##idx = { \
@ -546,9 +520,7 @@ DEVICE_DT_DEFINE(DT_NODELABEL(uart##idx), \
&uart_esp32_cfg_port_##idx, \ &uart_esp32_cfg_port_##idx, \
PRE_KERNEL_1, \ PRE_KERNEL_1, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&uart_esp32_api); \ &uart_esp32_api);
\
ESP32_UART_IRQ_HANDLER(idx)
#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay) #if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay)
ESP32_UART_INIT(0); ESP32_UART_INIT(0);

View file

@ -87,7 +87,8 @@
uart0: uart@3ff40000 { uart0: uart@3ff40000 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
reg = <0x3ff40000 0x400>; reg = <0x3ff40000 0x400>;
/* interrupts = <12>; - FIXME: Enable interrupts when interrupt-controller got supported in device tree */ interrupts = <UART0_INTR_SOURCE>;
interrupt-parent = <&intc>;
label = "UART_0"; label = "UART_0";
clocks = <&rtc ESP32_UART0_MODULE>; clocks = <&rtc ESP32_UART0_MODULE>;
status = "disabled"; status = "disabled";
@ -96,7 +97,8 @@
uart1: uart@3ff50000 { uart1: uart@3ff50000 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
reg = <0x3ff50000 0x400>; reg = <0x3ff50000 0x400>;
/* interrupts = <17>; - FIXME: Enable interrupts when interrupt-controller got supported in device tree */ interrupts = <UART1_INTR_SOURCE>;
interrupt-parent = <&intc>;
label = "UART_1"; label = "UART_1";
clocks = <&rtc ESP32_UART1_MODULE>; clocks = <&rtc ESP32_UART1_MODULE>;
status = "disabled"; status = "disabled";
@ -105,7 +107,8 @@
uart2: uart@3ff6e000 { uart2: uart@3ff6e000 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
reg = <0x3ff6E000 0x400>; reg = <0x3ff6E000 0x400>;
/* interrupts = <18>; - FIXME: Enable interrupts when interrupt-controller got supported in device tree */ interrupts = <UART2_INTR_SOURCE>;
interrupt-parent = <&intc>;
label = "UART_2"; label = "UART_2";
clocks = <&rtc ESP32_UART2_MODULE>; clocks = <&rtc ESP32_UART2_MODULE>;
status = "disabled"; status = "disabled";