ztimer frequency conversion module (64bit arithmetic) More...
ztimer frequency conversion module (64bit arithmetic)
This ztimer module allows converting a lower-level ztimer clockwith a given frequency to another frequency.
It is configured by passing two parameters (div, mul). Given a lower clock frequency f_low and a desired upper frequency f_upper, div and mul must be chosen such that
(f_upper * mul / div) == f_lower
A div or mul value of 0 is treated as 1 (no multiplication or division by 0 is done).
On every ztimer_set(), the target offset is first multiplied by mul and then divided by div, before passing it to the lower ztimer's ztimer_set().
On every ztimer_now(), the value from the lower ztimer is first multiplied by div and then divided by mul.
Multiplication and division is done using 64bit multiplication / division, thus its use should be avoided in favour of more optimized conversion modules.
Example:
Files | |
file | convert_muldiv64.h |
ztimer frequency conversion module API | |
Data Structures | |
struct | ztimer_convert_muldiv64_t |
ztimer_convert_muldiv64 structure More... | |
Functions | |
void | ztimer_convert_muldiv64_init (ztimer_convert_muldiv64_t *ztimer_convert_muldiv64, ztimer_clock_t *lower, unsigned div, unsigned mul) |
ztimer_convert_muldiv64 initialization function More... | |
void ztimer_convert_muldiv64_init | ( | ztimer_convert_muldiv64_t * | ztimer_convert_muldiv64, |
ztimer_clock_t * | lower, | ||
unsigned | div, | ||
unsigned | mul | ||
) |
ztimer_convert_muldiv64 initialization function
[in] | ztimer_convert_muldiv64 | instance to initialize |
[in] | lower | lower timer to convert |
[in] | div | see module doc |
[in] | mul | see module doc |