15 #include "sw/device/lib/testing/aon_timer_testutils.h"
16 #include "sw/device/lib/testing/pwrmgr_testutils.h"
17 #include "sw/device/lib/testing/rstmgr_testutils.h"
18 #include "sw/device/lib/testing/test_framework/check.h"
23 OTTF_DEFINE_TEST_CONFIG();
28 static void config_wdog(
const dif_aon_timer_t *aon_timer,
29 const dif_pwrmgr_t *pwrmgr, uint64_t bark_time_us,
30 uint64_t bite_time_us) {
31 uint32_t bark_cycles = 0;
32 CHECK_STATUS_OK(aon_timer_testutils_get_aon_cycles_32_from_us(bark_time_us,
34 uint32_t bite_cycles = 0;
35 CHECK_STATUS_OK(aon_timer_testutils_get_aon_cycles_32_from_us(bite_time_us,
38 LOG_INFO(
"Wdog will bark after %u us and bite after %u us",
39 (uint32_t)bark_time_us, (uint32_t)bite_time_us);
43 kDifPwrmgrResetRequestSourceTwo,
47 CHECK_STATUS_OK(aon_timer_testutils_watchdog_config(
48 aon_timer, (uint32_t)bark_cycles, (uint32_t)bite_cycles,
false));
54 static void wdog_bite_test(
const dif_aon_timer_t *aon_timer,
55 const dif_pwrmgr_t *pwrmgr, uint64_t bark_time_us) {
56 uint64_t bite_time_us = bark_time_us * 2;
57 config_wdog(aon_timer, pwrmgr, bark_time_us, bite_time_us);
59 CHECK(bark_time_us <= UINT32_MAX,
"bark_time_us must fit in a uint32_t");
63 uint32_t wait_us = (uint32_t)bark_time_us +
69 bool is_pending =
false;
70 CHECK_DIF_OK(dif_aon_timer_irq_is_pending(
71 aon_timer, kDifAonTimerIrqWdogTimerBark, &is_pending));
72 CHECK(is_pending,
"Wdog bark irq did not rise after %u microseconds",
78 CHECK(
false,
"Timeout waiting for Wdog bite reset!");
84 static void sleep_wdog_bite_test(
const dif_aon_timer_t *aon_timer,
85 const dif_pwrmgr_t *pwrmgr,
86 uint64_t bark_time_us) {
87 uint64_t bite_time_us = bark_time_us * 2;
88 config_wdog(aon_timer, pwrmgr, bark_time_us, bite_time_us);
91 CHECK_STATUS_OK(pwrmgr_testutils_enable_low_power(
92 pwrmgr, kDifPwrmgrWakeupRequestSourceTwo, 0));
96 CHECK(
false,
"Fail to enter in low power mode!");
102 CHECK_DIF_OK(dif_pwrmgr_init(
107 CHECK_DIF_OK(dif_rstmgr_init(
111 dif_aon_timer_t aon_timer;
112 CHECK_DIF_OK(dif_aon_timer_init(
117 rst_info = rstmgr_testutils_reason_get();
118 rstmgr_testutils_reason_clear();
121 rst_info == kDifRstmgrResetInfoWatchdog ||
124 "Wrong reset reason %02X", rst_info);
127 LOG_INFO(
"Booting for the first time, setting wdog");
129 wdog_bite_test(&aon_timer, &pwrmgr, 200);
130 }
else if (rst_info == kDifRstmgrResetInfoWatchdog) {
131 LOG_INFO(
"Booting for the second time due to wdog bite reset");
133 sleep_wdog_bite_test(&aon_timer, &pwrmgr, 200);
134 }
else if (rst_info ==
136 LOG_INFO(
"Booting for the third time due to wdog bite reset during sleep");