From cd107be97632cbbec2f4fc9cf2930b66af049e8a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 18 Apr 2020 01:26:32 +0200 Subject: [PATCH] drivers/periph/timer: add timer_set_periodic() --- Makefile.dep | 4 ++++ drivers/include/periph/timer.h | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Makefile.dep b/Makefile.dep index b092f3ecd6..a8183c5f2f 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -1050,6 +1050,10 @@ ifneq (,$(filter periph_gpio_irq,$(USEMODULE))) FEATURES_REQUIRED += periph_gpio endif +ifneq (,$(filter periph_timer_periodic,$(USEMODULE))) + FEATURES_REQUIRED += periph_timer +endif + ifneq (,$(filter devfs_hwrng,$(USEMODULE))) FEATURES_REQUIRED += periph_hwrng endif diff --git a/drivers/include/periph/timer.h b/drivers/include/periph/timer.h index fd4abc0a04..611efd3538 100644 --- a/drivers/include/periph/timer.h +++ b/drivers/include/periph/timer.h @@ -34,6 +34,7 @@ #define PERIPH_TIMER_H #include +#include #include "periph_cpu.h" /** @todo remove dev_enums.h include once all platforms are ported to the updated periph interface */ @@ -69,6 +70,26 @@ extern "C" { typedef unsigned int tim_t; #endif +/** + * @brief Reset the timer when the set() function is called + * + * When set, calling the timer_set_periodic() function resets the timer count value. + */ +#ifndef TIM_FLAG_RESET_ON_SET +#define TIM_FLAG_RESET_ON_SET (0x01) +#endif + +/** + * @brief Reset the timer on match + * + * When set, a match on this channel will reset the timer count value. + * When set on multiple channels, only the channel with the lowest match value + * will be reached. + */ +#ifndef TIM_FLAG_RESET_ON_MATCH +#define TIM_FLAG_RESET_ON_MATCH (0x02) +#endif + /** * @brief Signature of event callback functions triggered from interrupts * @@ -138,6 +159,21 @@ int timer_set(tim_t dev, int channel, unsigned int timeout); */ int timer_set_absolute(tim_t dev, int channel, unsigned int value); +/** + * @brief Set an absolute timeout value for the given channel of the given timer + * The timeout will be called periodically for each iteration + * + * @param[in] dev the timer device to set + * @param[in] channel the channel to set + * @param[in] value the absolute compare value when the callback will be + * triggered + * @param[in] flags options + * + * @return 0 on success + * @return -1 on error + */ +int timer_set_periodic(tim_t dev, int channel, unsigned int value, uint8_t flags); + /** * @brief Clear the given channel of the given timer device *