Skip to content

Commit 30c45b0

Browse files
sylvioalvescarlescufi
authored andcommitted
intc: esp32c3: use source as interrupt value
Using IRQ as source for interrupt values can fail when installing irq_connect_dynamic, as IRQ can previously be enabled. This updates the logic to use source map and allows default irq_enable() and irq_disable() to call esp32c3 interrupt allocator implementation. Signed-off-by: Sylvio Alves <[email protected]>
1 parent 4aad6d0 commit 30c45b0

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

drivers/interrupt_controller/intc_esp32c3.c

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include <zephyr.h>
1818
#include <drivers/interrupt_controller/intc_esp32c3.h>
1919
#include <sw_isr_table.h>
20+
#include <riscv/interrupt.h>
21+
22+
#define ESP32C3_INTC_DEFAULT_PRIO 15
2023

2124
#include <logging/log.h>
2225
LOG_MODULE_REGISTER(intc_esp32c3, CONFIG_LOG_DEFAULT_LEVEL);
@@ -40,17 +43,6 @@ LOG_MODULE_REGISTER(intc_esp32c3, CONFIG_LOG_DEFAULT_LEVEL);
4043

4144
static uint32_t esp_intr_enabled_mask[2] = {0, 0};
4245

43-
static void esp_intr_default_isr(const void *arg)
44-
{
45-
ARG_UNUSED(arg);
46-
ulong_t mcause;
47-
48-
__asm__ volatile("csrr %0, mcause" : "=r" (mcause));
49-
mcause &= SOC_MCAUSE_EXP_MASK;
50-
51-
INTC_LOG("Spurious interrupt, mcause: %ld, source %d", mcause, soc_intr_get_next_source());
52-
}
53-
5446
static uint32_t esp_intr_find_irq_for_source(uint32_t source)
5547
{
5648
/* in general case, each 2 sources goes routed to
@@ -80,15 +72,7 @@ void esp_intr_initialize(void)
8072
}
8173

8274
for (int i = 0; i < ETS_MAX_INTR_SOURCE; i++) {
83-
esp_rom_intr_matrix_set(0,
84-
i,
85-
ESP32C3_INTC_DISABLED_SLOT);
86-
87-
irq_connect_dynamic(i,
88-
ESP32C3_INTC_DEFAULT_PRIORITY,
89-
esp_intr_default_isr,
90-
NULL,
91-
0);
75+
esp_rom_intr_matrix_set(0, i, ESP32C3_INTC_DISABLED_SLOT);
9276
}
9377

9478
/* set global esp32c3's INTC masking level */
@@ -113,9 +97,6 @@ int esp_intr_alloc(int source,
11397
}
11498

11599
uint32_t key = irq_lock();
116-
uint32_t irq = esp_intr_find_irq_for_source(source);
117-
118-
esp_rom_intr_matrix_set(0, source, irq);
119100

120101
irq_connect_dynamic(source,
121102
ESP32C3_INTC_DEFAULT_PRIORITY,
@@ -133,7 +114,7 @@ int esp_intr_alloc(int source,
133114
esp_intr_enabled_mask[0], esp_intr_enabled_mask[1]);
134115

135116
irq_unlock(key);
136-
irq_enable(irq);
117+
irq_enable(source);
137118

138119
return 0;
139120
}
@@ -146,7 +127,7 @@ int esp_intr_disable(int source)
146127

147128
uint32_t key = irq_lock();
148129

149-
esp_rom_intr_matrix_set(source,
130+
esp_rom_intr_matrix_set(0,
150131
source,
151132
ESP32C3_INTC_DISABLED_SLOT);
152133

@@ -173,7 +154,6 @@ int esp_intr_enable(int source)
173154
uint32_t key = irq_lock();
174155
uint32_t irq = esp_intr_find_irq_for_source(source);
175156

176-
irq_disable(irq);
177157
esp_rom_intr_matrix_set(0, source, irq);
178158

179159
if (source < 32) {
@@ -185,7 +165,10 @@ int esp_intr_enable(int source)
185165
INTC_LOG("Enabled ISRs -- 0: 0x%X -- 1: 0x%X",
186166
esp_intr_enabled_mask[0], esp_intr_enabled_mask[1]);
187167

188-
irq_enable(irq);
168+
esprv_intc_int_set_priority(irq, ESP32C3_INTC_DEFAULT_PRIO);
169+
esprv_intc_int_set_type(irq, INTR_TYPE_LEVEL);
170+
esprv_intc_int_enable(1 << irq);
171+
189172
irq_unlock(key);
190173

191174
return 0;

soc/riscv/esp32c3/soc_irq.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,32 @@
2121
#include <toolchain/gcc.h>
2222
#include <soc.h>
2323

24-
#define ESP32C3_INTC_DEFAULT_PRIO 15
2524
#define ESP32C3_INTSTATUS_SLOT1_THRESHOLD 32
2625

2726
void arch_irq_enable(unsigned int irq)
2827
{
29-
uint32_t key = irq_lock();
30-
31-
esprv_intc_int_set_priority(irq, ESP32C3_INTC_DEFAULT_PRIO);
32-
esprv_intc_int_set_type(irq, INTR_TYPE_LEVEL);
33-
esprv_intc_int_enable(1 << irq);
34-
irq_unlock(key);
28+
esp_intr_enable(irq);
3529
}
3630

3731
void arch_irq_disable(unsigned int irq)
3832
{
39-
esprv_intc_int_disable(1 << irq);
33+
esp_intr_disable(irq);
4034
}
4135

4236
int arch_irq_is_enabled(unsigned int irq)
4337
{
44-
return (REG_READ(INTERRUPT_CORE0_CPU_INT_ENABLE_REG) & (1 << irq));
38+
bool res = false;
39+
uint32_t key = irq_lock();
40+
41+
if (irq < 32) {
42+
res = esp_intr_get_enabled_intmask(0) & BIT(irq);
43+
} else {
44+
res = esp_intr_get_enabled_intmask(1) & BIT(irq - 32);
45+
}
46+
47+
irq_unlock(key);
48+
49+
return res;
4550
}
4651

4752
uint32_t soc_intr_get_next_source(void)

0 commit comments

Comments
 (0)