Skip to content

Commit

Permalink
irq: esp32: Interrupts flags configuration
Browse files Browse the repository at this point in the history
Allows configuring special flags for interrupts

Signed-off-by: Raffael Rostagno <[email protected]>
  • Loading branch information
Raffael Rostagno committed Jul 3, 2024
1 parent 1462ed7 commit 8330c10
Show file tree
Hide file tree
Showing 32 changed files with 250 additions and 140 deletions.
5 changes: 4 additions & 1 deletion drivers/can/can_esp32_twai.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct can_esp32_twai_config {
const clock_control_subsys_t clock_subsys;
int irq_source;
int irq_priority;
int irq_flags;
#ifndef CONFIG_SOC_SERIES_ESP32
/* 32-bit variant of output clock divider register required for non-ESP32 MCUs */
uint32_t cdr32;
Expand Down Expand Up @@ -204,7 +205,8 @@ static int can_esp32_twai_init(const struct device *dev)
#endif /* !CONFIG_SOC_SERIES_ESP32 */

err = esp_intr_alloc(twai_config->irq_source,
esp_intr_level_to_flags(twai_config->irq_priority) | ESP_INTR_FLAG_IRAM,
esp_intr_level_to_flags(twai_config->irq_priority) |
esp_intr_flags_check(twai_config->irq_flags) | ESP_INTR_FLAG_IRAM,
can_esp32_twai_isr, (void *)dev, NULL);

if (err != 0) {
Expand Down Expand Up @@ -280,6 +282,7 @@ const struct can_driver_api can_esp32_twai_driver_api = {
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.irq_source = DT_INST_IRQ_BY_IDX(inst, 0, irq), \
.irq_priority = DT_INST_IRQ_BY_IDX(inst, 0, priority), \
.irq_flags = DT_INST_IRQ_BY_IDX(inst, 0, flags), \
TWAI_CDR32_INIT(inst) \
}; \
CAN_ESP32_TWAI_ASSERT_CLKOUT_DIVIDER(inst); \
Expand Down
8 changes: 5 additions & 3 deletions drivers/counter/counter_esp32_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct counter_esp32_config {
struct counter_config_info counter_info;
int irq_source;
int irq_priority;
int irq_flags;
const struct device *clock_dev;
};

Expand All @@ -57,14 +58,14 @@ static int counter_esp32_init(const struct device *dev)
const struct counter_esp32_config *cfg = dev->config;
struct counter_esp32_data *data = dev->data;


/* RTC_SLOW_CLK is the default clk source */
clock_control_get_rate(cfg->clock_dev,
(clock_control_subsys_t)ESP32_CLOCK_CONTROL_SUBSYS_RTC_SLOW,
&data->clk_src_freq);

int ret = esp_intr_alloc(cfg->irq_source,
esp_intr_level_to_flags(cfg->irq_priority),
esp_intr_level_to_flags(cfg->irq_priority) |
esp_intr_flags_check(cfg->irq_flags),
(ESP32_COUNTER_RTC_ISR_HANDLER)counter_esp32_isr,
(void *)dev,
NULL);
Expand Down Expand Up @@ -205,7 +206,8 @@ static const struct counter_esp32_config counter_config = {
},
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0)),
.irq_source = DT_INST_IRQ_BY_IDX(0, 0, irq),
.irq_priority = DT_INST_IRQ_BY_IDX(0, 0, priority)
.irq_priority = DT_INST_IRQ_BY_IDX(0, 0, priority),
.irq_flags = DT_INST_IRQ_BY_IDX(0, 0, flags)
};

