diff --git a/cpu/nrf5x_common/Kconfig b/cpu/nrf5x_common/Kconfig index 9a9a8d7736..8e715bb39e 100644 --- a/cpu/nrf5x_common/Kconfig +++ b/cpu/nrf5x_common/Kconfig @@ -20,6 +20,7 @@ depends on !CPU_FAM_NRF53 select HAS_PERIPH_HWRNG select HAS_PERIPH_TEMPERATURE select HAS_PERIPH_TIMER_PERIODIC + select HAS_PERIPH_TIMER_POLL select HAS_PERIPH_TIMER_QUERY_FREQS select HAS_PERIPH_RTT_OVERFLOW select HAS_PERIPH_UART_MODECFG diff --git a/cpu/nrf5x_common/Makefile.features b/cpu/nrf5x_common/Makefile.features index 0bfe5661f3..7f6fdfdd07 100644 --- a/cpu/nrf5x_common/Makefile.features +++ b/cpu/nrf5x_common/Makefile.features @@ -5,6 +5,7 @@ FEATURES_PROVIDED += periph_flashpage_in_address_space FEATURES_PROVIDED += periph_flashpage_pagewise FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_timer_periodic +FEATURES_PROVIDED += periph_timer_poll FEATURES_PROVIDED += periph_timer_query_freqs FEATURES_PROVIDED += periph_uart_modecfg FEATURES_PROVIDED += periph_wdt periph_wdt_cb diff --git a/cpu/nrf5x_common/include/timer_arch.h b/cpu/nrf5x_common/include/timer_arch.h new file mode 100644 index 0000000000..3251452158 --- /dev/null +++ b/cpu/nrf5x_common/include/timer_arch.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2015 Jan Wagner + * 2015-2016 Freie Universität Berlin + * 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_nrf5x_common + * @ingroup drivers_periph_timer + * @{ + * + * @file + * @brief CPU specific part of the timer API + * + * @author Christian Amsüss + */ + +#ifndef TIMER_ARCH_H +#define TIMER_ARCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef DOXYGEN /* hide implementation specific details from Doxygen */ + +static inline bool timer_poll_channel(tim_t tim, int channel) +{ + return timer_config[tim].dev->EVENTS_COMPARE[channel]; +} + +#endif /* DOXYGEN */ +#ifdef __cplusplus +} +#endif + +#endif /* TIMER_ARCH_H */ +/** @} */ diff --git a/drivers/include/periph/timer.h b/drivers/include/periph/timer.h index c4c021aba1..e9321c1963 100644 --- a/drivers/include/periph/timer.h +++ b/drivers/include/periph/timer.h @@ -35,6 +35,7 @@ #include #include +#include #include "architecture.h" #include "periph_cpu.h" @@ -295,6 +296,39 @@ uword_t timer_query_channel_numof(tim_t dev); */ uint32_t timer_query_freqs(tim_t dev, uword_t index); +#if defined(DOXYGEN) +/** + * @brief Check whether a compare channel has matched + * + * @return true once after the channel has matched. + * + * It is currently not defined whether this keeps returning true after a + * channel has been polled until that channel is set, or whether later calls + * return false. + * + * This is typically used in spin loops that wait for a timer's completion: + * + * ~~~ + * while (!timer_poll_channel(tim, chan)) {}; + * ~~~ + * + * This function is only available on platforms that implement the + * `periph_timer_poll` peripheral in addition to `periph_timer`. + * + */ +/* As this function is polled, it needs to be inlined, so it is typically + * provided through timer_arch.h. If a platform ever does not need to go + * through static inline here, this declaration's condition can be extended to + * be `(defined(MODULE_PERIPH_TIMER_POLL) && + * !defined(PERIPH_TIMER_PROVIDES_INLINE_POLL_CHANNEL) || defined(DOXYGEN)` or + * similar. */ +bool timer_poll_channel(tim_t dev, int channel); +#endif + +#if defined(MODULE_PERIPH_TIMER_POLL) +#include "timer_arch.h" +#endif + #ifdef __cplusplus } #endif diff --git a/kconfigs/Kconfig.features b/kconfigs/Kconfig.features index b867d180a4..7614d72a85 100644 --- a/kconfigs/Kconfig.features +++ b/kconfigs/Kconfig.features @@ -572,6 +572,12 @@ config HAS_PERIPH_TIMER_PERIODIC Indicates that the Timer peripheral provides the periodic timeout functionality. +config HAS_PERIPH_TIMER_POLL + bool + help + Indicates that the Timer peripheral supports the timer_poll_channel + function. + config HAS_PERIPH_TIMER_QUERY_FREQS bool help