1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/periph: Add timer_poll feature and timer_poll_channel function

This commit is contained in:
chrysn 2023-08-17 14:45:42 +02:00 committed by MrKevinWeiss
parent d32c32ffae
commit 02285fd63a
No known key found for this signature in database
GPG Key ID: C26684F1C0767FFF
5 changed files with 84 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,42 @@
/*
* Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
* 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 <chrysn@fsfe.org>
*/
#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 */
/** @} */

View File

@ -35,6 +35,7 @@
#include <limits.h>
#include <stdint.h>
#include <stdbool.h>
#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

View File

@ -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