Skip to content

Commit 0519723

Browse files
authored
Merge pull request #18 from bcmi-labs/extend_irq_manager
Extend irq manager
2 parents d7ea8a2 + 01e0e5a commit 0519723

28 files changed

+1809
-125
lines changed

cores/arduino/FspLinkIrq.h

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#ifndef ARDUINO_FSP_TRANSFERT_H
2+
#define ARDUINO_FSP_TRANSFERT_H
3+
4+
#include "Arduino.h"
5+
#include "r_elc.h"
6+
#include "r_elc_api.h"
7+
8+
9+
extern int attachIrq2Link(uint32_t pin, PinStatus mode);
10+
extern int detachIrq2Link(pin_size_t pinNumber);
11+
12+
/* Wrapper class for FSP ELC
13+
at the present only support the link of an external Irq to a peripheral */
14+
15+
const elc_cfg_t cfg = {ELC_EVENT_NONE};
16+
17+
class FspLinkIrq {
18+
private:
19+
elc_event_t getIrqExtEventFromChannel(uint8_t ch) {
20+
if(ch == 0) {
21+
return ELC_EVENT_ICU_IRQ0;
22+
}
23+
else if(ch == 1) {
24+
return ELC_EVENT_ICU_IRQ1;
25+
}
26+
else if(ch == 2) {
27+
return ELC_EVENT_ICU_IRQ2;
28+
}
29+
else if(ch == 3) {
30+
return ELC_EVENT_ICU_IRQ3;
31+
}
32+
else if(ch == 4) {
33+
return ELC_EVENT_ICU_IRQ4;
34+
}
35+
else if(ch == 5) {
36+
return ELC_EVENT_ICU_IRQ5;
37+
}
38+
else if(ch == 6) {
39+
return ELC_EVENT_ICU_IRQ6;
40+
}
41+
else if(ch == 7) {
42+
return ELC_EVENT_ICU_IRQ7;
43+
}
44+
else if(ch == 8) {
45+
return ELC_EVENT_ICU_IRQ8;
46+
}
47+
else if(ch == 9) {
48+
return ELC_EVENT_ICU_IRQ9;
49+
}
50+
else if(ch == 10) {
51+
return ELC_EVENT_ICU_IRQ10;
52+
}
53+
else if(ch == 11) {
54+
return ELC_EVENT_ICU_IRQ11;
55+
}
56+
else if(ch == 12) {
57+
return ELC_EVENT_ICU_IRQ12;
58+
}
59+
else if(ch == 13) {
60+
return ELC_EVENT_ICU_IRQ13;
61+
}
62+
else if(ch == 14) {
63+
return ELC_EVENT_ICU_IRQ14;
64+
}
65+
else {
66+
return ELC_EVENT_ICU_IRQ15;
67+
}
68+
}
69+
70+
71+
public:
72+
elc_instance_ctrl_t ctrl;
73+
//elc_cfg_t cfg;
74+
~FspLinkIrq() {
75+
R_ELC_Disable (&ctrl);
76+
R_ELC_Close (&ctrl);
77+
}
78+
FspLinkIrq() {
79+
80+
81+
82+
}
83+
84+
85+
86+
bool linkExtIrq(uint32_t pin, PinStatus mode, elc_peripheral_t peripheral) {
87+
88+
89+
uint8_t ch = attachIrq2Link((pin_size_t)pin, mode);
90+
91+
if(ch >= 0) {
92+
93+
fsp_err_t err = R_ELC_Open ( &ctrl, &cfg );
94+
if(err != FSP_SUCCESS && err != FSP_ERR_ALREADY_OPEN) {
95+
return false;
96+
}
97+
98+
R_ELC_Disable (&ctrl);
99+
100+
if(R_ELC_LinkSet ( &ctrl, peripheral, getIrqExtEventFromChannel(ch)) != FSP_SUCCESS) {
101+
R_ELC_Enable (&ctrl);
102+
return false;
103+
}
104+
105+
if(R_ELC_Enable (&ctrl) != FSP_SUCCESS) {
106+
return false;
107+
}
108+
}
109+
return true;
110+
}
111+
112+
void unlinkExtIrq(uint32_t pin) {
113+
uint8_t ch = detachIrq2Link((pin_size_t)pin);
114+
if(ch >= 0) {
115+
R_ELC_Disable (&ctrl);
116+
elc_event_t ev = getIrqExtEventFromChannel(ch);
117+
for(uint8_t i = 0; i < ELC_PERIPHERAL_NUM; i++) {
118+
if(cfg.link[i] == ev) {
119+
R_ELC_LinkBreak (&ctrl, (elc_peripheral_t)ev);
120+
break;
121+
}
122+
123+
}
124+
R_ELC_Enable (&ctrl);
125+
}
126+
}
127+
};
128+
129+
130+
131+
#endif
132+

0 commit comments

Comments
 (0)