drivers: esp32: esp_intr_alloc return condition
Add checks to return value of esp_intr_alloc to avoid drivers init returning 0 when interrupt allocation fails. Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
This commit is contained in:
parent
0b3a34cdca
commit
bb746cdcc5
11 changed files with 99 additions and 38 deletions
|
|
@ -203,11 +203,15 @@ static int can_esp32_twai_init(const struct device *dev)
|
|||
can_esp32_twai_write_reg32(dev, TWAI_CLOCK_DIVIDER_REG, twai_config->cdr32);
|
||||
#endif /* !CONFIG_SOC_SERIES_ESP32 */
|
||||
|
||||
esp_intr_alloc(twai_config->irq_source,
|
||||
err = esp_intr_alloc(twai_config->irq_source,
|
||||
ESP_PRIO_TO_FLAGS(twai_config->irq_priority) | ESP_INTR_FLAG_IRAM,
|
||||
can_esp32_twai_isr, (void *)dev, NULL);
|
||||
|
||||
return 0;
|
||||
if (err != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
const struct can_driver_api can_esp32_twai_driver_api = {
|
||||
|
|
|
|||
|
|
@ -63,13 +63,17 @@ static int counter_esp32_init(const struct device *dev)
|
|||
(clock_control_subsys_t)ESP32_CLOCK_CONTROL_SUBSYS_RTC_SLOW,
|
||||
&data->clk_src_freq);
|
||||
|
||||
esp_intr_alloc(cfg->irq_source,
|
||||
int ret = esp_intr_alloc(cfg->irq_source,
|
||||
ESP_PRIO_TO_FLAGS(cfg->irq_priority),
|
||||
(ESP32_COUNTER_RTC_ISR_HANDLER)counter_esp32_isr,
|
||||
(void *)dev,
|
||||
NULL);
|
||||
|
||||
return 0;
|
||||
if (ret != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int counter_esp32_start(const struct device *dev)
|
||||
|
|
|
|||
|
|
@ -96,13 +96,17 @@ static int counter_esp32_init(const struct device *dev)
|
|||
timer_ll_set_reload_value(data->hal_ctx.dev, data->hal_ctx.timer_id, 0);
|
||||
timer_ll_enable_counter(data->hal_ctx.dev, data->hal_ctx.timer_id, cfg->config.counter_en);
|
||||
|
||||
esp_intr_alloc(cfg->irq_source,
|
||||
k_spin_unlock(&lock, key);
|
||||
|
||||
int ret = esp_intr_alloc(cfg->irq_source,
|
||||
ESP_PRIO_TO_FLAGS(cfg->irq_priority),
|
||||
(ISR_HANDLER)counter_esp32_isr, (void *)dev, NULL);
|
||||
|
||||
k_spin_unlock(&lock, key);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int counter_esp32_start(const struct device *dev)
|
||||
|
|
|
|||
|
|
@ -478,12 +478,17 @@ static int gpio_esp32_init(const struct device *dev)
|
|||
static bool isr_connected;
|
||||
|
||||
if (!isr_connected) {
|
||||
esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, irq),
|
||||
int ret = esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, irq),
|
||||
ESP_PRIO_TO_FLAGS(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, priority)),
|
||||
(ISR_HANDLER)gpio_esp32_isr,
|
||||
(void *)dev,
|
||||
NULL);
|
||||
|
||||
if (ret != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
isr_connected = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -762,12 +762,17 @@ static int IRAM_ATTR i2c_esp32_init(const struct device *dev)
|
|||
|
||||
clock_control_on(config->clock_dev, config->clock_subsys);
|
||||
|
||||
esp_intr_alloc(config->irq_source,
|
||||
ret = esp_intr_alloc(config->irq_source,
|
||||
ESP_PRIO_TO_FLAGS(config->irq_priority) | ESP_INTR_FLAG_IRAM,
|
||||
i2c_esp32_isr,
|
||||
(void *)dev,
|
||||
NULL);
|
||||
|
||||
if (ret != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
i2c_hal_master_init(&data->hal);
|
||||
|
||||
i2c_esp32_configure_data_mode(dev);
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ static int esp32_ipm_init(const struct device *dev)
|
|||
{
|
||||
struct esp32_ipm_data *data = (struct esp32_ipm_data *)dev->data;
|
||||
struct esp32_ipm_config *cfg = (struct esp32_ipm_config *)dev->config;
|
||||
int ret;
|
||||
|
||||
data->this_core_id = esp_core_id();
|
||||
data->other_core_id = (data->this_core_id == 0) ? 1 : 0;
|
||||
|
|
@ -219,23 +220,35 @@ static int esp32_ipm_init(const struct device *dev)
|
|||
|
||||
/* pro_cpu is responsible to initialize the lock of shared memory */
|
||||
if (data->this_core_id == 0) {
|
||||
esp_intr_alloc(cfg->irq_source_pro_cpu,
|
||||
ESP_PRIO_TO_FLAGS(cfg->irq_priority_pro_cpu) | ESP_INTR_FLAG_IRAM,
|
||||
ret = esp_intr_alloc(cfg->irq_source_pro_cpu,
|
||||
ESP_PRIO_TO_FLAGS(cfg->irq_priority_pro_cpu) |
|
||||
ESP_INTR_FLAG_IRAM,
|
||||
(intr_handler_t)esp32_ipm_isr,
|
||||
(void *)dev,
|
||||
NULL);
|
||||
|
||||
if (ret != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
atomic_set(&data->control->lock, ESP32_IPM_LOCK_FREE_VAL);
|
||||
} else {
|
||||
/* app_cpu wait for initialization from pro_cpu, then takes it,
|
||||
* after that releases
|
||||
*/
|
||||
esp_intr_alloc(cfg->irq_source_app_cpu,
|
||||
ESP_PRIO_TO_FLAGS(cfg->irq_priority_app_cpu) | ESP_INTR_FLAG_IRAM,
|
||||
ret = esp_intr_alloc(cfg->irq_source_app_cpu,
|
||||
ESP_PRIO_TO_FLAGS(cfg->irq_priority_app_cpu) |
|
||||
ESP_INTR_FLAG_IRAM,
|
||||
(intr_handler_t)esp32_ipm_isr,
|
||||
(void *)dev,
|
||||
NULL);
|
||||
|
||||
if (ret != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOG_DBG("Waiting CPU0 to sync");
|
||||
while (!atomic_cas(&data->control->lock,
|
||||
ESP32_IPM_LOCK_FREE_VAL, data->this_core_id)) {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ struct mcpwm_esp32_config {
|
|||
uint8_t prescale_timer2;
|
||||
struct mcpwm_esp32_channel_config channel_config[MCPWM_CHANNEL_NUM];
|
||||
#ifdef CONFIG_PWM_CAPTURE
|
||||
void (*irq_config_func)(const struct device *dev);
|
||||
int (*irq_config_func)(const struct device *dev);
|
||||
#endif /* CONFIG_PWM_CAPTURE */
|
||||
};
|
||||
|
||||
|
|
@ -435,9 +435,13 @@ int mcpwm_esp32_init(const struct device *dev)
|
|||
mcpwm_ll_group_flush_shadow(data->hal.dev);
|
||||
|
||||
#ifdef CONFIG_PWM_CAPTURE
|
||||
config->irq_config_func(dev);
|
||||
ret = config->irq_config_func(dev);
|
||||
|
||||
if (ret != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", ret);
|
||||
}
|
||||
#endif /* CONFIG_PWM_CAPTURE */
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PWM_CAPTURE
|
||||
|
|
@ -531,12 +535,14 @@ static const struct pwm_driver_api mcpwm_esp32_api = {
|
|||
|
||||
#ifdef CONFIG_PWM_CAPTURE
|
||||
#define IRQ_CONFIG_FUNC(idx) \
|
||||
static void mcpwm_esp32_irq_config_func_##idx(const struct device *dev) \
|
||||
static int mcpwm_esp32_irq_config_func_##idx(const struct device *dev) \
|
||||
{ \
|
||||
esp_intr_alloc(DT_INST_IRQ_BY_IDX(idx, 0, irq), \
|
||||
int ret; \
|
||||
ret = esp_intr_alloc(DT_INST_IRQ_BY_IDX(idx, 0, irq), \
|
||||
ESP_PRIO_TO_FLAGS(DT_INST_IRQ_BY_IDX(idx, 0, priority)) | \
|
||||
ESP_INTR_FLAG_IRAM, \
|
||||
(intr_handler_t)mcpwm_esp32_isr, (void *)dev, NULL); \
|
||||
return ret; \
|
||||
}
|
||||
#define CAPTURE_INIT(idx) .irq_config_func = mcpwm_esp32_irq_config_func_##idx
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -107,8 +107,12 @@ static int serial_esp32_usb_init(const struct device *dev)
|
|||
|
||||
int ret = clock_control_on(config->clock_dev, config->clock_subsys);
|
||||
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
esp_intr_alloc(config->irq_source,
|
||||
ret = esp_intr_alloc(config->irq_source,
|
||||
ESP_PRIO_TO_FLAGS(config->irq_priority),
|
||||
(ISR_HANDLER)serial_esp32_usb_isr,
|
||||
(void *)dev, NULL);
|
||||
|
|
|
|||
|
|
@ -244,11 +244,16 @@ static int spi_esp32_init(const struct device *dev)
|
|||
spi_ll_disable_int(cfg->spi);
|
||||
spi_ll_clear_int_stat(cfg->spi);
|
||||
|
||||
esp_intr_alloc(cfg->irq_source,
|
||||
err = esp_intr_alloc(cfg->irq_source,
|
||||
ESP_PRIO_TO_FLAGS(cfg->irq_priority) | ESP_INTR_FLAG_IRAM,
|
||||
(ISR_HANDLER)spi_esp32_isr,
|
||||
(void *)dev,
|
||||
NULL);
|
||||
|
||||
if (err != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
err = spi_context_cs_configure_all(&data->ctx);
|
||||
|
|
|
|||
|
|
@ -143,12 +143,18 @@ void sys_clock_disable(void)
|
|||
|
||||
static int sys_clock_driver_init(void)
|
||||
{
|
||||
esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(systimer0), 0, irq),
|
||||
int ret;
|
||||
|
||||
ret = esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(systimer0), 0, irq),
|
||||
ESP_PRIO_TO_FLAGS(DT_IRQ_BY_IDX(DT_NODELABEL(systimer0), 0, priority)),
|
||||
sys_timer_isr,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
systimer_hal_init(&systimer_hal);
|
||||
systimer_hal_connect_alarm_counter(&systimer_hal,
|
||||
SYSTIMER_ALARM_OS_TICK_CORE0, SYSTIMER_COUNTER_OS_TICK);
|
||||
|
|
|
|||
|
|
@ -167,12 +167,17 @@ static int wdt_esp32_init(const struct device *dev)
|
|||
|
||||
wdt_hal_init(&data->hal, config->wdt_inst, MWDT_TICK_PRESCALER, true);
|
||||
|
||||
esp_intr_alloc(config->irq_source,
|
||||
ESP_PRIO_TO_FLAGS(cfg->irq_priority),
|
||||
int ret = esp_intr_alloc(config->irq_source,
|
||||
ESP_PRIO_TO_FLAGS(config->irq_priority),
|
||||
(ISR_HANDLER)wdt_esp32_isr,
|
||||
(void *)dev,
|
||||
NULL);
|
||||
|
||||
if (ret != 0) {
|
||||
LOG_ERR("could not allocate interrupt (err %d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_WDT_DISABLE_AT_BOOT
|
||||
wdt_esp32_enable(dev);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue