Skip to content

Commit 0d85356

Browse files
committed
cpu/qn908x: use bitarithm_test_and_clear() & fix cb
Previously, the callback was incorrectly passed a channel of zero as argument regardless of the channel that triggered the IRQ. This fixes the issue and also uses `bitarithm_test_and_clear()` to only iterate over the channels that actually have an IRQ flag set, rather than all channels.
1 parent c950286 commit 0d85356

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

cpu/qn908x/periph/timer.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626
#include <stdlib.h>
2727

28-
#include "cpu.h"
28+
#include "bitarithm.h"
2929
#include "board.h"
30-
#include "periph_conf.h"
30+
#include "cpu.h"
3131
#include "periph/timer.h"
32+
#include "periph_conf.h"
3233

3334
#include "vendor/drivers/fsl_clock.h"
3435

@@ -144,14 +145,15 @@ static inline void isr_ctimer_n(CTIMER_Type *dev, uint32_t ctimer_num)
144145
{
145146
DEBUG("isr_ctimer_%" PRIu32 " flags=0x%" PRIx32 "\n",
146147
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);
155157
}
156158
cortexm_isr_end();
157159
}

0 commit comments

Comments
 (0)