Skip to content

Adding Generic Interrupt function to IRQManager #316

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

Merged
merged 2 commits into from
May 15, 2024
Merged
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
22 changes: 22 additions & 0 deletions cores/arduino/IRQManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ IRQManager& IRQManager::getInstance() {
return instance;
}

bool IRQManager::addGenericInterrupt(GenericIrqCfg_t &cfg, Irq_f fnc /*= nullptr*/){
/* getting the address of the current location of the irq vector table */
volatile uint32_t *irq_ptr = (volatile uint32_t *)SCB->VTOR;
/* set the displacement to the "programmable" part of the table */
irq_ptr += FIXED_IRQ_NUM;
bool rv = false;

if((cfg.irq == FSP_INVALID_VECTOR) && (last_interrupt_index < PROG_IRQ_NUM)) {
if(fnc != nullptr){
R_ICU->IELSR[last_interrupt_index] = cfg.event;
*(irq_ptr + last_interrupt_index) = (uint32_t)fnc;
R_BSP_IrqDisable((IRQn_Type)last_interrupt_index);
R_BSP_IrqStatusClear((IRQn_Type)last_interrupt_index);
NVIC_SetPriority((IRQn_Type)last_interrupt_index, cfg.ipl);
R_BSP_IrqEnable ((IRQn_Type)last_interrupt_index);
cfg.irq = (IRQn_Type)last_interrupt_index;
last_interrupt_index++;
rv = true;
}
}
return rv;
}

bool IRQManager::addADCScanEnd(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
/* getting the address of the current location of the irq vector table */
Expand Down
8 changes: 7 additions & 1 deletion cores/arduino/IRQManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ typedef struct timer {
agt_extended_cfg_t *agt_ext_cfg;
} TimerIrqCfg_t;

typedef struct genericIrq {
IRQn_Type irq;
uint8_t ipl;
elc_event_t event;
} GenericIrqCfg_t;


#ifdef __cplusplus
Expand Down Expand Up @@ -199,7 +204,8 @@ class IRQManager {
it returns true if the interrupt is correctly added */
bool addDMA(dmac_extended_cfg_t &cfg, Irq_f fnc = nullptr);
#endif


bool addGenericInterrupt(GenericIrqCfg_t &cfg, Irq_f fnc = nullptr);
bool addTimerOverflow(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
bool addTimerUnderflow(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
bool addTimerCompareCaptureA(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
Expand Down
Loading