mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
ztimer: convert_frac: use self->scale_now for max_value
When using convert_frac to slow down a timer, the extension machinery is used to prevent converting values that would be larger than, after conversion, 2**32. In order to calculate the maximum value, UINT32_MAX is converted. Previously, this was mistakenly converted by multiplying with the fraction used to scale up a value. E.g., when using convert_frac to slow down a 1us timer to provide a 1ms timer, UINT32_MAX was multiplied by 1000. As the result is used % UINT32_MAX, this lead to a wrong value close to UINT32_MAX, as ((UINT32_MAX * N) % UINT32_MAX = (UINT32_MAX - N - 1)). This PR fixes the calculation so max_value is determined by multiplying with the fraction used to scale down a value.
This commit is contained in:
parent
1992f57765
commit
1ff609167e
@ -100,7 +100,7 @@ void ztimer_convert_frac_init(ztimer_convert_frac_t *self,
|
||||
|
||||
ztimer_convert_frac_compute_scale(self, freq_self, freq_lower);
|
||||
if (freq_self < freq_lower) {
|
||||
self->super.super.max_value = frac_scale(&self->scale_set, UINT32_MAX);
|
||||
self->super.super.max_value = frac_scale(&self->scale_now, UINT32_MAX);
|
||||
ztimer_init_extend(&self->super.super);
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user