Skip to content

Commit

Permalink
cpu/msp430/periph_timer: add a static_assert() for clear mask
Browse files Browse the repository at this point in the history
The driver assumes that timer A and timer B have the same register
layout regarding all the features exposed by the driver. This is
backed by the MCU family datasheets for the MSP430 x1xx and the
MSP430 G2xx / F2xx MCUs (and likely more families).

The assert() is pretty limited in coverage, but more to document why
a "timer A clear" mask is used but still claiming the driver also
works for timer B. It just looks too much like a bug otherwise.
  • Loading branch information
maribu committed Apr 14, 2024
1 parent 3cdc437 commit 2ef9491
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cpu/msp430/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
assume((unsigned)dev < TIMER_NUMOF);
msp430_timer_t *msptimer = timer_conf[dev].timer;

/* reset the timer A configuration */
static_assert(TACLR == TBCLR, "This driver assumes TIMER A and TIMER B "
"having the same register layout for the "
"features exposed by this driver. This "
"is backed by the datasheet for both "
"MSP430 x1xx and G2xx / F2xx MCUs.");
/* reset the timer configuration */
msptimer->CTL = TACLR;
/* save callback */
isr_ctx[dev].cb = cb;
Expand Down

0 comments on commit 2ef9491

Please sign in to comment.