Skip to content

Commit a2572b2

Browse files
Raffael Rostagnoraffarost
authored andcommitted
intc: Shared allocator for Xtensa and RISCV
Shared allocator for Xtensa and RISCV Signed-off-by: Raffael Rostagno <[email protected]>
1 parent 7901db6 commit a2572b2

File tree

18 files changed

+70
-109
lines changed

18 files changed

+70
-109
lines changed

components/esp_hw_support/include/esp_private/esp_riscv_intr.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ static inline uint32_t esp_riscv_intr_num_flags(int intr_num, uint32_t rsvd_mask
2828
}
2929

3030
extern intptr_t _mtvt_table[48];
31-
extern intptr_t _interrupt_handler;
31+
extern intptr_t _isr_wrapper;
3232

3333
/* The first 16 entries of the array are internal interrupt, ignore them */
3434
const intptr_t destination = _mtvt_table[16 + intr_num];
3535

36-
return (destination != (intptr_t)&_interrupt_handler) ? ESP_CPU_INTR_DESC_FLAG_RESVD : 0;
36+
return (destination != (intptr_t)&_isr_wrapper) ? ESP_CPU_INTR_DESC_FLAG_RESVD : 0;
3737
}
3838

3939

@@ -60,13 +60,12 @@ static inline uint32_t esp_riscv_intr_num_flags(int intr_num, uint32_t rsvd_mask
6060
}
6161

6262
extern intptr_t _vector_table[32];
63-
extern int _interrupt_handler;
6463
const intptr_t pc = (intptr_t) &_vector_table[intr_num];
6564

6665
/* JAL instructions are relative to the PC they are executed from. */
6766
const intptr_t destination = pc + riscv_decode_offset_from_jal_instruction(pc);
6867

69-
return (destination != (intptr_t)&_interrupt_handler) ? ESP_CPU_INTR_DESC_FLAG_RESVD : 0;
68+
return (destination != (intptr_t)&_isr_wrapper) ? ESP_CPU_INTR_DESC_FLAG_RESVD : 0;
7069
}
7170

7271
#endif // SOC_INT_CLIC_SUPPORTED

components/esp_hw_support/port/esp32c2/esp_cpu_intr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_desc_ret)
1111
{
1212
/* On the ESP32-C2, interrupt:
13+
* - 0 is unavailable according to TRM
1314
* - 1 is for Wi-Fi
1415
* - 6 for "permanently disabled interrupt", named INT_MUX_DISABLED_INTNO in the interrupt allocator
1516
*/
1617
// [TODO: IDF-2465]
17-
const uint32_t rsvd_mask = BIT(1) | BIT(6);
18+
const uint32_t rsvd_mask = BIT(0) | BIT(1) | BIT(6);
1819

1920
intr_desc_ret->priority = 1;
2021
intr_desc_ret->type = ESP_CPU_INTR_TYPE_NA;

components/esp_hw_support/port/esp32c3/esp_cpu_intr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_desc_ret)
1111
{
1212
/* On the ESP32-C3, interrupt:
13+
* - 0 is unavailable according to TRM
1314
* - 1 is for Wi-Fi
1415
* - 6 for "permanently disabled interrupt", named INT_MUX_DISABLED_INTNO in the interrupt allocator
1516
*/
1617
// [TODO: IDF-2465]
17-
const uint32_t rsvd_mask = BIT(1) | BIT(6);
18+
const uint32_t rsvd_mask = BIT(0) | BIT(1) | BIT(6);
1819

1920
intr_desc_ret->priority = 1;
2021
intr_desc_ret->type = ESP_CPU_INTR_TYPE_NA;

components/esp_hw_support/port/esp32c6/esp_cpu_intr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_desc_ret)
1111
{
1212
/* On the ESP32-C6, interrupt:
13+
* - 0, 3, 4, and 7 are used by the CPU for core-local interrupts (CLINT)
1314
* - 1 is for Wi-Fi
1415
* - 6 for "permanently disabled interrupt"
15-
*
16-
* Interrupts 3, 4 and 7 are unavailable for PULP CPU as they are bound to Core-Local Interrupts (CLINT)
1716
*/
1817
// [TODO: IDF-2465]
19-
const uint32_t rsvd_mask = BIT(1) | BIT(3) | BIT(4) | BIT(6) | BIT(7);
18+
const uint32_t rsvd_mask = BIT(0) | BIT(1) | BIT(3) | BIT(4) | BIT(6) | BIT(7);
2019

2120
intr_desc_ret->priority = 1;
2221
intr_desc_ret->type = ESP_CPU_INTR_TYPE_NA;

components/esp_timer/private_include/esp_timer_impl.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,7 @@
1919
#include <stdint.h>
2020
#include "esp_err.h"
2121

22-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || \
23-
defined(CONFIG_SOC_SERIES_ESP32C3) || \
24-
defined(CONFIG_SOC_SERIES_ESP32C6)
25-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
26-
#define ISR_HANDLER isr_handler_t
27-
#else
2822
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
29-
#define ISR_HANDLER intr_handler_t
30-
#endif
3123

3224
/**
3325
* @brief Minimal initialization of platform specific layer of esp_timer
@@ -45,7 +37,7 @@ esp_err_t esp_timer_impl_early_init(void);
4537
* Before calling this function, esp_timer_impl_early_init must be called.
4638
* @return ESP_OK, ESP_ERR_NO_MEM, or one of the errors from interrupt allocator
4739
*/
48-
esp_err_t esp_timer_impl_init(ISR_HANDLER alarm_handler);
40+
esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler);
4941

