6 #include "sw/device/lib/base/status.h"
14 #include "sw/device/lib/testing/pwrmgr_testutils.h"
15 #include "sw/device/lib/testing/rstmgr_testutils.h"
16 #include "sw/device/lib/testing/sysrst_ctrl_testutils.h"
17 #include "sw/device/lib/testing/test_framework/check.h"
19 #include "sw/device/lib/testing/test_framework/ottf_utils.h"
23 OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control =
true);
25 static const dt_pwrmgr_t kPwrmgrDt = 0;
26 static_assert(kDtPwrmgrCount == 1,
"this test expects a pwrmgr");
27 static const dt_pinmux_t kPinmuxDt = 0;
28 static_assert(kDtPinmuxCount == 1,
"this test expects a pinmux");
29 static const dt_rstmgr_t kRstmgrDt = 0;
30 static_assert(kDtRstmgrCount == 1,
"this test expects a rstmgr");
31 static const dt_gpio_t kGpioDt = 0;
32 static_assert(kDtGpioCount == 1,
"this test expects a gpio");
33 static const dt_sysrst_ctrl_t kSysrstCtrlDt = 0;
34 static_assert(kDtSysrstCtrlCount == 1,
"this test expects a sysrst_ctrl");
40 static volatile const uint8_t kTestPhaseDV;
42 static dif_pwrmgr_t pwrmgr;
43 static dif_rstmgr_t rstmgr;
44 static dif_pinmux_t pinmux;
45 static dif_sysrst_ctrl_t sysrst_ctrl;
46 static dif_gpio_t gpio;
51 kTestPhaseTimeoutUsecDV = 500,
52 kTestPhaseTimeoutUsecReal = 1000000,
59 kTestPhaseDriveInitial = 1,
60 kTestPhaseWaitNoWakeup = 2,
61 kTestPhaseWaitWakeup = 3,
65 static const dt_sysrst_ctrl_periph_io_t kPeripheralInputs[] = {
66 kDtSysrstCtrlPeriphIoPwrbIn,
67 kDtSysrstCtrlPeriphIoAcPresent,
68 kDtSysrstCtrlPeriphIoLidOpen,
71 static const dt_pad_t kInputPadsDV[] = {
77 static const dt_pad_t kInputPadsReal[] = {
83 static const dt_sysrst_ctrl_periph_io_t kPeripheralOutputs[] = {
84 kDtSysrstCtrlPeriphIoZ3Wakeup,
87 static const dt_pad_t kOutputPadsDV[] = {
91 static const dt_pad_t kOutputPadsReal[] = {
96 static const uint32_t kGpioMask = 0x7;
102 static void pinmux_setup(
void) {
103 const dt_pad_t *kInputPads =
105 for (
int i = 0; i < kNumMioInPads; ++i) {
107 &pinmux, dt_sysrst_ctrl_periph_io(kSysrstCtrlDt, kPeripheralInputs[i]),
111 const dt_pad_t *kOutputPads =
113 for (
int i = 0; i < kNumMioOutPads; ++i) {
115 &pinmux, kOutputPads[i],
116 dt_sysrst_ctrl_periph_io(kSysrstCtrlDt, kPeripheralOutputs[i])));
118 sysrst_ctrl_testutils_setup_dio(&pinmux);
119 sysrst_ctrl_testutils_release_dio(&sysrst_ctrl,
true,
true);
122 static uint8_t read_phase_pins(
void) {
128 static const uint8_t kGrayCode[] = {0, 1, 3, 2, 7, 6, 4, 5};
129 return kGrayCode[gpio_state & kGpioMask];
140 static status_t wait_next_test_phase(uint8_t prior_phase) {
143 test_status_set(kTestStatusInWfi);
144 test_status_set(kTestStatusInTest);
145 LOG_INFO(
"wait_next_test_phase after %d", prior_phase);
148 kTestPhaseTimeoutUsecDV);
149 LOG_INFO(
"Read test phase 0x%x", kTestPhaseDV);
152 kTestPhaseTimeoutUsecReal);
160 static void configure_wakeup(
void) {
176 static void go_to_sleep(
void) {
181 dt_sysrst_ctrl_instance_id(kSysrstCtrlDt), kDtSysrstCtrlWakeupWkupReq,
185 test_status_set(kTestStatusInWfi);
186 CHECK_STATUS_OK(rstmgr_testutils_pre_reset(&rstmgr));
188 pwrmgr_testutils_enable_low_power(&pwrmgr, wakeup_sources,
193 static bool reset_is_low_power_exit(
void) {
195 rstmgr_testutils_reason_clear();
199 static bool has_wakeup_happened(
void) {
200 bool wakeup_detected;
203 return wakeup_detected;
207 CHECK_DIF_OK(dif_sysrst_ctrl_init_from_dt(kSysrstCtrlDt, &sysrst_ctrl));
208 CHECK_DIF_OK(dif_pinmux_init_from_dt(kPinmuxDt, &pinmux));
209 CHECK_DIF_OK(dif_pwrmgr_init_from_dt(kPwrmgrDt, &pwrmgr));
210 CHECK_DIF_OK(dif_rstmgr_init_from_dt(kRstmgrDt, &rstmgr));
211 CHECK_DIF_OK(dif_gpio_init_from_dt(kGpioDt, &gpio));
218 &pinmux, dt_gpio_periph_io(kGpioDt, kDtGpioPeriphIoGpio0), kDtPadIob0));
220 &pinmux, dt_gpio_periph_io(kGpioDt, kDtGpioPeriphIoGpio1), kDtPadIob1));
222 &pinmux, dt_gpio_periph_io(kGpioDt, kDtGpioPeriphIoGpio2), kDtPadIob2));
227 uint8_t current_test_phase =
229 LOG_INFO(
"Test phase %d", current_test_phase);
230 switch (current_test_phase) {
234 case kTestPhaseDriveInitial:
238 case kTestPhaseWaitNoWakeup:
239 CHECK(!reset_is_low_power_exit());
240 CHECK(!has_wakeup_happened());
244 case kTestPhaseWaitWakeup:
245 CHECK(reset_is_low_power_exit());
246 CHECK(has_wakeup_happened());
253 LOG_ERROR(
"Unexpected test phase : %d", current_test_phase);