Skip to content

IRQManager: implement callback based method for custom irq handlers #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cores/arduino/IRQManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,31 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
return rv;
}

/*
The implementer should update the value of last_interrupt once done
eg:

bool config_my_funky_peripheral(unsigned int* last_interrupt, volatile uint32_t *irq_ptr, void* config) {
funky_peripheral_cfg_t* cfg = (funky_peripheral_cfg_t*)config;
*(irq_ptr + *last_interrupt) = (uint32_t)cfg->irq_callback;
cfg->interrupt = *last_interrupt;
// increase the interrupt count
*last_interrupt++;
return true;
}

and then use as:

funky_peripheral_cfg_t funky_cfg;
IRQManager::getInstance().addCustomPeripheral(config_my_funky_peripheral, &funky_cfg);
*/
bool IRQManager::addCustomPeripheral(bool (*cb)(unsigned int* last_interrupt, volatile uint32_t *irq_ptr, void* conf), void* conf) {
volatile uint32_t *irq_ptr = (volatile uint32_t *)SCB->VTOR;
irq_ptr += FIXED_IRQ_NUM;

return cb(&last_interrupt_index, irq_ptr, conf);
}

bool IRQManager::set_adc_end_link_event(int li, int ch){
bool rv = false;
if (0) {}
Expand Down
2 changes: 2 additions & 0 deletions cores/arduino/IRQManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ using Irq_f = void (*)(void);
class IRQManager {
public:
bool addPeripheral(Peripheral_t p, void *cfg);
bool addCustomPeripheral(bool (*cb)(unsigned int* last_interrupt, volatile uint32_t *irq_ptr, void* conf), void* conf);

static IRQManager& getInstance();

#ifdef HAS_DMAC
Expand Down
Loading