From f55e438d569dddabb66bcf3de21fade10e673547 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 5 Nov 2019 13:17:05 +0100 Subject: [PATCH] boards/atmega328p: Fixed xtimer frequency The ATmega328p on a breadboard can have various frequencies depending on the fuse settings and whether and which crystal is connected. Thus, finding a fixed xtimer frequency that can be configured for every CPU core clock with the available prescalers is not possible. Therefore, the fixed frequency is replaced by a frequency depending on the CPU clock speed. For CPU clock frequency of more than 4 MHz a prescaler of 64 will be chosen (same as on the Arduino Uno), for 4 MHz and less a prescaler of 8 will be chosen. --- boards/atmega328p/include/board.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/boards/atmega328p/include/board.h b/boards/atmega328p/include/board.h index 283dcdc8af..0af1eb1def 100644 --- a/boards/atmega328p/include/board.h +++ b/boards/atmega328p/include/board.h @@ -24,6 +24,7 @@ #define BOARD_H #include "cpu.h" +#include "periph_conf.h" #ifdef __cplusplus extern "C" { @@ -44,7 +45,11 @@ extern "C" { * @{ */ #define XTIMER_WIDTH (16) -#define XTIMER_HZ (250000UL) +#if CLOCK_CORECLOCK > 4000000UL +#define XTIMER_HZ (CLOCK_CORECLOCK / 64) +#else +#define XTIMER_HZ (CLOCK_CORECLOCK / 8) +#endif #define XTIMER_BACKOFF (40) /** @} */