11 #include "sw/device/lib/runtime/irq.h"
13 #include "sw/device/lib/testing/aon_timer_testutils.h"
14 #include "sw/device/lib/testing/pwrmgr_testutils.h"
15 #include "sw/device/lib/testing/rv_plic_testutils.h"
16 #include "sw/device/lib/testing/test_framework/check.h"
20 #include "pwrmgr_regs.h"
23 dif_rv_plic_t rv_plic;
26 kDifPwrmgrWakeupRequestSourceFive;
27 static uint32_t wakeup_source = PWRMGR_PARAM_AON_TIMER_AON_WKUP_REQ_IDX;
29 static dif_aon_timer_t timer;
31 void ottf_external_isr(uint32_t *exc_info) {
41 dif_aon_timer_irq_t irq =
42 (dif_aon_timer_irq_t)(irq_id -
51 CHECK_DIF_OK(dif_aon_timer_irq_acknowledge(&timer, irq));
52 bool is_pending =
true;
53 CHECK_DIF_OK(dif_aon_timer_irq_is_pending(
54 &timer, kDifAonTimerIrqWkupTimerExpired, &is_pending));
58 dif_pwrmgr_irq_t irq =
61 CHECK(irq == kDifPwrmgrIrqWakeup,
"Pwrmgr IRQ ID: %d is incorrect", irq);
62 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(&pwrmgr, irq));
64 CHECK(
false,
"IRQ peripheral: %d is incorrect", peripheral);
73 static bool get_wakeup_status(
void) {
77 return (wake_req > 0);
80 static void clear_wakeup(
void) {
88 static void test_init(
void) {
89 irq_global_ctrl(
true);
90 irq_external_ctrl(
true);
92 CHECK_DIF_OK(dif_pwrmgr_init(
94 CHECK_DIF_OK(dif_rv_plic_init(
101 rv_plic_testutils_irq_range_enable(
109 CHECK_DIF_OK(dif_aon_timer_init(
114 static void set_timer(uint64_t time) {
116 CHECK_STATUS_OK(aon_timer_testutils_get_aon_cycles_32_from_us(time, &cycles));
117 CHECK_STATUS_OK(aon_timer_testutils_wakeup_config(&timer, cycles));
120 static bool lowpower_hint_is_cleared(
void) {
126 static void test_sleep(
bool wfi_fallthrough) {
127 LOG_INFO(
"Low power WFI (fallthrough=%d)", wfi_fallthrough);
130 kDifPwrmgrDomainOptionMainPowerInLowPower;
132 pwrmgr_testutils_enable_low_power(&pwrmgr, wakeup_src, domain_config));
133 irq_global_ctrl(
false);
134 if (wfi_fallthrough) {
135 LOG_INFO(
"Fallthough WFI due to timer pending");
142 LOG_INFO(
"Woke up by source %d", wakeup_source);
146 irq_global_ctrl(
true);
151 irq_global_ctrl(
false);
154 irq_global_ctrl(
true);
157 OTTF_DEFINE_TEST_CONFIG();
161 if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0)) !=
true) {