12 #include "sw/device/lib/testing/pwrmgr_testutils.h"
13 #include "sw/device/lib/testing/rstmgr_testutils.h"
14 #include "sw/device/lib/testing/sysrst_ctrl_testutils.h"
15 #include "sw/device/lib/testing/test_framework/check.h"
18 OTTF_DEFINE_TEST_CONFIG();
20 static dif_pwrmgr_t pwrmgr;
21 static dif_rstmgr_t rstmgr;
22 static dif_sysrst_ctrl_t sysrst_ctrl;
23 static dif_gpio_t gpio;
28 static const dt_pwrmgr_t kPwrmgrDt = 0;
29 static_assert(kDtPwrmgrCount == 1,
"this test expects a pwrmgr");
30 static const dt_pinmux_t kPinmuxDt = 0;
31 static_assert(kDtPinmuxCount == 1,
"this test expects a pinmux");
32 static const dt_rstmgr_t kRstmgrDt = 0;
33 static_assert(kDtRstmgrCount == 1,
"this test expects a rstmgr");
34 static const dt_gpio_t kGpioDt = 0;
35 static_assert(kDtGpioCount == 1,
"this test expects a gpio");
36 static const dt_sysrst_ctrl_t kSysrstCtrlDt = 0;
37 static_assert(kDtSysrstCtrlCount == 1,
"this test expects a sysrst_ctrl");
40 kTestPhaseCheckComboReset = 0,
41 kTestPhaseCheckDeepSleepWakeup = 1,
42 kTestPhaseCheckDeepSleepReset = 2,
43 kTestPhaseFinalCheck = 3,
50 kDetectionTimeThreshold = 1024,
51 kEcResetDuration = 512,
52 kDebounceTimeThreshold = 128,
56 kOutputNumMioPads = 6,
59 static const dt_sysrst_ctrl_periph_io_t kPeripheralInputs[] = {
60 kDtSysrstCtrlPeriphIoKey0In, kDtSysrstCtrlPeriphIoKey1In,
61 kDtSysrstCtrlPeriphIoKey2In, kDtSysrstCtrlPeriphIoPwrbIn,
62 kDtSysrstCtrlPeriphIoAcPresent, kDtSysrstCtrlPeriphIoLidOpen,
65 static const dt_pad_t kInputPadsDV[] = {
66 kDtPadIob3, kDtPadIob6, kDtPadIob8, kDtPadIob9, kDtPadIoc7, kDtPadIoc9,
71 static const dt_pad_t kInputPadsReal[] = {
72 kDtPadIor10, kDtPadIor11, kDtPadIor12, kDtPadIor5, kDtPadIor6, kDtPadIor7,
76 static volatile const uint8_t kTestPhaseDV = 0;
78 static const uint32_t kGpioMask = 0x3;
80 static void check_combo_reset(
void) {
86 .detection_time_threshold = kDetectionTimeThreshold,
87 .embedded_controller_reset_duration = kEcResetDuration,
92 .debounce_time_threshold = kDebounceTimeThreshold,
100 .override_value =
true}));
102 CHECK_STATUS_OK(rstmgr_testutils_pre_reset(&rstmgr));
106 test_status_set(kTestStatusInWfi);
110 static void check_deep_sleep_wakeup(
void) {
113 .ac_power_debounce_time_threshold = 0,
114 .lid_open_debounce_time_threshold = 0,
115 .power_button_debounce_time_threshold = 0,
119 CHECK_STATUS_OK(rstmgr_testutils_pre_reset(&rstmgr));
121 pwrmgr_testutils_enable_low_power(&pwrmgr, wakeup_sources, 0));
123 test_status_set(kTestStatusInWfi);
127 static void check_deep_sleep_reset(
void) {
133 .detection_time_threshold = kDetectionTimeThreshold,
134 .embedded_controller_reset_duration = kEcResetDuration,
141 .override_value =
true}));
144 .debounce_time_threshold = kDebounceTimeThreshold,
149 CHECK_STATUS_OK(rstmgr_testutils_pre_reset(&rstmgr));
156 pwrmgr_testutils_enable_low_power(&pwrmgr, other_wakeup_sources, 0));
158 test_status_set(kTestStatusInWfi);
163 CHECK_DIF_OK(dif_pwrmgr_init_from_dt(kPwrmgrDt, &pwrmgr));
164 CHECK_DIF_OK(dif_rstmgr_init_from_dt(kRstmgrDt, &rstmgr));
165 CHECK_DIF_OK(dif_sysrst_ctrl_init_from_dt(kSysrstCtrlDt, &sysrst_ctrl));
166 CHECK_DIF_OK(dif_gpio_init_from_dt(kGpioDt, &gpio));
170 dt_sysrst_ctrl_instance_id(kSysrstCtrlDt), kDtSysrstCtrlWakeupWkupReq,
174 dt_sysrst_ctrl_instance_id(kSysrstCtrlDt), kDtSysrstCtrlResetReqRstReq,
179 kDtPinmuxWakeupPinWkupReq, &other_wakeup_sources));
182 rstmgr_reset_info = rstmgr_testutils_reason_get();
185 CHECK_DIF_OK(dif_pinmux_init_from_dt(kPinmuxDt, &pinmux));
186 const dt_pad_t *kInputPads =
188 for (
int i = 0; i < kOutputNumMioPads; ++i) {
190 &pinmux, dt_sysrst_ctrl_periph_io(kSysrstCtrlDt, kPeripheralInputs[i]),
196 sysrst_ctrl_testutils_setup_dio(&pinmux);
198 &pinmux, dt_gpio_periph_io(kGpioDt, kDtGpioPeriphIoGpio0), kDtPadIob0));
200 &pinmux, dt_gpio_periph_io(kGpioDt, kDtGpioPeriphIoGpio1), kDtPadIob1));
208 uint8_t kTestPhase = kTestPhaseDV;
212 kTestPhase = gpio_state & kGpioMask;
214 LOG_INFO(
"test phase: %u", kTestPhase);
216 switch (kTestPhase) {
217 case kTestPhaseCheckComboReset:
221 case kTestPhaseCheckDeepSleepWakeup:
222 CHECK(rstmgr_reset_info == kDifRstmgrResetInfoSysRstCtrl);
223 check_deep_sleep_wakeup();
225 case kTestPhaseCheckDeepSleepReset:
227 check_deep_sleep_reset();
229 case kTestPhaseFinalCheck:
230 CHECK(rstmgr_reset_info ==
235 LOG_ERROR(
"Unexpected test phase : %d", kTestPhase);