25
25
26
26
#include <stdlib.h>
27
27
28
- #include "cpu .h"
28
+ #include "bitarithm .h"
29
29
#include "board.h"
30
- #include "periph_conf .h"
30
+ #include "cpu .h"
31
31
#include "periph/timer.h"
32
+ #include "periph_conf.h"
32
33
33
34
#include "vendor/drivers/fsl_clock.h"
34
35
@@ -66,9 +67,9 @@ static const clock_ip_name_t ctimers_clocks[FSL_FEATURE_SOC_CTIMER_COUNT] =
66
67
#error "ERROR in board timer configuration: too many timers defined"
67
68
#endif
68
69
69
- int timer_init (tim_t tim , unsigned long freq , timer_cb_t cb , void * arg )
70
+ int timer_init (tim_t tim , uint32_t freq , timer_cb_t cb , void * arg )
70
71
{
71
- DEBUG ("timer_init(%u, %lu )\n" , tim , freq );
72
+ DEBUG ("timer_init(%u, %" PRIu32 " )\n" , tim , freq );
72
73
if (tim >= TIMER_NUMOF ) {
73
74
return -1 ;
74
75
}
@@ -84,7 +85,7 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
84
85
uint32_t core_freq = CLOCK_GetFreq (kCLOCK_ApbClk );
85
86
uint32_t prescale = (core_freq + freq / 2 ) / freq - 1 ;
86
87
if (prescale == (uint32_t )(-1 )) {
87
- DEBUG ("timer_init: Frequency %lu is too fast for core_freq=%lu" ,
88
+ DEBUG ("timer_init: Frequency %" PRIu32 " is too fast for core_freq=%" PRIu32 ,
88
89
freq , core_freq );
89
90
return -1 ;
90
91
}
@@ -144,14 +145,15 @@ static inline void isr_ctimer_n(CTIMER_Type *dev, uint32_t ctimer_num)
144
145
{
145
146
DEBUG ("isr_ctimer_%" PRIu32 " flags=0x%" PRIx32 "\n" ,
146
147
ctimer_num , dev -> IR );
147
- for (uint32_t i = 0 ; i < TIMER_CHANNELS ; i ++ ) {
148
- if (dev -> IR & (1u << i )) {
149
- /* Note: setting the bit to 1 in the flag register will clear the
150
- * bit. */
151
- dev -> IR = 1u << i ;
152
- dev -> MCR &= ~(CTIMER_MCR_MR0I_MASK << (i * 3 ));
153
- isr_ctx [ctimer_num ].cb (isr_ctx [ctimer_num ].arg , 0 );
154
- }
148
+ unsigned state = dev -> IR & ((1 << TIMER_CHANNELS ) - 1 );
149
+ while (state ) {
150
+ uint8_t channel ;
151
+ state = bitarithm_test_and_clear (state , & channel );
152
+ /* Note: setting the bit to 1 in the flag register will clear the
153
+ * bit. */
154
+ dev -> IR = 1u << channel ;
155
+ dev -> MCR &= ~(CTIMER_MCR_MR0I_MASK << (channel * 3 ));
156
+ isr_ctx [ctimer_num ].cb (isr_ctx [ctimer_num ].arg , channel );
155
157
}
156
158
cortexm_isr_end ();
157
159
}
0 commit comments