All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches

ztimer frequency conversion module (64bit arithmetic) More...

Detailed Description

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:

  1. if a ztimer_periph_timer with 250kHz is to be "sped up" to 1MHz, use div=4, mul=0
  2. if a ztimer with 1024Hz is to be converted to 1000Hz, use div=125, mul=128

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
 

Function Documentation

◆ ztimer_convert_muldiv64_init()

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

Parameters
[in]ztimer_convert_muldiv64instance to initialize
[in]lowerlower timer to convert
[in]divsee module doc
[in]mulsee module doc