5 #include "sw/device/lib/testing/aon_timer_testutils.h"
10 #include "dt/dt_aon_timer.h"
11 #include "dt/dt_api.h"
16 #include "sw/device/lib/testing/test_framework/check.h"
18 #define MODULE_ID MAKE_MODULE_ID('a', 'o', 't')
20 status_t aon_timer_testutils_get_aon_cycles_32_from_us(uint64_t microseconds,
23 udiv64_slow(microseconds * dt_clock_frequency(dt_aon_timer_clock(
24 kDtAonTimerAon, kDtAonTimerClockAon)),
27 TRY_CHECK(cycles_ <= UINT32_MAX,
28 "The value 0x%08x%08x can't fit into the 32 bits timer counter.",
29 (uint32_t)(cycles_ >> 32), (uint32_t)cycles_);
30 *cycles = (uint32_t)cycles_;
34 status_t aon_timer_testutils_get_aon_cycles_64_from_us(uint64_t microseconds,
37 udiv64_slow(microseconds * dt_clock_frequency(dt_aon_timer_clock(
38 kDtAonTimerAon, kDtAonTimerClockAon)),
44 status_t aon_timer_testutils_get_us_from_aon_cycles(uint64_t cycles,
47 dt_clock_frequency(dt_aon_timer_clock(
48 kDtAonTimerAon, kDtAonTimerClockAon)),
50 TRY_CHECK(uss <= UINT32_MAX,
51 "The value 0x%08x%08x can't fit into the 32 bits timer counter.",
52 (uint32_t)(uss >> 32), (uint32_t)uss);
57 status_t aon_timer_testutils_wakeup_config(
const dif_aon_timer_t *aon_timer,
63 TRY(dif_aon_timer_irq_acknowledge(aon_timer,
64 kDifAonTimerIrqWkupTimerExpired));
66 bool is_pending =
true;
67 TRY(dif_aon_timer_irq_is_pending(aon_timer, kDifAonTimerIrqWkupTimerExpired,
69 TRY_CHECK(!is_pending);
76 status_t aon_timer_testutils_watchdog_config(
const dif_aon_timer_t *aon_timer,
79 bool pause_in_sleep) {
84 TRY(dif_aon_timer_irq_acknowledge(aon_timer, kDifAonTimerIrqWdogTimerBark));
85 bool is_pending =
true;
86 TRY(dif_aon_timer_irq_is_pending(aon_timer, kDifAonTimerIrqWdogTimerBark,
88 TRY_CHECK(!is_pending);
90 pause_in_sleep,
false));
94 status_t aon_timer_testutils_shutdown(
const dif_aon_timer_t *aon_timer) {
98 TRY(dif_aon_timer_irq_acknowledge_all(aon_timer));
103 TRY_CHECK(enabled ==
false);
105 TRY_CHECK(enabled ==
false);