17 #include "sw/device/lib/testing/aon_timer_testutils.h"
18 #include "sw/device/lib/testing/clkmgr_testutils.h"
19 #include "sw/device/lib/testing/test_framework/check.h"
25 static const int kSettleDelayMicros = 200;
26 static const int kMeasurementsPerRound = 100;
29 static bool did_extclk_settle(
const dif_clkmgr_t *clkmgr) {
35 void execute_clkmgr_external_clk_src_for_sw_test(
bool fast_ext_clk) {
39 uint32_t delay_micros = 0;
40 CHECK_STATUS_OK(aon_timer_testutils_get_us_from_aon_cycles(
41 kMeasurementsPerRound, &delay_micros));
43 CHECK_DIF_OK(dif_clkmgr_init(
48 CHECK(err_codes == 0,
"Unexpected non-zero clkmgr recoverable error code");
54 LOG_INFO(
"Selecting external clock and %s speed clocks",
55 (fast_ext_clk ?
"fast" :
"slow"));
61 IBEX_SPIN_FOR(did_extclk_settle(&clkmgr), kSettleDelayMicros);
64 CHECK_STATUS_OK(clkmgr_testutils_enable_clock_counts_with_expected_thresholds(
69 CHECK_STATUS_OK(clkmgr_testutils_check_measurement_counts(&clkmgr));
70 CHECK_STATUS_OK(clkmgr_testutils_disable_clock_counts(&clkmgr));
74 LOG_INFO(
"Disabling external clock");
78 IBEX_SPIN_FOR(!did_extclk_settle(&clkmgr), kSettleDelayMicros);
81 CHECK_STATUS_OK(clkmgr_testutils_enable_clock_counts_with_expected_thresholds(
82 &clkmgr,
false,
false,
85 CHECK_STATUS_OK(clkmgr_testutils_check_measurement_counts(&clkmgr));
86 CHECK_STATUS_OK(clkmgr_testutils_disable_clock_counts(&clkmgr));