14 #include "sw/device/lib/testing/rstmgr_testutils.h"
15 #include "sw/device/lib/testing/test_framework/check.h"
18 #include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
19 #include "sw/device/silicon_creator/lib/drivers/rstmgr.h"
20 #include "sw/device/silicon_creator/lib/drivers/watchdog.h"
21 #include "sw/device/silicon_creator/lib/error.h"
24 #include "rstmgr_regs.h"
26 static uint32_t compute_ticks_per_ms(uint64_t hz) {
27 const uint64_t kTicksPerMs =
udiv64_slow(hz, 1000, NULL);
28 CHECK(kTicksPerMs <= UINT32_MAX,
"kTicksPerMs exceeds UINT32_MAX");
29 return (uint32_t)kTicksPerMs;
33 static rom_error_t watchdog_pet_test(
void) {
36 uint32_t bark_threshold = 9 * bite_threshold / 8;
37 LOG_INFO(
"bite threshold = %d", bite_threshold);
38 LOG_INFO(
"bark threshold = %d", bark_threshold);
40 .bite_threshold = bite_threshold,
41 .bark_threshold = bark_threshold,
45 for (
size_t i = 0; i < 10; ++i) {
56 static rom_error_t watchdog_configure_disabled_test(
void) {
59 LOG_INFO(
"threshold = %d", threshold);
61 .bite_threshold = threshold,
62 .bark_threshold = threshold,
72 static rom_error_t watchdog_bite_test(
void) {
75 uint32_t bark_threshold = 9 * bite_threshold / 8;
76 LOG_INFO(
"bite threshold = %d", bite_threshold);
77 LOG_INFO(
"bark threshold = %d", bark_threshold);
79 .bite_threshold = bite_threshold,
80 .bark_threshold = bark_threshold,
91 OTTF_DEFINE_TEST_CONFIG();
95 typedef enum TestPhase {
105 uint32_t reason = rstmgr_testutils_reason_get();
106 rstmgr_alert_info_enable();
107 LOG_INFO(
"reset_info = %08x", reason);
111 rstmgr_testutils_reason_clear();
121 retention_sram_clear();
123 *phase = kTestPhasePet;
126 *phase = kTestPhaseDisable;
129 *phase = kTestPhaseBite;
132 *phase = kTestPhaseDone;
133 LOG_ERROR(
"Test failure: should have reset before this line.");
135 LOG_INFO(
"Detected reset after escalation test");
136 if (*phase != kTestPhaseBite) {
137 LOG_ERROR(
"Test failure: expected phase %d but got phase %d",
138 kTestPhaseBite, *phase);
141 result = OK_STATUS();
147 return status_ok(result);