Skip to content

Commit f39bc19

Browse files
committed
cores/xmc/: Add Interrupt Implementation.
Signed-off-by: MDin <Dinesh.M-EE@infineon.com>
1 parent 79a1e99 commit f39bc19

1 file changed

Lines changed: 200 additions & 0 deletions

File tree

cores/xmc/WInterrupts.c

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
//****************************************************************************
2+
// @Project Includes
3+
//****************************************************************************
4+
#include "Arduino.h"
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
//****************************************************************************
9+
// @Prototypes Of Local Functions
10+
//****************************************************************************
11+
static voidFuncPtr interrupt_0_cb = NULL;
12+
static voidFuncPtr interrupt_1_cb = NULL;
13+
14+
//****************************************************************************
15+
// @Local Functions
16+
//****************************************************************************
17+
#if defined(INTERRUPT_USE_ERU)
18+
void ERU0_3_IRQHandler(void) {
19+
if (interrupt_0_cb) {
20+
interrupt_0_cb();
21+
}
22+
}
23+
24+
#if defined(XMC4200_Platform2GO)
25+
void ERU0_0_IRQHandler(void) {
26+
if (interrupt_1_cb) {
27+
interrupt_1_cb();
28+
}
29+
}
30+
#else
31+
void ERU1_0_IRQHandler(void) {
32+
if (interrupt_1_cb) {
33+
interrupt_1_cb();
34+
}
35+
}
36+
#endif
37+
38+
#else
39+
void CCU40_0_IRQHandler(void) {
40+
if (interrupt_0_cb) {
41+
interrupt_0_cb();
42+
}
43+
}
44+
45+
void CCU40_1_IRQHandler(void) {
46+
if (interrupt_1_cb) {
47+
interrupt_1_cb();
48+
}
49+
}
50+
#endif
51+
52+
void attachInterrupt(pin_size_t interrupt_num, voidFuncPtr callback, PinStatus mode) {
53+
XMC_PIN_INTERRUPT_t pin_irq = mapping_interrupt[interrupt_num];
54+
#if defined(INTERRUPT_USE_ERU)
55+
XMC_ERU_ETL_EDGE_DETECTION_t event_config = 0;
56+
57+
switch (mode) {
58+
case CHANGE:
59+
event_config = XMC_ERU_ETL_EDGE_DETECTION_BOTH;
60+
break;
61+
62+
case RISING:
63+
event_config = XMC_ERU_ETL_EDGE_DETECTION_RISING;
64+
break;
65+
66+
case FALLING:
67+
event_config = XMC_ERU_ETL_EDGE_DETECTION_FALLING;
68+
break;
69+
70+
default:
71+
event_config = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_NONE;
72+
break;
73+
}
74+
75+
XMC_ERU_Enable(pin_irq.eru);
76+
XMC_ERU_ETL_SetInput(pin_irq.eru, pin_irq.etl, pin_irq.input_a, pin_irq.input_b);
77+
XMC_ERU_ETL_SetEdgeDetection(pin_irq.eru, pin_irq.etl, event_config);
78+
XMC_ERU_ETL_SetSource(pin_irq.eru, pin_irq.etl, XMC_ERU_ETL_SOURCE_B);
79+
XMC_ERU_ETL_EnableOutputTrigger(pin_irq.eru, pin_irq.etl, pin_irq.ogu);
80+
XMC_ERU_OGU_SetServiceRequestMode(pin_irq.eru, pin_irq.ogu,
81+
XMC_ERU_OGU_SERVICE_REQUEST_ON_TRIGGER);
82+
83+
if (pin_irq.irq_num == 0) {
84+
NVIC_SetPriority(ERU0_3_IRQn, 3);
85+
interrupt_0_cb = callback;
86+
NVIC_EnableIRQ(ERU0_3_IRQn);
87+
} else if (pin_irq.irq_num == 1) {
88+
#if defined(XMC4200_Platform2GO)
89+
NVIC_SetPriority(ERU0_0_IRQn, 3);
90+
interrupt_1_cb = callback;
91+
NVIC_EnableIRQ(ERU0_0_IRQn);
92+
#else
93+
NVIC_SetPriority(ERU1_0_IRQn, 3);
94+
interrupt_1_cb = callback;
95+
NVIC_EnableIRQ(ERU1_0_IRQn);
96+
#endif
97+
}
98+
#else
99+
XMC_CCU4_SLICE_EVENT_CONFIG_t event_config = {0};
100+
101+
switch (mode) {
102+
case CHANGE:
103+
event_config.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_DUAL_EDGE;
104+
break;
105+
106+
case RISING:
107+
event_config.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_RISING_EDGE;
108+
break;
109+
110+
case FALLING:
111+
event_config.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_FALLING_EDGE;
112+
break;
113+
114+
default:
115+
event_config.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_NONE;
116+
break;
117+
}
118+
119+
XMC_CCU4_Init(pin_irq.ccu, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR);
120+
XMC_CCU4_EnableClock(pin_irq.ccu, pin_irq.slice_num);
121+
122+
if (pin_irq.irq_num == 0) {
123+
#if defined(XMC1100_Boot_Kit) || defined(XMC1400_Arduino_Kit) || defined(XMC1400_XMC2GO)
124+
/* P1_4 external interrupt goes through USIC to CCU4 */
125+
XMC_USIC_CH_Enable(XMC_USIC0_CH0);
126+
XMC_USIC_CH_SetInputSource(XMC_USIC0_CH0, XMC_USIC_CH_INPUT_DX5, USIC0_C0_DX5_P1_4);
127+
XMC_USIC_CH_SetInputSource(XMC_USIC0_CH0, XMC_USIC_CH_INPUT_DX2, USIC0_C0_DX2_DX5INS);
128+
#endif
129+
XMC_CCU4_SLICE_EnableMultipleEvents(pin_irq.slice, XMC_CCU4_SLICE_MULTI_IRQ_ID_EVENT0);
130+
XMC_CCU4_SLICE_SetInterruptNode(pin_irq.slice, XMC_CCU4_SLICE_IRQ_ID_EVENT0, 0);
131+
NVIC_SetPriority(CCU40_0_IRQn, 3);
132+
133+
event_config.mapped_input = pin_irq.input;
134+
XMC_CCU4_SLICE_ConfigureEvent(pin_irq.slice, XMC_CCU4_SLICE_EVENT_0, &event_config);
135+
136+
interrupt_0_cb = callback;
137+
NVIC_EnableIRQ(CCU40_0_IRQn);
138+
} else if (pin_irq.irq_num == 1) {
139+
#if defined(XMC1300_Boot_Kit)
140+
/* P0_13 external interrupt goes through USIC to CCU4 */
141+
XMC_USIC_CH_Enable(XMC_USIC0_CH0);
142+
XMC_USIC_CH_SetInputSource(XMC_USIC0_CH0, XMC_USIC_CH_INPUT_DX2, USIC0_C0_DX2_P0_13);
143+
#endif
144+
#if defined(XMC1400_Arduino_Kit)
145+
/* P1_1 external interrupt goes through USIC to CCU4 */
146+
XMC_USIC_CH_Enable(XMC_USIC0_CH1);
147+
XMC_USIC_CH_SetInputSource(XMC_USIC0_CH1, XMC_USIC_CH_INPUT_DX2, USIC0_C1_DX2_P1_1);
148+
#endif
149+
XMC_CCU4_SLICE_EnableMultipleEvents(pin_irq.slice, XMC_CCU4_SLICE_MULTI_IRQ_ID_EVENT1);
150+
XMC_CCU4_SLICE_SetInterruptNode(pin_irq.slice, XMC_CCU4_SLICE_IRQ_ID_EVENT1, 1);
151+
NVIC_SetPriority(CCU40_1_IRQn, 3);
152+
153+
event_config.mapped_input = pin_irq.input;
154+
XMC_CCU4_SLICE_ConfigureEvent(pin_irq.slice, XMC_CCU4_SLICE_EVENT_1, &event_config);
155+
156+
interrupt_1_cb = callback;
157+
NVIC_EnableIRQ(CCU40_1_IRQn);
158+
}
159+
#endif
160+
}
161+
162+
void detachInterrupt(pin_size_t interrupt_num) {
163+
#if defined(INTERRUPT_USE_ERU)
164+
XMC_PIN_INTERRUPT_t pin_irq = mapping_interrupt[interrupt_num];
165+
switch (pin_irq.irq_num) {
166+
case 0:
167+
NVIC_DisableIRQ(ERU0_3_IRQn);
168+
break;
169+
170+
case 1:
171+
#if defined(XMC4200_Platform2GO)
172+
NVIC_DisableIRQ(ERU0_0_IRQn);
173+
#else
174+
NVIC_DisableIRQ(ERU1_0_IRQn);
175+
#endif
176+
break;
177+
default:
178+
break;
179+
}
180+
#else
181+
switch (interrupt_num) {
182+
case 0:
183+
NVIC_DisableIRQ(CCU40_0_IRQn);
184+
break;
185+
186+
case 1:
187+
NVIC_DisableIRQ(CCU40_1_IRQn);
188+
break;
189+
default:
190+
break;
191+
}
192+
#endif
193+
194+
}
195+
#ifdef __cplusplus
196+
}
197+
#endif
198+
//****************************************************************************
199+
// END OF FILE
200+
//****************************************************************************

0 commit comments

Comments
 (0)