10 #include "sw/device/lib/testing/aon_timer_testutils.h"
11 #include "sw/device/lib/testing/pwrmgr_testutils.h"
12 #include "sw/device/lib/testing/test_framework/check.h"
14 #include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
15 #include "sw/device/silicon_creator/lib/drivers/rstmgr.h"
17 static const dt_pwrmgr_t kPwrmgrDt = 0;
18 static_assert(kDtPwrmgrCount == 1,
"this test expects exactly one pwrmgr");
19 static const dt_aon_timer_t kAonTimerDt = 0;
20 static_assert(kDtAonTimerCount >= 1,
21 "this test expects at least one aon_timer");
23 OTTF_DEFINE_TEST_CONFIG();
36 bool check_ram_region_unchanged(
char *start,
size_t length) {
38 memset(&pattern32, kPattern,
sizeof(pattern32));
40 bool unchanged =
true;
41 for (
size_t i = 0; i < length; i +=
sizeof(uint32_t)) {
42 uint32_t val =
read_32(start + i);
43 if (val != pattern32) {
44 LOG_ERROR(
"Retention SRAM changed at word %u (%x --> %x).",
45 i /
sizeof(uint32_t), pattern32, val);
58 LOG_INFO(
"Checking that retention SRAM values are unchanged");
59 bool unchanged =
true;
65 CHECK(creator_resv_size >
sizeof(uint32_t));
66 CHECK(owner_resv_size >
sizeof(uint32_t));
70 check_ram_region_unchanged((
char *)&ret->
owner.
reserved, owner_resv_size);
74 rom_error_t retention_ram_keep_test(
void) {
83 LOG_INFO(
"Checking boot_log.retention_ram_initialized: %x",
86 LOG_INFO(
"Writing known pattern to ret RAM");
91 CHECK_DIF_OK(dif_pwrmgr_init_from_dt(kPwrmgrDt, &pwrmgr));
95 kDtAonTimerWakeupWkupReq, &wakeup_sources));
109 dif_aon_timer_t aon_timer;
110 CHECK_DIF_OK(dif_aon_timer_init_from_dt(kAonTimerDt, &aon_timer));
112 aon_timer_testutils_wakeup_config(&aon_timer, wakeup_threshold));
116 pwrmgr_testutils_enable_low_power(&pwrmgr, wakeup_sources, 0));
117 LOG_INFO(
"Issue WFI to enter sleep");
120 LOG_INFO(
"Woke up from low power exit");
121 LOG_INFO(
"Checking boot_log.retention_ram_initialized: %x",
125 CHECK(check_ram_unchanged(ret));
132 LOG_INFO(
"Checking boot_log.retention_ram_initialized: %x",
137 CHECK(check_ram_unchanged(ret));
140 LOG_ERROR(
"Did not find a reset reason of Low-Power Exit or SW request");
141 return kErrorUnknown;
147 return status_ok(result);