8 #include "sw/device/lib/testing/aon_timer_testutils.h"
9 #include "sw/device/lib/testing/clkmgr_testutils.h"
10 #include "sw/device/lib/testing/pwrmgr_testutils.h"
11 #include "sw/device/lib/testing/sensor_ctrl_testutils.h"
12 #include "sw/device/lib/testing/test_framework/check.h"
17 OTTF_DEFINE_TEST_CONFIG();
39 kWaitForCSRPollingUs = 1,
40 kMeasurementsPerRound = 100,
43 static dif_clkmgr_t clkmgr;
44 static dif_pwrmgr_t pwrmgr;
47 dif_sensor_ctrl_t sensor_ctrl;
48 dif_aon_timer_t aon_timer;
50 uint32_t delay_micros = 0;
51 CHECK_STATUS_OK(aon_timer_testutils_get_us_from_aon_cycles(
52 kMeasurementsPerRound, &delay_micros));
54 CHECK_DIF_OK(dif_clkmgr_init(
56 CHECK_DIF_OK(dif_sensor_ctrl_init(
59 CHECK_DIF_OK(dif_pwrmgr_init(
61 CHECK_DIF_OK(dif_aon_timer_init(
68 if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0)) ==
true) {
70 LOG_INFO(
"Run clock measurements right after POR");
72 clkmgr_testutils_enable_clock_counts_with_expected_thresholds(
73 &clkmgr,
false,
false,
78 CHECK_STATUS_OK(clkmgr_testutils_check_measurement_counts(&clkmgr));
79 CHECK_STATUS_OK(clkmgr_testutils_disable_clock_counts(&clkmgr));
89 aon_timer_testutils_wakeup_config(&aon_timer, wakeup_threshold));
91 LOG_INFO(
"Start clock measurements to cause an error for main and io clk.");
93 clkmgr_testutils_enable_clock_counts_with_expected_thresholds(
101 CHECK_STATUS_OK(pwrmgr_testutils_enable_low_power(
102 &pwrmgr, kDifPwrmgrWakeupRequestSourceFive,
103 kDifPwrmgrDomainOptionUsbClockInActivePower));
105 LOG_INFO(
"TEST: Issue WFI to enter deep sleep");
108 }
else if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(
109 &pwrmgr, kDifPwrmgrWakeupRequestSourceFive)) ==
true) {
111 bool all_disabled = UNWRAP(clkmgr_testutils_check_measurement_enables(
118 LOG_INFO(
"Check for all clock measurements disabled done");
122 kDifClkmgrRecovErrTypeMainMeas | kDifClkmgrRecovErrTypeIoMeas;
125 CHECK(err_codes == expected_err_codes,
126 "expected main and io clk measurement error 0x%x, but got 0x%x",
127 expected_err_codes, err_codes);
132 LOG_INFO(
"TEST: one more measurement");
134 clkmgr_testutils_enable_clock_counts_with_expected_thresholds(
135 &clkmgr,
false,
false,
138 CHECK_STATUS_OK(clkmgr_testutils_check_measurement_counts(&clkmgr));
139 CHECK_STATUS_OK(clkmgr_testutils_disable_clock_counts(&clkmgr));
146 LOG_ERROR(
"Unexpected wakeup detected: type = %d, request_source = %d",