Skip to content

Commit

Permalink
drivers/periph: Add timer_poll feature and timer_poll_channel function
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn authored and MrKevinWeiss committed Dec 19, 2023
1 parent d32c32f commit 02285fd
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpu/nrf5x_common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cpu/nrf5x_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions cpu/nrf5x_common/include/timer_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2015 Jan Wagner <[email protected]>
* 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 <[email protected]>
*/

#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 */
/** @} */
34 changes: 34 additions & 0 deletions drivers/include/periph/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <limits.h>
#include <stdint.h>
#include <stdbool.h>

#include "architecture.h"
#include "periph_cpu.h"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions kconfigs/Kconfig.features
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 02285fd

Please sign in to comment.