mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
ztimer/convert: only extend the clocks if ztimer_ondemand isn't used
This commit is contained in:
parent
4013dff1fd
commit
9fbb4d3391
@ -103,7 +103,12 @@ 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_now, UINT32_MAX);
|
||||
#if !MODULE_ZTIMER_ONDEMAND
|
||||
/* extend lower clock only if the ondemand driver isn't selected
|
||||
* otherwise, the clock extension will be called with the first
|
||||
* ztimer_acquire() call */
|
||||
ztimer_init_extend(&self->super.super);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
DEBUG("ztimer_convert_frac_init: rounding up val:%" PRIu32 "\n",
|
||||
|
@ -121,5 +121,10 @@ void ztimer_convert_muldiv64_init(
|
||||
ztimer_convert_muldiv64->super.super.ops = &_ztimer_convert_muldiv64_ops;
|
||||
ztimer_convert_muldiv64->div = div;
|
||||
ztimer_convert_muldiv64->mul = mul;
|
||||
#if !MODULE_ZTIMER_ONDEMAND
|
||||
/* extend lower clock only if the ondemand driver isn't selected
|
||||
* otherwise, the clock extension will be called with the first
|
||||
* ztimer_acquire() call */
|
||||
ztimer_init_extend(&ztimer_convert_muldiv64->super.super);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
USEMODULE += ztimer_core
|
||||
USEMODULE += ztimer_mock
|
||||
USEMODULE += ztimer_convert_muldiv64
|
||||
USEMODULE += ztimer_convert_frac
|
||||
USEMODULE += ztimer_ondemand
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "ztimer.h"
|
||||
#include "ztimer/mock.h"
|
||||
#include "ztimer/convert_frac.h"
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
@ -147,6 +148,33 @@ static void test_ztimer_ondemand_timers(void)
|
||||
TEST_ASSERT_EQUAL_INT(0, zmock.armed);
|
||||
}
|
||||
|
||||
static void test_ztimer_ondemand_timers_converted(void)
|
||||
{
|
||||
ztimer_mock_t zmock;
|
||||
ztimer_convert_frac_t zc;
|
||||
ztimer_clock_t *z = &zc.super.super;
|
||||
|
||||
/* the base timer must be extended */
|
||||
ztimer_mock_init(&zmock, 24);
|
||||
const uint32_t factor = 10;
|
||||
ztimer_convert_frac_init(&zc, &zmock.super, 1, factor);
|
||||
|
||||
z->adjust_clock_start = 10;
|
||||
|
||||
int a_arg = 0;
|
||||
ztimer_t a = {.callback = _set_cb, .arg = &a_arg};
|
||||
const uint32_t a_val = 100;
|
||||
ztimer_set(z, &a, a_val);
|
||||
TEST_ASSERT_EQUAL_INT((a_val - z->adjust_clock_start) * factor, zmock.target);
|
||||
TEST_ASSERT_EQUAL_INT(1, zmock.running);
|
||||
TEST_ASSERT_EQUAL_INT(1, zmock.armed);
|
||||
|
||||
ztimer_mock_advance(&zmock, zmock.target);
|
||||
TEST_ASSERT_EQUAL_INT(HAS_BEEN_EXEC, a_arg);
|
||||
TEST_ASSERT_EQUAL_INT(0, zmock.running);
|
||||
TEST_ASSERT_EQUAL_INT(0, zmock.armed);
|
||||
}
|
||||
|
||||
Test *tests_ztimer_ondemand_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
@ -154,6 +182,7 @@ Test *tests_ztimer_ondemand_tests(void)
|
||||
new_TestFixture(test_ztimer_ondemand_acquire_ops_unsupported),
|
||||
new_TestFixture(test_ztimer_ondemand_acquire_release_extend),
|
||||
new_TestFixture(test_ztimer_ondemand_timers),
|
||||
new_TestFixture(test_ztimer_ondemand_timers_converted),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(ztimer_tests, NULL, NULL, fixtures);
|
||||
|
Loading…
Reference in New Issue
Block a user