diff --git a/cores/arduino/IRQManager.cpp b/cores/arduino/IRQManager.cpp index 4d9e6e1e8..2e84955ed 100644 --- a/cores/arduino/IRQManager.cpp +++ b/cores/arduino/IRQManager.cpp @@ -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 */ diff --git a/cores/arduino/IRQManager.h b/cores/arduino/IRQManager.h index 2f9e093cc..0419613ab 100644 --- a/cores/arduino/IRQManager.h +++ b/cores/arduino/IRQManager.h @@ -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 @@ -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);