static const struct counter_driver_api rtc_timer_esp32_api = {
Expand Down
7 changes: 5 additions & 2 deletions drivers/counter/counter_esp32_tmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct counter_esp32_config {
timer_idx_t index;
int irq_source;
int irq_priority;
int irq_flags;
};

struct counter_esp32_data {
Expand Down Expand Up @@ -97,7 +98,8 @@ static int counter_esp32_init(const struct device *dev)
k_spin_unlock(&lock, key);

int ret = esp_intr_alloc(cfg->irq_source,
esp_intr_level_to_flags(cfg->irq_priority),
esp_intr_level_to_flags(cfg->irq_priority) |
esp_intr_flags_check(cfg->irq_flags),
(ISR_HANDLER)counter_esp32_isr, (void *)dev, NULL);

if (ret != 0) {
Expand Down Expand Up @@ -262,7 +264,8 @@ static void counter_esp32_isr(void *arg)
.group = DT_INST_PROP(idx, group), \
.index = DT_INST_PROP(idx, index), \
.irq_source = DT_INST_IRQ_BY_IDX(idx, 0, irq), \
.irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority) \
.irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority), \
.irq_flags = DT_INST_IRQ_BY_IDX(idx, 0, flags) \
}; \
\
\
Expand Down
19 changes: 11 additions & 8 deletions drivers/dma/dma_esp32_gdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum dma_channel_dir {
struct irq_config {
uint8_t irq_source;
uint8_t irq_priority;
int irq_flags;
};

struct dma_esp32_channel {
Expand Down Expand Up @@ -454,15 +455,15 @@ static int dma_esp32_configure_irq(const struct device *dev)

for (uint8_t i = 0; i < config->irq_size; i++) {
int ret = esp_intr_alloc(irq_cfg[i].irq_source,
esp_intr_level_to_flags(irq_cfg[i].irq_priority) |
ESP_INTR_FLAG_IRAM,
esp_intr_level_to_flags(irq_cfg[i].irq_priority) |
esp_intr_flags_check(irq_cfg[i].irq_flags) | ESP_INTR_FLAG_IRAM,
#if defined(CONFIG_SOC_SERIES_ESP32S3)
(ISR_HANDLER)config->irq_handlers[i / 2],
(ISR_HANDLER)config->irq_handlers[i / 2],
#else
(ISR_HANDLER)config->irq_handlers[i],
(ISR_HANDLER)config->irq_handlers[i],
#endif
(void *)dev,
NULL);
(void *)dev,
NULL);
if (ret != 0) {
LOG_ERR("Could not allocate interrupt handler");
return ret;
Expand Down Expand Up @@ -546,8 +547,10 @@ static void *irq_handlers[] = {
};

#define IRQ_NUM(idx) DT_NUM_IRQS(DT_DRV_INST(idx))
#define IRQ_ENTRY(n, idx) \
{ DT_INST_IRQ_BY_IDX(idx, n, irq), DT_INST_IRQ_BY_IDX(idx, n, priority) },
#define IRQ_ENTRY(n, idx) { \
DT_INST_IRQ_BY_IDX(idx, n, irq), \
DT_INST_IRQ_BY_IDX(idx, n, priority), \
DT_INST_IRQ_BY_IDX(idx, n, flags) },

#define DMA_ESP32_INIT(idx) \
static struct irq_config irq_config_##idx[] = { \
Expand Down
1 change: 1 addition & 0 deletions drivers/ethernet/eth_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ int eth_esp32_initialize(const struct device *dev)
/* Configure ISR */
res = esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(eth), 0, irq),
esp_intr_level_to_flags(DT_IRQ_BY_IDX(DT_NODELABEL(eth), 0, priority)) |
esp_intr_flags_check(DT_IRQ_BY_IDX(DT_NODELABEL(eth), 0, flags)) |
ESP_INTR_FLAG_IRAM,
eth_esp32_isr,
(void *)dev,
Expand Down
3 changes: 2 additions & 1 deletion drivers/gpio/gpio_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ static int gpio_esp32_init(const struct device *dev)

if (!isr_connected) {
int ret = esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, irq),
esp_intr_level_to_flags(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, priority)),
esp_intr_level_to_flags(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, priority)) |
esp_intr_flags_check(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, flags)),
(ISR_HANDLER)gpio_esp32_isr,
(void *)dev,
NULL);
Expand Down
5 changes: 4 additions & 1 deletion drivers/i2c/i2c_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct i2c_esp32_config {

int irq_source;
int irq_priority;
int irq_flags;

const uint32_t bitrate;
const uint32_t scl_timeout;
Expand Down Expand Up @@ -766,7 +767,8 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev)
clock_control_on(config->clock_dev, config->clock_subsys);

