Skip to content

Commit 154b133

Browse files
committed
IRQManager: implement callback based method for custom irq handlers
1 parent 6c28783 commit 154b133

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

cores/arduino/IRQManager.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,31 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
939939
return rv;
940940
}
941941

942+
/*
943+
The implementer should update the value of last_interrupt once done
944+
eg:
945+
946+
bool config_my_funky_peripheral(unsigned int* last_interrupt, volatile uint32_t *irq_ptr, void* config) {
947+
funky_peripheral_cfg_t* cfg = (funky_peripheral_cfg_t*)config;
948+
*(irq_ptr + *last_interrupt) = (uint32_t)cfg->irq_callback;
949+
cfg->interrupt = *last_interrupt;
950+
// increase the interrupt count
951+
*last_interrupt++;
952+
return true;
953+
}
954+
955+
and then use as:
956+
957+
funky_peripheral_cfg_t funky_cfg;
958+
IRQManager::getInstance().addCustomPeripheral(config_my_funky_peripheral, &funky_cfg);
959+
*/
960+
bool IRQManager::addCustomPeripheral(bool (*cb)(unsigned int* last_interrupt, volatile uint32_t *irq_ptr, void* conf), void* conf) {
961+
volatile uint32_t *irq_ptr = (volatile uint32_t *)SCB->VTOR;
962+
irq_ptr += FIXED_IRQ_NUM;
963+
964+
return cb(&last_interrupt_index, irq_ptr, conf);
965+
}
966+
942967
bool IRQManager::set_adc_end_link_event(int li, int ch){
943968
bool rv = false;
944969
if (0) {}

cores/arduino/IRQManager.h

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ using Irq_f = void (*)(void);
190190
class IRQManager {
191191
public:
192192
bool addPeripheral(Peripheral_t p, void *cfg);
193+
bool addCustomPeripheral(bool (*cb)(unsigned int* last_interrupt, volatile uint32_t *irq_ptr, void* conf), void* conf);
194+
193195
static IRQManager& getInstance();
194196

195197
#ifdef HAS_DMAC

0 commit comments

Comments
 (0)