5042
/**
5143
* @brief Deinitialize platform specific layer of esp_timer

components/esp_timer/src/esp_timer.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,7 @@
3838

3939
#include "sdkconfig.h"
4040

41-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || \
42-
defined(CONFIG_SOC_SERIES_ESP32C3) || \
43-
defined(CONFIG_SOC_SERIES_ESP32C6)
44-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
45-
#define ISR_HANDLER isr_handler_t
46-
#else
4741
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
48-
#define ISR_HANDLER intr_handler_t
49-
#endif
5042

5143
#define LOG_MODULE_NAME esp_timer
5244
#include <zephyr/logging/log.h>
@@ -576,7 +568,7 @@ esp_err_t esp_timer_init(void)
576568
esp_err_t err = ESP_OK;
577569
err = init_timer_task();
578570
if (err == ESP_OK) {
579-
err = esp_timer_impl_init((ISR_HANDLER)&timer_alarm_handler);
571+
err = esp_timer_impl_init((intr_handler_t)&timer_alarm_handler);
580572
if (err != ESP_OK) {
581573
ESP_EARLY_LOGE(TAG, "ISR init failed");
582574
deinit_timer_task();

components/esp_timer/src/esp_timer_impl_lac.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323
#include "soc/timer_group_reg.h"
2424
#include "soc/rtc.h"
2525

26-
#ifdef CONFIG_SOC_SERIES_ESP32C3
27-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
28-
#else
2926
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
30-
#endif
3127

3228
/**
3329
* @file esp_timer_lac.c

components/esp_timer/src/esp_timer_impl_systimer.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,7 @@
2222
#include "hal/systimer_types.h"
2323
#include "hal/systimer_hal.h"
2424

25-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || \
26-
defined(CONFIG_SOC_SERIES_ESP32C3) || \
27-
defined(CONFIG_SOC_SERIES_ESP32C6)
28-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
29-
#define ISR_HANDLER isr_handler_t
30-
#else
3125
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
32-
#define ISR_HANDLER intr_handler_t
33-
#endif
3426

3527
/**
3628
* @file esp_timer_systimer.c
@@ -50,7 +42,7 @@ static const char *TAG = "esp_timer_systimer";
5042
/* Function from the upper layer to be called when the interrupt happens.
5143
* Registered in esp_timer_impl_init.
5244
*/
53-
static ISR_HANDLER s_alarm_handler = NULL;
45+
static intr_handler_t s_alarm_handler = NULL;
5446

5547
/* Systimer HAL layer object */
5648
static systimer_hal_context_t systimer_hal;
@@ -145,7 +137,7 @@ esp_err_t esp_timer_impl_early_init(void)
145137
return ESP_OK;
146138
}
147139

148-
esp_err_t esp_timer_impl_init(ISR_HANDLER alarm_handler)
140+
esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler)
149141
{
150142
int isr_flags = 0 /* ZEP-795 (GH #74368): esp_timer ISR priority relaxed to avoid
151143
* IRQ not being allocated when several peripherals are enabled
@@ -156,7 +148,7 @@ esp_err_t esp_timer_impl_init(ISR_HANDLER alarm_handler)
156148
| ESP_INTR_FLAG_IRAM;
157149

158150
esp_err_t err = esp_intr_alloc(ETS_SYSTIMER_TARGET2_EDGE_INTR_SOURCE, isr_flags,
159-
(ISR_HANDLER)timer_alarm_isr, NULL, NULL);
151+
(intr_handler_t)timer_alarm_isr, NULL, NULL);
160152
if (err != ESP_OK) {
161153
ESP_EARLY_LOGE(TAG, "esp_intr_alloc failed (0x%x)", err);
162154
return err;

zephyr/esp32/src/wifi/esp_wifi_adapter.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,19 @@ static void clear_intr_wrapper(uint32_t intr_source, uint32_t intr_num)
405405

406406
static void set_isr_wrapper(int32_t n, void *f, void *arg)
407407
{
408-
esp_intr_alloc(n, 0, f, arg, NULL);
408+
irq_disable(n);
409+
irq_connect_dynamic(n, 0, f, arg, 0);
410+
irq_enable(n);
409411
}
410412

411413
static void intr_on(unsigned int mask)
412414
{
413-
irq_enable(0);
415+
irq_enable(__builtin_ctz(mask));
414416
}
415417

416418
static void intr_off(unsigned int mask)
417419
{
418-
irq_disable(0);
420+
irq_disable(__builtin_ctz(mask));
419421
}
420422

421423
uint32_t esp_get_free_heap_size(void)

zephyr/esp32c2/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ if(CONFIG_SOC_SERIES_ESP32C2)
260260
../../components/log/log_noos.c
261261
../../components/log/log.c
262262

263+
../../components/riscv/interrupt.c
264+
../../components/riscv/instruction_decode.c
263265

264266
../port/heap/heap_caps_zephyr.c
265267
../port/host_flash/cache_utils.c
266-
../../components/riscv/interrupt.c
267268
../port/bootloader/bootloader_flash.c
268269

269270
../common/flash_init.c

0 commit comments

Comments
 (0)