1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-20 12:03:52 +01:00
RIOT/sys/include/ztimer/periph_timer.h
Marian Buschsieweke 25b8d65f68
sys/ztimer: make use of periph_timer_query_freqs
This makes use of the `periph_timer_query_freqs` feature:

1. It does choose the closest frequency supported before calling
   timer_init() in the ztimer_periph_timer backend.
2. It does make use of the actually chosen frequency when using
   `ztimer_convert_frac`.
3. It does `assert()` the frequency is within 5% of the specified when
   no frequency conversion is performed or `ztimer_convert_shift_up`
   is used.
2025-04-15 15:10:07 +02:00

67 lines
1.7 KiB
C

/*
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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.
*/
/**
* @defgroup sys_ztimer_periph_timer ztimer periph/timer backend
* @ingroup sys_ztimer
* @brief ztimer periph/timer backend
*
* This ztimer module implements a ztimer virtual clock on top of periph/timer.
*
* This module has two tuning values:
* "adjust": will be subtracted from every timer set.
* "min": Every timer will be set to max("min", value).
* @{
*
* @file
* @brief ztimer periph/timer backend API
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef ZTIMER_PERIPH_TIMER_H
#define ZTIMER_PERIPH_TIMER_H
#include "ztimer.h"
#include "periph/timer.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief ztimer periph context structure
*/
typedef struct {
ztimer_clock_t super; /**< super class */
tim_t dev; /**< periph timer device */
uint16_t min; /**< optional minimum value */
} ztimer_periph_timer_t;
/**
* @brief ztimer periph initialization
*
* Initializes the given periph timer and sets up the ztimer device.
*
* @param[in] clock ztimer periph device to initialize
* @param[in] dev periph timer to use
* @param[in] freq frequency to configure
* @param[in] max_val maximum value this timer supports
*
* @return The actual frequency the timer has been configured to
*/
uint32_t ztimer_periph_timer_init(ztimer_periph_timer_t *clock, tim_t dev,
uint32_t freq, uint32_t max_val);
#ifdef __cplusplus
}
#endif
#endif /* ZTIMER_PERIPH_TIMER_H */
/** @} */