Skip to content

Commit b21aa62

Browse files
committed
ulp: improve interrupt handler for ULP
Add support for arguments in interrupt handler Signed-off-by: Lucas Tamborrino <[email protected]>
1 parent f3453bd commit b21aa62

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

components/ulp/lp_core/lp_core/include/ulp_lp_core_interrupts.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ void ulp_lp_core_intr_enable(void);
5555
*/
5656
void ulp_lp_core_intr_disable(void);
5757

58+
#if SOC_LP_CORE_SINGLE_INTERRUPT_VECTOR
59+
int ulp_lp_core_intr_set_handler(int intr_source, void (*handler)(void *arg), void *arg);
60+
#endif
61+
5862
#ifdef __cplusplus
5963
}
6064
#endif

components/ulp/lp_core/lp_core/lp_core_interrupt.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,40 @@ void __attribute__((weak, alias("ulp_lp_core_default_intr_handler"))) ulp_lp_cor
7070

7171
#if SOC_LP_CORE_SINGLE_INTERRUPT_VECTOR
7272

73-
static void* s_intr_handlers[] = {
74-
ulp_lp_core_lp_io_intr_handler,
75-
ulp_lp_core_lp_i2c_intr_handler,
76-
ulp_lp_core_lp_uart_intr_handler,
77-
ulp_lp_core_lp_timer_intr_handler,
78-
0, // Reserved / Unused
79-
ulp_lp_core_lp_pmu_intr_handler,
73+
typedef struct {
74+
void (*handler)(void *arg);
75+
void *arg;
76+
} ulp_lp_core_intr_handler_t;
77+
78+
static ulp_lp_core_intr_handler_t s_intr_handlers[] = {
79+
{(void (*)(void *))ulp_lp_core_lp_io_intr_handler, NULL},
80+
{(void (*)(void *))ulp_lp_core_lp_i2c_intr_handler, NULL},
81+
{(void (*)(void *))ulp_lp_core_lp_uart_intr_handler, NULL},
82+
{(void (*)(void *))ulp_lp_core_lp_timer_intr_handler, NULL},
83+
{NULL, NULL}, // Reserved / Unused
84+
{(void (*)(void *))ulp_lp_core_lp_pmu_intr_handler, NULL},
8085
};
8186

87+
int ulp_lp_core_intr_set_handler(int intr_source, void (*handler)(void *arg), void *arg)
88+
{
89+
if (intr_source < 0 || intr_source >= sizeof(s_intr_handlers) / sizeof(s_intr_handlers[0])) {
90+
return -1;
91+
}
92+
93+
s_intr_handlers[intr_source].handler = handler;
94+
s_intr_handlers[intr_source].arg = arg;
95+
96+
return 0;
97+
}
98+
8299
void __attribute__((weak)) ulp_lp_core_intr_handler(void)
83100
{
84101
uint8_t intr_source = lp_core_ll_get_triggered_interrupt_srcs();
85-
for (int i = 0; i < sizeof(s_intr_handlers) / 4; i++) {
102+
for (int i = 0; i < sizeof(s_intr_handlers) / sizeof(s_intr_handlers[0]); i++) {
86103
if (intr_source & (1 << i)) {
87-
void (*handler)(void) = s_intr_handlers[i];
88-
if (handler) {
89-
handler();
104+
ulp_lp_core_intr_handler_t *handler_entry = &s_intr_handlers[i];
105+
if (handler_entry->handler) {
106+
handler_entry->handler(handler_entry->arg);
90107
}
91108
}
92109
}

0 commit comments

Comments
 (0)