From d0fccdb54941bc8891138ae73cdb28f2f3498f46 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 27 Jun 2023 19:16:05 +0200 Subject: [PATCH 1/2] drivers/pcf857x: Move compile time check to compilation unit This allows including the header without using the module. Obviously, calls to the functions provided by the header won't like without using the module. But including the header can still be useful for e.g.: if (IS_USED(MODULE_PCF857x)) { /* make use of the module */ } In the above example all calls to pcf857x functions would be optimized out when the module is not used, full compile checks happen in either case. --- drivers/include/pcf857x.h | 4 ---- drivers/pcf857x/pcf857x.c | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/include/pcf857x.h b/drivers/include/pcf857x.h index 4b270be1e6..c2ce3ba888 100644 --- a/drivers/include/pcf857x.h +++ b/drivers/include/pcf857x.h @@ -260,10 +260,6 @@ extern "C" #include "event.h" #endif /* MODULE_PCF857X_IRQ */ -#if !IS_USED(MODULE_PCF8574) && !IS_USED(MODULE_PCF8574A) && !IS_USED(MODULE_PCF8575) -#error "Please provide a list of pcf857x variants used by the application (pcf8574, pcf8574a or pcf8575)" -#endif - /** * @name PCF857X I2C slave addresses * diff --git a/drivers/pcf857x/pcf857x.c b/drivers/pcf857x/pcf857x.c index d74c4a8a18..a37d21b394 100644 --- a/drivers/pcf857x/pcf857x.c +++ b/drivers/pcf857x/pcf857x.c @@ -42,6 +42,10 @@ #endif /* ENABLE_DEBUG */ +#if !IS_USED(MODULE_PCF8574) && !IS_USED(MODULE_PCF8574A) && !IS_USED(MODULE_PCF8575) +#error "Please provide a list of pcf857x variants used by the application (pcf8574, pcf8574a or pcf8575)" +#endif + #if IS_USED(MODULE_PCF857X_IRQ_LOW) #define PCF857X_EVENT_PRIO EVENT_PRIO_LOWEST #elif IS_USED(MODULE_PCF857X_IRQ_MEDIUM) From 63caa457461c31abf947226fe5dd2854a074d701 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 5 Jul 2023 10:24:34 +0200 Subject: [PATCH 2/2] cpu/sam3: assert valid freq in timer_init() The API of timer_init() expects callers to know what frequencies are supported and only use valid frequencies. So let's add an `assert()` to aid debugging if the app uses an invalid. --- cpu/sam3/periph/timer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpu/sam3/periph/timer.c b/cpu/sam3/periph/timer.c index d4485f1714..721b6f879f 100644 --- a/cpu/sam3/periph/timer.c +++ b/cpu/sam3/periph/timer.c @@ -111,7 +111,12 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg) * channel 1 toggles this line on each timer tick, the actual frequency * driving channel 0 is f_ch2 / 2 --> f_ch0/1 = (MCK / 2) / 2 / freq. */ - dev(tim)->TC_CHANNEL[1].TC_RC = (CLOCK_CORECLOCK / 4) / freq; + uint32_t tc_rc = (CLOCK_CORECLOCK / 4) / freq; + /* the API expects apps to know in advance which frequencies are possible + * and only configure with supported frequencies. So aid debugging with + * an assert */ + assert(tc_rc * freq == CLOCK_CORECLOCK / 4); + dev(tim)->TC_CHANNEL[1].TC_RC = tc_rc; /* start channel 1 */ dev(tim)->TC_CHANNEL[1].TC_CCR = (TC_CCR_CLKEN | TC_CCR_SWTRG);