Software APIs
pwrmgr_deep_sleep_all_wake_ups.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
6 #include "sw/device/lib/runtime/irq.h"
8 #include "sw/device/lib/testing/pwrmgr_testutils.h"
9 #include "sw/device/lib/testing/ret_sram_testutils.h"
10 #include "sw/device/lib/testing/test_framework/check.h"
12 #include "sw/device/tests/pwrmgr_sleep_all_wake_ups_impl.h"
13 
14 /*
15  PWRMGR DEEP SLEEP ALL WAKE UPS TEST
16 
17  This test runs power manager wake up from deep sleep mode by
18  wake up inputs.
19  */
20 
21 OTTF_DEFINE_TEST_CONFIG();
22 
23 /**
24  * Clean up pwrmgr wakeup reason register for the next round.
25  */
26 static void delay_n_clear(uint32_t delay_in_us) {
27  busy_spin_micros(delay_in_us);
28  CHECK_DIF_OK(dif_pwrmgr_wakeup_reason_clear(&pwrmgr));
29 }
30 
31 bool test_main(void) {
32  // Enable global and external IRQ at Ibex.
33  irq_global_ctrl(true);
34  irq_external_ctrl(true);
35 
36  ret_sram_testutils_init();
37 
38  init_units();
39 
40  uint32_t wakeup_unit = 0;
41 
42  if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0))) {
43  LOG_INFO("POR reset");
44  CHECK_STATUS_OK(ret_sram_testutils_counter_clear(kCounterCases));
45  } else {
46  CHECK_STATUS_OK(
47  ret_sram_testutils_counter_get(kCounterCases, &wakeup_unit));
48  check_wakeup_reason(wakeup_unit);
49  LOG_INFO("Woke up by source %d", wakeup_unit);
50  clear_wakeup(wakeup_unit);
51  delay_n_clear(4);
52  CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterCases));
53  }
54 
55  while (true) {
56  CHECK_STATUS_OK(
57  ret_sram_testutils_counter_get(kCounterCases, &wakeup_unit));
58  if (wakeup_unit >= get_wakeup_count()) {
59  return true;
60  }
61  if (execute_test(wakeup_unit, /*deep_sleep=*/true)) {
62  CHECK(false, "This is not reachable since we entered deep sleep");
63  } else {
64  // Skip test.
65  CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterCases));
66  }
67  }
68 
69  return false;
70 }