Skip to content

Commit 907aaa4

Browse files
committed
added IRQManager class to dynamically handle irq vector table (at the present just works for uart and in a simplified way, because it does not touch other interrupts automatically generated by e2studio)
1 parent 237cb3d commit 907aaa4

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

cores/arduino/IRQManager.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "IRQManager.h"
2+
#include "bsp_api.h"
3+
4+
#define FIXED_IRQ_NUM 16
5+
#define PROG_IRQ_NUM 32
6+
7+
#define UART_SCI2_REQ_NUM 4
8+
#define UART_SCI2_PRIORITY 12
9+
10+
IRQManager::IRQManager() : last_interrupt_index{-1} {
11+
12+
}
13+
14+
IRQManager::~IRQManager() {
15+
16+
}
17+
18+
IRQManager& IRQManager::getInstance() {
19+
static IRQManager instance;
20+
return instance;
21+
}
22+
23+
24+
bool IRQManager::addPeripheral(Peripheral_t p, uart_cfg_t &cfg) {
25+
/* getting the address of the current location of the irq vector table */
26+
volatile uint32_t *irq_ptr = (volatile uint32_t *)SCB->VTOR;
27+
/* set the displacement to the "programmable" part of the table */
28+
irq_ptr += FIXED_IRQ_NUM;
29+
30+
31+
if(p == UART_SCI2) {
32+
if( (last_interrupt_index + UART_SCI2_REQ_NUM) < PROG_IRQ_NUM ) {
33+
/* TX interrupt */
34+
last_interrupt_index = 26;
35+
cfg.txi_ipl = UART_SCI2_PRIORITY;
36+
cfg.txi_irq = (IRQn_Type)last_interrupt_index;
37+
*(irq_ptr + last_interrupt_index) = (uint32_t)sci_uart_txi_isr;
38+
R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SCI2_TXI);
39+
40+
/* TX-ERROR interrupt */
41+
last_interrupt_index++;
42+
cfg.tei_ipl = UART_SCI2_PRIORITY;
43+
cfg.tei_irq = (IRQn_Type)last_interrupt_index;
44+
*(irq_ptr + last_interrupt_index) = (uint32_t)sci_uart_tei_isr;
45+
R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SCI2_TEI);
46+
47+
/* RX interrupt */
48+
last_interrupt_index++;
49+
cfg.rxi_ipl = UART_SCI2_PRIORITY;
50+
cfg.rxi_irq = (IRQn_Type)last_interrupt_index;
51+
*(irq_ptr + last_interrupt_index) = (uint32_t)sci_uart_rxi_isr;
52+
R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SCI2_RXI);
53+
54+
/* RX-ERROR interrupt */
55+
last_interrupt_index++;
56+
cfg.eri_ipl = UART_SCI2_PRIORITY;
57+
cfg.eri_irq = (IRQn_Type)last_interrupt_index;
58+
*(irq_ptr + last_interrupt_index) = (uint32_t)sci_uart_eri_isr;
59+
R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SCI2_ERI);
60+
}
61+
else {
62+
return false;
63+
}
64+
}
65+
else {
66+
return false;
67+
}
68+
}
69+
70+
/* Do not build these data structures if no interrupts are currently allocated because IAR will have build errors. */
71+
72+

cores/arduino/IRQManager.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef ARDUINO_IRQ_MANAGER_H
2+
#define ARDUINO_IRQ_MANAGER_H
3+
4+
#include "bsp_api.h"
5+
#include "r_uart_api.h"
6+
7+
typedef enum {
8+
RTC,
9+
UART_SCI2,
10+
I2C_MASTER,
11+
I2C_SLAVE
12+
} Peripheral_t;
13+
14+
15+
class IRQManager {
16+
public:
17+
bool addPeripheral(Peripheral_t p, uart_cfg_t &cfg);
18+
static IRQManager& getInstance();
19+
IRQManager(IRQManager const&) = delete;
20+
void operator=(IRQManager const&) = delete;
21+
~IRQManager();
22+
23+
private:
24+
int last_interrupt_index;
25+
IRQManager();
26+
27+
};
28+
29+
30+
31+
32+
33+
#endif

0 commit comments

Comments
 (0)