19 #include "sw/device/lib/testing/aon_timer_testutils.h"
20 #include "sw/device/lib/testing/flash_ctrl_testutils.h"
21 #include "sw/device/lib/testing/nv_counter_testutils.h"
22 #include "sw/device/lib/testing/pwrmgr_testutils.h"
23 #include "sw/device/lib/testing/rstmgr_testutils.h"
24 #include "sw/device/lib/testing/test_framework/check.h"
29 OTTF_DEFINE_TEST_CONFIG();
30 static volatile const uint8_t RST_IDX[5] = {3, 30, 130, 5, 50};
36 static void config_sysrst(
const dif_pwrmgr_t *pwrmgr,
37 const dif_sysrst_ctrl_t *sysrst_ctrl_aon) {
42 kDifPwrmgrResetRequestSourceOne,
44 LOG_INFO(
"Reset Request SourceOne is set");
52 .detection_time_threshold = 10,
54 .embedded_controller_reset_duration = 10};
65 CHECK_DIF_OK(dif_pinmux_init(
69 sysrst_ctrl_aon, sysrst_ctrl_input_change_config));
78 CHECK(
false,
"Timeout waiting for sysrst reset!");
84 static void config_wdog(
const dif_aon_timer_t *aon_timer,
85 const dif_pwrmgr_t *pwrmgr, uint64_t bark_time_us,
86 uint64_t bite_time_us) {
87 uint32_t bark_cycles = 0;
88 CHECK_STATUS_OK(aon_timer_testutils_get_aon_cycles_32_from_us(bark_time_us,
90 uint32_t bite_cycles = 0;
91 CHECK_STATUS_OK(aon_timer_testutils_get_aon_cycles_32_from_us(bite_time_us,
94 LOG_INFO(
"Wdog will bark after %u us and bite after %u us",
95 (uint32_t)bark_time_us, (uint32_t)bite_time_us);
99 kDifPwrmgrResetRequestSourceTwo,
103 CHECK_STATUS_OK(aon_timer_testutils_watchdog_config(aon_timer, bark_cycles,
104 bite_cycles,
false));
110 static void wdog_bite_test(
const dif_aon_timer_t *aon_timer,
111 const dif_pwrmgr_t *pwrmgr, uint64_t bark_time_us) {
112 uint64_t bite_time_us = bark_time_us * 2;
113 config_wdog(aon_timer, pwrmgr, bark_time_us, bite_time_us);
117 uint64_t wait_us_u64 =
120 CHECK(wait_us_u64 <= UINT32_MAX,
"wait_us_u64 must fit in uint32_t");
121 uint32_t wait_us = (uint32_t)wait_us_u64;
125 bool is_pending =
false;
126 CHECK_DIF_OK(dif_aon_timer_irq_is_pending(
127 aon_timer, kDifAonTimerIrqWdogTimerBark, &is_pending));
128 CHECK(is_pending,
"Wdog bark irq did not rise after %u microseconds",
134 CHECK(
false,
"Timeout waiting for Wdog bite reset!");
140 CHECK_DIF_OK(dif_pwrmgr_init(
144 dif_sysrst_ctrl_t sysrst_ctrl_aon;
145 CHECK_DIF_OK(dif_sysrst_ctrl_init(
151 CHECK_DIF_OK(dif_rstmgr_init(
155 dif_aon_timer_t aon_timer;
156 CHECK_DIF_OK(dif_aon_timer_init(
166 flash_ctrl_testutils_default_region_access(&flash_ctrl,
175 uint32_t event_idx = 0;
176 CHECK_STATUS_OK(flash_ctrl_testutils_counter_get(0, &event_idx));
179 CHECK_STATUS_OK(flash_ctrl_testutils_counter_increment(&flash_ctrl, 0));
181 LOG_INFO(
"Test round %d", event_idx);
182 LOG_INFO(
"RST_IDX[%d] = %d", event_idx, RST_IDX[event_idx]);
186 rst_info = rstmgr_testutils_reason_get();
187 rstmgr_testutils_reason_clear();
190 rst_info == kDifRstmgrResetInfoWatchdog ||
191 rst_info == kDifRstmgrResetInfoSysRstCtrl,
192 "Wrong reset reason %02X", rst_info);
195 LOG_INFO(
"Booting for the first time, setting sysrst");
196 config_sysrst(&pwrmgr, &sysrst_ctrl_aon);
197 }
else if (rst_info == kDifRstmgrResetInfoSysRstCtrl) {
198 LOG_INFO(
"Booting for the second time due to system reset control reset");
200 wdog_bite_test(&aon_timer, &pwrmgr, 200);
201 }
else if (rst_info == kDifRstmgrResetInfoWatchdog) {
202 LOG_INFO(
"Booting for the third time due to wdog bite reset");