@@ -3,30 +3,30 @@ static XMC_CCU4_SLICE_t *active_pwm4_slice = nullptr; // Active CCU4 slice
33static XMC_CCU8_SLICE_t *active_pwm8_slice = nullptr ; // Active CCU8 slice
44static XMC_CCU4_MODULE_t *active_pwm4_ccu = nullptr ; // Active CCU4 module
55static XMC_CCU8_MODULE_t *active_pwm8_ccu = nullptr ; // Active CCU8 module
6- uint8_t slice_number;
6+ volatile uint8_t slice_number_ccu4;
7+ volatile uint8_t slice_number_ccu8;
8+
79
8- static volatile bool timer_interrupt_ccu4 = false ;
910
1011#ifdef __cplusplus
1112extern " C" {
1213#endif
1314void CCU43_0_IRQHandler (void ) {
1415if (active_pwm4_slice != nullptr && active_pwm4_ccu != nullptr ) {
1516 XMC_CCU4_SLICE_StopTimer (active_pwm4_slice);
16- XMC_CCU4_DisableClock (active_pwm4_ccu, slice_number ); // Disable the clock
17+ XMC_CCU4_DisableClock (active_pwm4_ccu, slice_number_ccu4 ); // Disable the clock
1718
1819 active_pwm4_slice = nullptr ; // Clear the active CCU4 slice
1920 active_pwm4_ccu = nullptr ; // Clear the active CCU4 module
2021}
2122if (active_pwm8_slice != nullptr && active_pwm8_ccu != nullptr ) {
2223 XMC_CCU8_SLICE_StopTimer (active_pwm8_slice);
23- XMC_CCU8_DisableClock (active_pwm8_ccu, slice_number );
24+ XMC_CCU8_DisableClock (active_pwm8_ccu, slice_number_ccu8 );
2425 active_pwm8_slice = nullptr ; // Clear the active CCU8 slice
2526 active_pwm8_ccu = nullptr ; // Clear the active CCU8 module
2627}
27- XMC_CCU4_SLICE_StopTimer (CCU43_CC40);
28+ XMC_CCU4_SLICE_StopTimer (CCU43_CC40);
2829 XMC_CCU4_SLICE_ClearEvent (CCU43_CC40, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
29- timer_interrupt_ccu4 = true ;
3030
3131}
3232
@@ -48,7 +48,7 @@ class Tone {
4848 XMC_PWM4_t *pwm4 = &mapping_pwm4[pin_index];
4949 active_pwm4_slice = pwm4->slice ; // Store the active CCU4 slice
5050 active_pwm4_ccu = pwm4->ccu ; // Store the active CCU4 module
51- slice_number = pwm4->slice_num ; // Store the slice number
51+ slice_number_ccu4 = pwm4->slice_num ; // Store the slice number
5252 configureTone (pin, frequency);
5353 XMC_GPIO_SetMode (pwm4->port_pin .port , pwm4->port_pin .pin ,
5454 (XMC_GPIO_MODE_t)(XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm4->port_mode ));
@@ -62,6 +62,7 @@ class Tone {
6262 XMC_PWM8_t *pwm8 = &mapping_pwm8[pin_index];
6363 active_pwm8_slice = pwm8->slice ; // Store the active CCU8 slice
6464 active_pwm8_ccu = pwm8->ccu ; // Store the active CCU8 module
65+ slice_number_ccu8 = pwm8->slice_num ;
6566 configureTone (pin, frequency);
6667 XMC_GPIO_SetMode (pwm8->port_pin .port , pwm8->port_pin .pin ,
6768 (XMC_GPIO_MODE_t)(XMC_GPIO_MODE_OUTPUT_PUSH_PULL | pwm8->port_mode ));
@@ -95,7 +96,6 @@ class Tone {
9596private:
9697 void configureTone (pin_size_t pin, unsigned int frequency) {
9798 int pin_index;
98- timer_interrupt_ccu4 = false ;
9999
100100 if ((pin_index = scanMapTable (mapping_pin_PWM4, pin)) >= 0 ) {
101101 XMC_PWM4_t *pwm4 = &mapping_pwm4[pin_index];
@@ -145,7 +145,6 @@ class Tone {
145145 }
146146
147147 void configureTimerInterrupt (unsigned long duration_ms) {
148- timer_interrupt_ccu4 = false ;
149148 XMC_CCU4_Init (CCU43, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR);
150149 XMC_CCU4_SLICE_COMPARE_CONFIG_t timer_config;
151150 timer_config.timer_mode = XMC_CCU4_SLICE_TIMER_COUNT_MODE_EA;
0 commit comments