Skip to content

Commit 12f8d2c

Browse files
authored
Merge pull request #316 from delta-G/genericIrq
Adding Generic Interrupt function to IRQManager
2 parents 9029d7d + 4af8b7f commit 12f8d2c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Diff for: cores/arduino/IRQManager.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ IRQManager& IRQManager::getInstance() {
3838
return instance;
3939
}
4040

41+
bool IRQManager::addGenericInterrupt(GenericIrqCfg_t &cfg, Irq_f fnc /*= nullptr*/){
42+
/* getting the address of the current location of the irq vector table */
43+
volatile uint32_t *irq_ptr = (volatile uint32_t *)SCB->VTOR;
44+
/* set the displacement to the "programmable" part of the table */
45+
irq_ptr += FIXED_IRQ_NUM;
46+
bool rv = false;
47+
48+
if((cfg.irq == FSP_INVALID_VECTOR) && (last_interrupt_index < PROG_IRQ_NUM)) {
49+
if(fnc != nullptr){
50+
R_ICU->IELSR[last_interrupt_index] = cfg.event;
51+
*(irq_ptr + last_interrupt_index) = (uint32_t)fnc;
52+
R_BSP_IrqDisable((IRQn_Type)last_interrupt_index);
53+
R_BSP_IrqStatusClear((IRQn_Type)last_interrupt_index);
54+
NVIC_SetPriority((IRQn_Type)last_interrupt_index, cfg.ipl);
55+
R_BSP_IrqEnable ((IRQn_Type)last_interrupt_index);
56+
cfg.irq = (IRQn_Type)last_interrupt_index;
57+
last_interrupt_index++;
58+
rv = true;
59+
}
60+
}
61+
return rv;
62+
}
4163

4264
bool IRQManager::addADCScanEnd(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
4365
/* getting the address of the current location of the irq vector table */

Diff for: cores/arduino/IRQManager.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ typedef struct timer {
125125
agt_extended_cfg_t *agt_ext_cfg;
126126
} TimerIrqCfg_t;
127127

128+
typedef struct genericIrq {
129+
IRQn_Type irq;
130+
uint8_t ipl;
131+
elc_event_t event;
132+
} GenericIrqCfg_t;
128133

129134

130135
#ifdef __cplusplus
@@ -199,7 +204,8 @@ class IRQManager {
199204
it returns true if the interrupt is correctly added */
200205
bool addDMA(dmac_extended_cfg_t &cfg, Irq_f fnc = nullptr);
201206
#endif
202-
207+
208+
bool addGenericInterrupt(GenericIrqCfg_t &cfg, Irq_f fnc = nullptr);
203209
bool addTimerOverflow(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
204210
bool addTimerUnderflow(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
205211
bool addTimerCompareCaptureA(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);

0 commit comments

Comments
 (0)