ret = esp_intr_alloc(config->irq_source,
esp_intr_level_to_flags(config->irq_priority) | ESP_INTR_FLAG_IRAM,
esp_intr_level_to_flags(config->irq_priority) |
esp_intr_flags_check(config->irq_flags) | ESP_INTR_FLAG_IRAM,
i2c_esp32_isr,
(void *)dev,
NULL);
Expand Down Expand Up @@ -837,6 +839,7 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev)
}, \
.irq_source = DT_INST_IRQ_BY_IDX(idx, 0, irq), \
.irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority), \
.irq_flags = DT_INST_IRQ_BY_IDX(idx, 0, flags), \
.bitrate = I2C_FREQUENCY(idx), \
.scl_timeout = I2C_ESP32_TIMEOUT(idx), \
}; \
Expand Down
4 changes: 3 additions & 1 deletion drivers/input/input_esp32_touch_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ static esp_err_t esp32_rtc_isr_install(intr_handler_t intr_handler, const void *
REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX);

err = esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(touch), 0, irq),
DT_IRQ_BY_IDX(DT_NODELABEL(touch), 0, priority),
esp_intr_level_to_flags(
DT_IRQ_BY_IDX(DT_NODELABEL(touch), 0, priority)) |
esp_intr_flags_check(DT_IRQ_BY_IDX(DT_NODELABEL(touch), 0, flags)),
intr_handler, (void *)handler_arg, NULL);

