6 #include "sw/device/lib/runtime/irq.h"
8 #include "sw/device/lib/testing/ret_sram_testutils.h"
9 #include "sw/device/lib/testing/test_framework/check.h"
11 #include "sw/device/tests/pwrmgr_sleep_all_wake_ups_impl.h"
26 OTTF_DEFINE_TEST_CONFIG();
31 static void delay_n_clear(uint32_t delay_in_us) {
36 static uint32_t get_wakeup_unit(uint32_t count) {
return count / 2; }
38 static bool get_deep_sleep(uint32_t count) {
return (count % 2) == 1; }
42 irq_global_ctrl(
true);
43 irq_external_ctrl(
true);
47 ret_sram_testutils_init();
49 uint32_t wakeup_count = 0;
50 uint32_t wakeup_unit = 0;
51 bool deep_sleep =
false;
58 CHECK_STATUS_OK(ret_sram_testutils_counter_clear(kCounterCases));
60 LOG_ERROR(
"Unexpected wakeup_reason.types 0x%x", wakeup_reason.
types);
65 ret_sram_testutils_counter_get(kCounterCases, &wakeup_count));
66 wakeup_unit = get_wakeup_unit(wakeup_count);
67 deep_sleep = get_deep_sleep(wakeup_count);
68 CHECK(deep_sleep,
"Should be deep sleep");
69 check_wakeup_reason(wakeup_unit);
70 LOG_INFO(
"Woke up by source %d", wakeup_unit);
71 clear_wakeup(wakeup_unit);
74 CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterCases));
79 ret_sram_testutils_counter_get(kCounterCases, &wakeup_count));
80 if (wakeup_count >= 2 * get_wakeup_count()) {
83 wakeup_unit = get_wakeup_unit(wakeup_count);
84 deep_sleep = get_deep_sleep(wakeup_count);
86 CHECK(!deep_sleep,
"Should be normal sleep");
87 if (execute_test(wakeup_unit, deep_sleep)) {
88 check_wakeup_reason(wakeup_unit);
89 LOG_INFO(
"Woke up by source %d", wakeup_unit);
90 clear_wakeup(wakeup_unit);
93 CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterCases));
95 ret_sram_testutils_counter_get(kCounterCases, &wakeup_count));
96 wakeup_unit = get_wakeup_unit(wakeup_count);
97 deep_sleep = get_deep_sleep(wakeup_count);
99 CHECK(deep_sleep,
"Should be deep sleep");
100 if (execute_test(wakeup_unit, deep_sleep)) {
101 CHECK(
false,
"This is not reachable since we entered deep sleep");
104 CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterCases));