sys/ztimer: make use of periph_timer_query_freqs #20582
Open
+144
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution description
This makes use of the
periph_timer_query_freqs
feature:ztimer_convert_frac
.assert()
the frequency is within 5% of the specified when no frequency conversion is performed orztimer_convert_shift_up
is used.Motivation
We have a number of MCUs that can run from internal oscillators (without using external crystal for accuracy):
periph_timer
, so not relevant here)If those MCUs are used without external crystal, the actual CPU frequency may be off from what the the board config aims for significantly due to large production variance and temperature and supply voltage dependence. As a result, all
periph_timer
instances driven by the same clock will also be off significantly, which can hinder accuracy in time keeping significantly.This adds the support to ztimer to react on the actual frequency information provided by
periph_timer_query_freqs
and adjust the time keeping accordingly.Testing procedure
As of now, only the MSP430 (and the FE310) will measure the actual CPU frequency at runtime, and only the MSP430 timer will compensate frequencies exposed via
timer_query_freqs()
. So only on MSP430 this can really be tested now, e.g. withtests/sys/ztimer_msg
.In
master
this test sadly fails because oftimer_set()
not yet working correctly on small timeouts (and waiting one period longer than needed).With this PR the test passes and the messages at second 30 is indeed about thirty seconds after the start message received. (It would be off by 40 % without compensation.)
Issues/PRs references
timer_get_closest_freq()
#20581Fixes #8251