5 #include "sw/device/tests/penetrationtests/firmware/lib/extclk_sca_fi.h"
7 #include "sw/device/lib/base/multibits.h"
8 #include "sw/device/lib/base/status.h"
13 #include "sw/device/lib/testing/test_framework/check.h"
14 #include "sw/device/lib/testing/test_framework/ottf_test_config.h"
15 #include "sw/device/lib/testing/test_framework/ujson_ottf.h"
16 #include "sw/device/lib/ujson/ujson.h"
17 #include "sw/device/tests/penetrationtests/json/extclk_sca_fi_commands.h"
23 static const int kSettleDelayMicros = 200;
25 static dif_clkmgr_t clkmgr;
28 static bool did_extclk_settle(
const dif_clkmgr_t *clkmgr) {
35 penetrationtest_extclk_sca_fi_cfg_t uj_data;
36 TRY(ujson_deserialize_penetrationtest_extclk_sca_fi_cfg_t(uj, &uj_data));
43 if (!uj_data.hi_speed_sel) {
44 LOG_INFO(
"Switching to low speed Extclk...");
46 LOG_INFO(
"Switching to high speed Extclk...");
51 IBEX_SPIN_FOR(did_extclk_settle(&clkmgr), kSettleDelayMicros);
55 LOG_INFO(
"Manually reset the device to switch back to internal clock.");
62 extclk_sca_fi_subcommand_t cmd;
63 TRY(ujson_deserialize_extclk_sca_fi_subcommand_t(uj, &cmd));
65 case kExtClkScaFiSubcommandConfigure:
66 return handle_extclk_sca_fi_configure(uj);
68 LOG_ERROR(
"Unrecognized EXTCLK SCA FI subcommand: %d", cmd);
69 return INVALID_ARGUMENT();