15 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
20 #include "sw/device/lib/testing/alert_handler_testutils.h"
21 #include "sw/device/lib/testing/aon_timer_testutils.h"
22 #include "sw/device/lib/testing/pwrmgr_testutils.h"
23 #include "sw/device/lib/testing/test_framework/check.h"
24 #include "sw/device/lib/testing/test_framework/ottf_isrs.h"
27 #include "alert_handler_regs.h"
28 #include "aon_timer_regs.h"
31 typedef void (*isr_handler)(void);
32 static volatile isr_handler expected_isr_handler;
34 static volatile bool nmi_fired =
false;
35 static volatile bool ext_irq_fired =
false;
36 static volatile bool irq_is_pending =
false;
38 static dif_aon_timer_t aon_timer;
39 static dif_rv_core_ibex_t rv_core_ibex;
40 static dif_pwrmgr_t pwrmgr;
41 static dif_rv_timer_t rv_timer;
42 static dif_alert_handler_t alert_handler;
44 static dif_pinmux_t pinmux;
45 static dif_otp_ctrl_t otp_ctrl;
46 static dif_gpio_t gpio;
48 static const dt_pwrmgr_t kPwrmgrDt = 0;
49 static_assert(kDtPwrmgrCount == 1,
"this library expects exactly one pwrmgr");
50 static const dt_rv_core_ibex_t kRvCoreIbexDt = 0;
51 static_assert(kDtRvCoreIbexCount == 1,
52 "this library expects exactly one rv_core_ibex");
53 static const dt_alert_handler_t kAlertHandlerDt = 0;
54 static_assert(kDtAlertHandlerCount == 1,
55 "this library expects exactly one alert_handler");
56 static const dt_rv_timer_t kRvTimerDt = 0;
57 static_assert(kDtRvTimerCount >= 1,
58 "this library expects at least one rv_timer");
59 static const dt_aon_timer_t kAonTimerDt = 0;
60 static_assert(kDtAonTimerCount == 1,
61 "this library expects exactly one aon_timer");
62 static const dt_pinmux_t kPinmuxDt = 0;
63 static_assert(kDtPinmuxCount == 1,
"this library expects exactly one pinmux");
64 static const dt_gpio_t kGpioDt = 0;
65 static_assert(kDtGpioCount == 1,
"this library expects exactly one gpio");
66 static const dt_otp_ctrl_t kOtpCtrlDt = 0;
67 static_assert(kDtOtpCtrlCount == 1,
68 "this library expects exactly one otp_ctrl");
69 static const dt_pwm_t kPwmDt = 0;
70 static_assert(kDtPwmCount >= 1,
"this library expects at least one pwm");
72 OTTF_DEFINE_TEST_CONFIG();
76 void ottf_external_isr(uint32_t *exc_info) {
81 void ottf_external_nmi_handler(uint32_t *exc_info) {
84 expected_isr_handler();
86 CHECK_DIF_OK(dif_rv_core_ibex_get_nmi_state(
88 CHECK_DIF_OK(dif_rv_core_ibex_clear_nmi_state(&rv_core_ibex,
89 kDifRvCoreIbexNmiSourceAll));
92 static void wdog_irq_handler(
void) {
97 CHECK_DIF_OK(dif_aon_timer_irq_is_pending(
98 &aon_timer, kDifAonTimerIrqWdogTimerBark, &is_pending));
99 irq_is_pending = is_pending;
107 dif_aon_timer_irq_acknowledge(&aon_timer, kDifAonTimerIrqWdogTimerBark));
112 CHECK_DIF_OK(dif_aon_timer_init_from_dt(kAonTimerDt, &aon_timer));
113 CHECK_DIF_OK(dif_rv_core_ibex_init_from_dt(kRvCoreIbexDt, &rv_core_ibex));
114 CHECK_DIF_OK(dif_pwrmgr_init_from_dt(kPwrmgrDt, &pwrmgr));
115 CHECK_DIF_OK(dif_rv_timer_init_from_dt(kRvTimerDt, &rv_timer));
116 CHECK_DIF_OK(dif_alert_handler_init_from_dt(kAlertHandlerDt, &alert_handler));
117 CHECK_DIF_OK(dif_pwm_init_from_dt(kPwmDt, &pwm));
118 CHECK_DIF_OK(dif_pinmux_init_from_dt(kPinmuxDt, &pinmux));
119 CHECK_DIF_OK(dif_otp_ctrl_init_from_dt(kOtpCtrlDt, &otp_ctrl));
120 CHECK_DIF_OK(dif_gpio_init_from_dt(kGpioDt, &gpio));
122 LOG_INFO(
"Running CHIP Power Idle Load test");
124 static const uint32_t kGpioMask = 0x00000004;
140 static const uint32_t kComparator = 0;
141 static const uint64_t kTickFreqHz = 1000000;
142 static const uint64_t kDeadline = UINT32_MAX;
153 uint64_t current_time;
156 (current_time + kDeadline)));
169 alert_classes[i] = kDifAlertHandlerClassA;
174 kDifAlertHandlerLocalAlertAlertPingFail};
181 .duration_cycles = 2000}};
185 .accumulator_threshold = UINT16_MAX,
186 .irq_deadline_cycles = UINT32_MAX,
187 .escalation_phases = esc_phases,
188 .escalation_phases_len =
ARRAYSIZE(esc_phases),
194 kDifAlertHandlerClassB};
199 .alert_classes = alert_classes,
201 .local_alerts = loc_alerts,
202 .local_alert_classes = loc_alert_classes,
203 .local_alerts_len =
ARRAYSIZE(loc_alerts),
205 .class_configs = class_configs,
207 .ping_timeout = UINT16_MAX,
212 alert_handler_testutils_configure_all(&alert_handler, config,
219 CHECK(is_locked,
"Expected ping timer to be locked");
226 .beats_per_pulse_cycle = 32,
236 .blink_parameter_x = 0,
237 .blink_parameter_y = 0,
240 kDifPwmChannel0, kDifPwmChannel1, kDifPwmChannel2,
241 kDifPwmChannel3, kDifPwmChannel4, kDifPwmChannel5,
244 static volatile const uint16_t kPwmDutycycle[PWM_PARAM_N_OUTPUTS] = {
263 for (
int i = 0; i < PWM_PARAM_N_OUTPUTS; ++i) {
277 for (
int i = 0; i < PWM_PARAM_N_OUTPUTS; ++i) {
290 .integrity_period_mask = 0x1,
291 .consistency_period_mask = 0x1,
296 LOG_INFO(
"OTP periodic checks active");
300 static const uint64_t kTimeTillBark = 1000;
304 expected_isr_handler = wdog_irq_handler;
308 dif_rv_core_ibex_enable_nmi(&rv_core_ibex, kDifRvCoreIbexNmiSourceWdog));
309 uint32_t count_cycles = 0;
310 CHECK_STATUS_OK(aon_timer_testutils_get_aon_cycles_32_from_us(kTimeTillBark,
312 CHECK_STATUS_OK(aon_timer_testutils_watchdog_config(&aon_timer, count_cycles,
333 CHECK(irq_is_pending,
"Expected watchdog bark interrupt to be pending");
337 "WDOG NMI state check1 not expected! wdog_enable:%x, wdog_raised:%x",
340 CHECK_DIF_OK(dif_rv_core_ibex_get_nmi_state(
344 "WDOG NMI state check2 not expected! wdog_enable:%x wdog_raised:%x",
348 CHECK(ext_irq_fired ==
false,
"Unexpected external interrupt triggered.");
352 CHECK(UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0)) ==
true);
354 CHECK_STATUS_OK(aon_timer_testutils_shutdown(&aon_timer));
356 test_status_set(kTestStatusInTest);