11 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
13 #include "sw/device/lib/runtime/irq.h"
15 #include "sw/device/lib/testing/alert_handler_testutils.h"
16 #include "sw/device/lib/testing/keymgr_testutils.h"
17 #include "sw/device/lib/testing/rstmgr_testutils.h"
18 #include "sw/device/lib/testing/test_framework/FreeRTOSConfig.h"
19 #include "sw/device/lib/testing/test_framework/check.h"
22 #include "alert_handler_regs.h"
24 #include "rv_core_ibex_regs.h"
26 OTTF_DEFINE_TEST_CONFIG();
28 static dif_clkmgr_t clkmgr;
29 static dif_keymgr_t keymgr;
30 static dif_rstmgr_t rstmgr;
31 static dif_alert_handler_t alert_handler;
32 static dif_rv_core_ibex_t rv_core_ibex;
33 static dif_uart_t uart;
44 void ottf_external_nmi_handler(uint32_t *exc_info) {
46 LOG_INFO(
"You are experiencing an NMI");
50 CHECK_DIF_OK(dif_rv_core_ibex_get_nmi_state(
54 "Alert handler NMI state not expected:\n\t"
55 "alert_enable:%x\n\talert_raised:%x\n",
60 &alert_handler, kDifAlertHandlerClassA, &state));
68 LOG_FATAL(
"This message should never be seen");
74 static void init_peripheral_handles(
void) {
75 CHECK_DIF_OK(dif_clkmgr_init(
78 CHECK_DIF_OK(dif_rstmgr_init(
81 CHECK_DIF_OK(dif_alert_handler_init(
85 CHECK_DIF_OK(dif_rv_core_ibex_init(
89 CHECK_DIF_OK(dif_uart_init(
92 CHECK_DIF_OK(dif_keymgr_init(
100 static void config_alert_handler(
void) {
106 uint32_t phase0DurationCycles = 1000000;
108 phase0DurationCycles /= 10;
110 phase0DurationCycles /= 100;
116 .duration_cycles = phase0DurationCycles},
119 .duration_cycles = 10000},
122 .duration_cycles = 10000},
126 .accumulator_threshold = 0,
127 .irq_deadline_cycles = 0,
128 .escalation_phases = escalationProfiles,
129 .escalation_phases_len = 3,
141 &alert_handler, kDifAlertHandlerClassA, configProfiles[0],
158 init_peripheral_handles();
162 rst_info = rstmgr_testutils_reason_get();
163 rstmgr_testutils_reason_clear();
166 config_alert_handler();
169 CHECK_STATUS_OK(keymgr_testutils_advance_state(&keymgr, NULL));
172 LOG_INFO(
"Keymgr entered Init State");
175 CHECK_DIF_OK(dif_rv_core_ibex_enable_nmi(&rv_core_ibex,
176 kDifRvCoreIbexNmiSourceAlert));
179 CHECK_DIF_OK(dif_rv_core_ibex_alert_force(&rv_core_ibex,
180 kDifRvCoreIbexAlertRecovSwErr));
184 LOG_ERROR(
"Should have reset before this line");
188 LOG_INFO(
"Reset due to alert escalation");
191 LOG_ERROR(
"Unexpected reset info %d", rst_info);