Skip to content

Commit 0284255

Browse files
dineshgit411LinjingZhang
authored andcommitted
cores/xmc: Modified Interrupt handler.
Signed-off-by: MDin <Dinesh.M-EE@infineon.com>
1 parent 08c2b86 commit 0284255

1 file changed

Lines changed: 33 additions & 55 deletions

File tree

cores/xmc/Tone.cpp

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
#include "Arduino.h"
2+
static XMC_CCU4_SLICE_t *active_pwm4_slice = nullptr; // Active CCU4 slice
3+
static XMC_CCU8_SLICE_t *active_pwm8_slice = nullptr; // Active CCU8 slice
4+
static XMC_CCU4_MODULE_t *active_pwm4_ccu = nullptr; // Active CCU4 module
5+
static XMC_CCU8_MODULE_t *active_pwm8_ccu = nullptr; // Active CCU8 module
6+
uint8_t slice_number;
27

3-
XMC_PWM4_t *pwm4;
48
static volatile bool timer_interrupt_ccu4 = false;
5-
static volatile bool timer_interrupt_ccu8 = false;
69

710
#ifdef __cplusplus
811
extern "C" {
912
#endif
1013
void CCU43_0_IRQHandler(void) {
14+
if(active_pwm4_slice != nullptr && active_pwm4_ccu != nullptr) {
15+
XMC_CCU4_SLICE_StopTimer(active_pwm4_slice);
16+
XMC_CCU4_DisableClock(active_pwm4_ccu, slice_number); // Disable the clock
1117

12-
XMC_CCU4_SLICE_StopTimer(CCU43_CC40);
18+
active_pwm4_slice = nullptr; // Clear the active CCU4 slice
19+
active_pwm4_ccu = nullptr; // Clear the active CCU4 module
20+
}
21+
if(active_pwm8_slice != nullptr && active_pwm8_ccu != nullptr) {
22+
XMC_CCU8_SLICE_StopTimer(active_pwm8_slice);
23+
XMC_CCU8_DisableClock(active_pwm8_ccu, slice_number);
24+
active_pwm8_slice = nullptr; // Clear the active CCU8 slice
25+
active_pwm8_ccu = nullptr; // Clear the active CCU8 module
26+
}
27+
XMC_CCU4_SLICE_StopTimer(CCU43_CC40);
1328
XMC_CCU4_SLICE_ClearEvent(CCU43_CC40, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
1429
timer_interrupt_ccu4 = true;
1530

1631
}
1732

18-
void CCU81_0_IRQHandler(void) {
19-
XMC_CCU8_SLICE_StopTimer(CCU81_CC80);
20-
XMC_CCU8_SLICE_ClearEvent(CCU81_CC80, XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH);
21-
timer_interrupt_ccu8 = true;
22-
}
2333
#ifdef __cplusplus
2434
}
2535
#endif
@@ -36,36 +46,40 @@ class Tone {
3646
int pin_index;
3747
if ((pin_index = scanMapTable(mapping_pin_PWM4, pin)) >= 0) {
3848
XMC_PWM4_t *pwm4 = &mapping_pwm4[pin_index];
49+
active_pwm4_slice = pwm4->slice; // Store the active CCU4 slice
50+
active_pwm4_ccu = pwm4->ccu; // Store the active CCU4 module
51+
slice_number = pwm4->slice_num; // Store the slice number
3952
configureTone(pin, frequency);
4053
XMC_GPIO_SetMode(pwm4->port_pin.port, pwm4->port_pin.pin,
4154
(XMC_GPIO_MODE_t)(XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm4->port_mode));
4255
XMC_CCU4_SLICE_StartTimer(pwm4->slice);
4356
if(duration >0) {
4457
configureTimerInterrupt(duration);
45-
if(timer_interrupt_ccu4 == true)
46-
{
47-
XMC_CCU4_SLICE_StopTimer(pwm4->slice);
48-
timer_interrupt_ccu4 = false;
49-
50-
}
58+
// if(timer_interrupt_ccu4 == true)
59+
// {
60+
// XMC_CCU4_SLICE_StopTimer(pwm4->slice);
61+
// timer_interrupt_ccu4 = false;
62+
// }
5163
}
5264
}
5365
#if defined(CCU8V2) || defined(CCU8V1)
5466
else if ((pin_index = scanMapTable(mapping_pin_PWM8, pin)) >= 0) {
5567
XMC_PWM8_t *pwm8 = &mapping_pwm8[pin_index];
68+
active_pwm8_slice = pwm8->slice; // Store the active CCU8 slice
69+
active_pwm8_ccu = pwm8->ccu; // Store the active CCU8 module
5670
configureTone(pin, frequency);
5771
XMC_GPIO_SetMode(pwm8->port_pin.port, pwm8->port_pin.pin,
5872
(XMC_GPIO_MODE_t)(XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm8->port_mode));
5973
XMC_CCU8_SLICE_StartTimer(pwm8->slice);
6074
// calculate pulses
6175
if(duration >0) {
6276
configureTimerInterrupt(duration);
63-
if(timer_interrupt_ccu8 == true)
64-
{
65-
XMC_CCU8_SLICE_StopTimer(pwm8->slice);
66-
timer_interrupt_ccu8 = false;
77+
// if(timer_interrupt_ccu4 == true)
78+
// {
79+
// XMC_CCU8_SLICE_StopTimer(pwm8->slice);
80+
// timer_interrupt_ccu4 = false;
6781

68-
}
82+
// }
6983
}
7084
}
7185
#endif
@@ -136,7 +150,6 @@ class Tone {
136150
XMC_CCU8_EnableShadowTransfer(
137151
pwm8->ccu, XMC_CCU8_SHADOW_TRANSFER_SLICE_0 | XMC_CCU8_SHADOW_TRANSFER_SLICE_2 |
138152
XMC_CCU8_SHADOW_TRANSFER_SLICE_3 | XMC_CCU8_SHADOW_TRANSFER_SLICE_1);
139-
timer_interrupt_ccu8 = false;
140153

141154
}
142155
#endif
@@ -171,41 +184,6 @@ class Tone {
171184
NVIC_SetPriority(CCU43_0_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 63, 0));
172185

173186
NVIC_EnableIRQ(CCU43_0_IRQn);
174-
175-
#if defined(CCU8V2) || defined(CCU8V1)
176-
timer_interrupt_ccu8 = false;
177-
XMC_CCU8_Init(CCU81, XMC_CCU8_SLICE_MCMS_ACTION_TRANSFER_PR_CR);
178-
XMC_CCU8_SLICE_COMPARE_CONFIG_t timer_config_ccu8;
179-
timer_config_ccu8.timer_mode = XMC_CCU8_SLICE_TIMER_COUNT_MODE_EA;
180-
timer_config_ccu8.monoshot = XMC_CCU8_SLICE_TIMER_REPEAT_MODE_SINGLE;
181-
timer_config_ccu8.prescaler_mode = XMC_CCU8_SLICE_PRESCALER_MODE_NORMAL;
182-
timer_config_ccu8.prescaler_initval = XMC_CCU8_SLICE_PRESCALER_32768;
183-
timer_config_ccu8.float_limit = XMC_CCU8_SLICE_PRESCALER_32768;
184-
timer_config_ccu8.passive_level_out0 = XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_LOW;
185-
timer_config_ccu8.passive_level_out1 = XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_LOW;
186-
timer_config_ccu8.passive_level_out2 = XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_LOW;
187-
timer_config_ccu8.passive_level_out3 = XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_LOW;
188-
189-
XMC_CCU8_SLICE_CompareInit(CCU81_CC80, &timer_config_ccu8);
190-
191-
// Calculate period for the timer based on the duration
192-
uint32_t timer_ticks_ccu8 = (PCLK / 32768) * duration_ms / 1000;
193-
XMC_CCU8_SLICE_SetTimerPeriodMatch(CCU81_CC80, timer_ticks_ccu8);
194-
XMC_CCU8_SetMultiChannelShadowTransferMode(CCU81, XMC_CCU8_MULTI_CHANNEL_SHADOW_TRANSFER_SW_SLICE0);
195-
XMC_CCU8_EnableShadowTransfer(CCU81,XMC_CCU8_SHADOW_TRANSFER_SLICE_0);
196-
XMC_CCU8_SLICE_SetInterruptNode(CCU81_CC80, XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH, XMC_CCU8_SLICE_SR_ID_0);
197-
XMC_CCU8_SLICE_EnableEvent(CCU81_CC80, XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH);
198-
XMC_CCU8_EnableClock(CCU81, 0);
199-
200-
// Enable the NVIC interrupt
201-
XMC_CCU8_SLICE_SetTimerValue(CCU81_CC80, 0U);
202-
203-
// Start the timer
204-
XMC_CCU8_SLICE_StartTimer(CCU81_CC80);
205-
NVIC_SetPriority(CCU81_0_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 63, 0));
206-
207-
NVIC_EnableIRQ(CCU81_0_IRQn);
208-
#endif
209187
}
210188

211189
// Scan the pwm pin mapping table

0 commit comments

Comments
 (0)