1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/include/ztimer/convert_shift.h
Kaspar Schleiser 6dd79366bb sys: add ztimer subsystem
Co-authored-by: Joakim Nohlgård <joakim.nohlgard@eistec.se>
2020-03-04 12:44:02 +01:00

72 lines
1.8 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_convert_shift conversion using shifts
* @ingroup sys_ztimer_convert
* @brief Translates between clock tick rates
*
* Translates the ticks of an underlying clock into virtual ticks at a different
* frequency, by using bit shifts. Thus it works only for fractions that are
* powers of 2.
*
* @{
* @file
* @brief ztimer_convert_shift interface definitions
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef ZTIMER_CONVERT_SHIFT_H
#define ZTIMER_CONVERT_SHIFT_H
#include <stdint.h>
#include "ztimer.h"
#include "ztimer/convert.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief ztimer_convert_shift frequency conversion layer class
*/
typedef struct {
/**
* @brief Superclass instance
*/
ztimer_convert_t super;
/**
* @brief Frequency conversion scaling constant from lower to self
*
* This value is saved as positive integer. The functions within the "ops"
* struct decides whether to left or right shift.
*/
unsigned shift;
} ztimer_convert_shift_t;
/**
* @brief ztimer_convert_shift init() for (fake) increasing timer frequency
*
* Will cause every lower now() to be left-shifted and every set() to be
* right-shifted.
*
* @param[in] clock pointer to instance being initialized
* @param[in] lower pointer to underlying clock
* @param[in] shift shift value to use
*/
void ztimer_convert_shift_up_init(ztimer_convert_shift_t *clock,
ztimer_clock_t *lower, unsigned shift);
#ifdef __cplusplus
}
#endif
#endif /* ZTIMER_CONVERT_SHIFT_H */
/** @} */