return err;
Expand Down
6 changes: 6 additions & 0 deletions drivers/ipm/ipm_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ struct esp32_ipm_memory {
struct esp32_ipm_config {
int irq_source_pro_cpu;
int irq_priority_pro_cpu;
int irq_flags_pro_cpu;
int irq_source_app_cpu;
int irq_priority_app_cpu;
int irq_flags_app_cpu;
};

struct esp32_ipm_data {
Expand Down Expand Up @@ -221,6 +223,7 @@ static int esp32_ipm_init(const struct device *dev)
if (data->this_core_id == 0) {
ret = esp_intr_alloc(cfg->irq_source_pro_cpu,
esp_intr_level_to_flags(cfg->irq_priority_pro_cpu) |
esp_intr_flags_check(cfg->irq_flags_pro_cpu) |
ESP_INTR_FLAG_IRAM,
(intr_handler_t)esp32_ipm_isr,
(void *)dev,
Expand All @@ -238,6 +241,7 @@ static int esp32_ipm_init(const struct device *dev)
*/
ret = esp_intr_alloc(cfg->irq_source_app_cpu,
esp_intr_level_to_flags(cfg->irq_priority_app_cpu) |
esp_intr_flags_check(cfg->irq_flags_app_cpu) |
ESP_INTR_FLAG_IRAM,
(intr_handler_t)esp32_ipm_isr,
(void *)dev,
Expand Down Expand Up @@ -281,8 +285,10 @@ static const struct ipm_driver_api esp32_ipm_driver_api = {
static struct esp32_ipm_config esp32_ipm_device_cfg_##idx = { \
.irq_source_pro_cpu = DT_INST_IRQ_BY_IDX(idx, 0, irq), \
.irq_priority_pro_cpu = DT_INST_IRQ_BY_IDX(idx, 0, priority), \
.irq_flags_pro_cpu = DT_INST_IRQ_BY_IDX(idx, 0, flags), \
.irq_source_app_cpu = DT_INST_IRQ_BY_IDX(idx, 1, irq), \
.irq_priority_app_cpu = DT_INST_IRQ_BY_IDX(idx, 1, priority), \
.irq_flags_app_cpu = DT_INST_IRQ_BY_IDX(idx, 1, flags), \
}; \
\
static struct esp32_ipm_data esp32_ipm_device_data_##idx = { \
Expand Down
4 changes: 3 additions & 1 deletion drivers/pwm/pwm_mc_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ static const struct pwm_driver_api mcpwm_esp32_api = {
{ \
int ret; \
ret = esp_intr_alloc(DT_INST_IRQ_BY_IDX(idx, 0, irq), \
DT_INST_IRQ_BY_IDX(idx, 0, priority) | ESP_INTR_FLAG_IRAM, \
esp_intr_level_to_flags(DT_INST_IRQ_BY_IDX(idx, 0, priority)) | \
esp_intr_flags_check(DT_INST_IRQ_BY_IDX(idx, 0, flags)) | \
ESP_INTR_FLAG_IRAM, \
(intr_handler_t)mcpwm_esp32_isr, (void *)dev, NULL); \
return ret; \
}
Expand Down
5 changes: 4 additions & 1 deletion drivers/sdhc/sdhc_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct sdhc_esp32_config {

int irq_source;
int irq_priority;
int irq_flags;
uint8_t bus_width_cfg;

struct sdhc_host_props props;
Expand Down Expand Up @@ -1342,7 +1343,8 @@ static int sdhc_esp32_init(const struct device *dev)

/* Attach interrupt handler */
ret = esp_intr_alloc(cfg->irq_source,
esp_intr_level_to_flags(cfg->irq_priority) | ESP_INTR_FLAG_IRAM,
esp_intr_level_to_flags(cfg->irq_priority) |
esp_intr_flags_check(cfg->irq_flags) | ESP_INTR_FLAG_IRAM,
&sdio_esp32_isr, (void *)dev,
&data->s_host_ctx.intr_handle);

Expand Down Expand Up @@ -1411,6 +1413,7 @@ static const struct sdhc_driver_api sdhc_api = {.reset = sdhc_esp32_reset,
.sdio_hw = (const sdmmc_dev_t *)DT_REG_ADDR(DT_INST_PARENT(n)), \
.irq_source = DT_IRQ_BY_IDX(DT_INST_PARENT(n), 0, irq), \
.irq_priority = DT_IRQ_BY_IDX(DT_INST_PARENT(n), 0, priority), \
.irq_flags = DT_IRQ_BY_IDX(DT_INST_PARENT(n), 0, flags), \
.slot = DT_REG_ADDR(DT_DRV_INST(n)), \
.bus_width_cfg = DT_INST_PROP(n, bus_width), \
.pcfg = PINCTRL_DT_DEV_CONFIG_GET(DT_DRV_INST(n)), \
Expand Down
5 changes: 4 additions & 1 deletion drivers/sensor/espressif/pcnt_esp32/pcnt_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct pcnt_esp32_config {
const clock_control_subsys_t clock_subsys;
const int irq_source;
const int irq_priority;
const int irq_flags;
struct pcnt_esp32_unit_config *unit_config;
const int unit_len;
};
Expand Down Expand Up @@ -342,7 +343,8 @@ static int pcnt_esp32_trigger_set(const struct device *dev, const struct sensor_
data->trigger = trig;

ret = esp_intr_alloc(config->irq_source,
esp_intr_level_to_flags(config->irq_priority) | ESP_INTR_FLAG_IRAM,
esp_intr_level_to_flags(config->irq_priority) |
esp_intr_flags_check(config->irq_flags) | ESP_INTR_FLAG_IRAM,
(intr_handler_t)pcnt_esp32_isr, (void *)dev, NULL);

if (ret != 0) {
Expand Down Expand Up @@ -405,6 +407,7 @@ static struct pcnt_esp32_config pcnt_esp32_config = {
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(0, offset),
.irq_source = DT_INST_IRQ_BY_IDX(0, 0, irq),
.irq_priority = DT_INST_IRQ_BY_IDX(0, 0, priority),
.irq_flags = DT_INST_IRQ_BY_IDX(0, 0, flags),
.unit_config = unit_config,
.unit_len = ARRAY_SIZE(unit_config),
};
Expand Down
7 changes: 5 additions & 2 deletions drivers/serial/serial_esp32_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct serial_esp32_usb_config {
const clock_control_subsys_t clock_subsys;
int irq_source;
int irq_priority;
int irq_flags;
};

struct serial_esp32_usb_data {
Expand Down Expand Up @@ -113,7 +114,8 @@ static int serial_esp32_usb_init(const struct device *dev)

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
ret = esp_intr_alloc(config->irq_source,
esp_intr_level_to_flags(config->irq_priority),
esp_intr_level_to_flags(config->irq_priority) |
esp_intr_flags_check(config->irq_flags),
(ISR_HANDLER)serial_esp32_usb_isr,
(void *)dev, NULL);
#endif
Expand Down Expand Up @@ -276,7 +278,8 @@ static const DRAM_ATTR struct serial_esp32_usb_config serial_esp32_usb_cfg = {
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0)),
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(0, offset),
.irq_source = DT_INST_IRQ_BY_IDX(0, 0, irq),
.irq_priority = DT_INST_IRQ_BY_IDX(0, 0, priority)
.irq_priority = DT_INST_IRQ_BY_IDX(0, 0, priority),
.irq_flags = DT_INST_IRQ_BY_IDX(0, 0, flags)
};

static struct serial_esp32_usb_data serial_esp32_usb_data_0;
Expand Down
5 changes: 4 additions & 1 deletion drivers/serial/uart_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct uart_esp32_config {
const clock_control_subsys_t clock_subsys;
int irq_source;
int irq_priority;
int irq_flags;
bool tx_invert;
bool rx_invert;
#if CONFIG_UART_ASYNC_API
Expand Down Expand Up @@ -929,7 +930,8 @@ static int uart_esp32_init(const struct device *dev)

#if CONFIG_UART_INTERRUPT_DRIVEN || CONFIG_UART_ASYNC_API
ret = esp_intr_alloc(config->irq_source,
esp_intr_level_to_flags(config->irq_priority),
esp_intr_level_to_flags(config->irq_priority) |
esp_intr_flags_check(config->irq_flags),
(ISR_HANDLER)uart_esp32_isr,
(void *)dev,
NULL);
Expand Down Expand Up @@ -1016,6 +1018,7 @@ static const DRAM_ATTR struct uart_driver_api uart_esp32_api = {
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(idx, offset), \
.irq_source = DT_INST_IRQ_BY_IDX(idx, 0, irq), \
.irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority), \
.irq_flags = DT_INST_IRQ_BY_IDX(idx, 0, flags), \
.tx_invert = DT_INST_PROP_OR(idx, tx_invert, false), \
.rx_invert = DT_INST_PROP_OR(idx, rx_invert, false), \
ESP_UART_DMA_INIT(idx)}; \
Expand Down
4 changes: 3 additions & 1 deletion drivers/spi/spi_esp32_spim.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ static int spi_esp32_init(const struct device *dev)
spi_ll_clear_int_stat(cfg->spi);

err = esp_intr_alloc(cfg->irq_source,
esp_intr_level_to_flags(cfg->irq_priority) | ESP_INTR_FLAG_IRAM,
esp_intr_level_to_flags(cfg->irq_priority) |
esp_intr_flags_check(cfg->irq_flags) | ESP_INTR_FLAG_IRAM,
(ISR_HANDLER)spi_esp32_isr,
(void *)dev,
NULL);
Expand Down Expand Up @@ -532,6 +533,7 @@ static const struct spi_driver_api spi_api = {
.input_delay_ns = 0, \
.irq_source = DT_INST_IRQ_BY_IDX(idx, 0, irq), \
.irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority), \
.irq_flags = DT_INST_IRQ_BY_IDX(idx, 0, flags), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
.clock_subsys = \
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(idx, offset), \
Expand Down
1 change: 1 addition & 0 deletions drivers/spi/spi_esp32_spim.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct spi_esp32_config {
int input_delay_ns;
int irq_source;
int irq_priority;
int irq_flags;
const struct pinctrl_dev_config *pcfg;
clock_control_subsys_t clock_subsys;
bool use_iomux;
Expand Down
3 changes: 2 additions & 1 deletion drivers/timer/esp32_sys_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ static int sys_clock_driver_init(void)
int ret;

ret = esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(systimer0), 0, irq),
esp_intr_level_to_flags(DT_IRQ_BY_IDX(DT_NODELABEL(systimer0), 0, priority)),
esp_intr_level_to_flags(DT_IRQ_BY_IDX(DT_NODELABEL(systimer0), 0, priority)) |
esp_intr_flags_check(DT_IRQ_BY_IDX(DT_NODELABEL(systimer0), 0, flags)),
sys_timer_isr,
NULL,
NULL);
Expand Down
Loading

0 comments on commit 8330c10

Please sign in to comment.