From 6f6c902d2e372ac534060faec025c69ca0c2cbb4 Mon Sep 17 00:00:00 2001 From: David <6957239+delta-G@users.noreply.github.com> Date: Mon, 13 May 2024 21:40:29 -0500 Subject: [PATCH 1/2] added generic interrupt --- cores/arduino/IRQManager.cpp | 22 ++++++++++++++++++++++ cores/arduino/IRQManager.h | 8 +++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cores/arduino/IRQManager.cpp b/cores/arduino/IRQManager.cpp index 4d9e6e1e8..dcecaf752 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) { + 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); From 4af8b7f3db403ca6475289f7d37811af13151ac2 Mon Sep 17 00:00:00 2001 From: David <6957239+delta-G@users.noreply.github.com> Date: Tue, 14 May 2024 14:30:59 -0500 Subject: [PATCH 2/2] added check for last_interrupt_index against PROG_IRQ_NUM --- cores/arduino/IRQManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/IRQManager.cpp b/cores/arduino/IRQManager.cpp index dcecaf752..2e84955ed 100644 --- a/cores/arduino/IRQManager.cpp +++ b/cores/arduino/IRQManager.cpp @@ -45,7 +45,7 @@ bool IRQManager::addGenericInterrupt(GenericIrqCfg_t &cfg, Irq_f fnc /*= nullptr irq_ptr += FIXED_IRQ_NUM; bool rv = false; - if(cfg.irq == FSP_INVALID_VECTOR) { + 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;