17
17
#include <zephyr.h>
18
18
#include <drivers/interrupt_controller/intc_esp32c3.h>
19
19
#include <sw_isr_table.h>
20
+ #include <riscv/interrupt.h>
21
+
22
+ #define ESP32C3_INTC_DEFAULT_PRIO 15
20
23
21
24
#include <logging/log.h>
22
25
LOG_MODULE_REGISTER (intc_esp32c3 , CONFIG_LOG_DEFAULT_LEVEL );
@@ -40,17 +43,6 @@ LOG_MODULE_REGISTER(intc_esp32c3, CONFIG_LOG_DEFAULT_LEVEL);
40
43
41
44
static uint32_t esp_intr_enabled_mask [2 ] = {0 , 0 };
42
45
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
-
54
46
static uint32_t esp_intr_find_irq_for_source (uint32_t source )
55
47
{
56
48
/* in general case, each 2 sources goes routed to
@@ -80,15 +72,7 @@ void esp_intr_initialize(void)
80
72
}
81
73
82
74
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 );
92
76
}
93
77
94
78
/* set global esp32c3's INTC masking level */
@@ -113,9 +97,6 @@ int esp_intr_alloc(int source,
113
97
}
114
98
115
99
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 );
119
100
120
101
irq_connect_dynamic (source ,
121
102
ESP32C3_INTC_DEFAULT_PRIORITY ,
@@ -133,7 +114,7 @@ int esp_intr_alloc(int source,
133
114
esp_intr_enabled_mask [0 ], esp_intr_enabled_mask [1 ]);
134
115
135
116
irq_unlock (key );
136
- irq_enable (irq );
117
+ irq_enable (source );
137
118
138
119
return 0 ;
139
120
}
@@ -146,7 +127,7 @@ int esp_intr_disable(int source)
146
127
147
128
uint32_t key = irq_lock ();
148
129
149
- esp_rom_intr_matrix_set (source ,
130
+ esp_rom_intr_matrix_set (0 ,
150
131
source ,
151
132
ESP32C3_INTC_DISABLED_SLOT );
152
133
@@ -173,7 +154,6 @@ int esp_intr_enable(int source)
173
154
uint32_t key = irq_lock ();
174
155
uint32_t irq = esp_intr_find_irq_for_source (source );
175
156
176
- irq_disable (irq );
177
157
esp_rom_intr_matrix_set (0 , source , irq );
178
158
179
159
if (source < 32 ) {
@@ -185,7 +165,10 @@ int esp_intr_enable(int source)
185
165
INTC_LOG ("Enabled ISRs -- 0: 0x%X -- 1: 0x%X" ,
186
166
esp_intr_enabled_mask [0 ], esp_intr_enabled_mask [1 ]);
187
167
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
+
189
172
irq_unlock (key );
190
173
191
174
return 0 ;
0 commit comments