8 #include "sw/device/lib/runtime/irq.h"
10 #include "sw/device/lib/testing/entropy_testutils.h"
12 #include "sw/device/lib/testing/test_framework/check.h"
21 OTTF_DEFINE_TEST_CONFIG();
23 static dif_rv_plic_t plic;
24 static volatile bool otbn_finished;
29 static void check_otbn_err_bits(dif_otbn_t *otbn,
33 CHECK(otbn_err_bits == expected_err_bits,
34 "dif_otbn_get_err_bits() produced unexpected error bits: %x",
41 static void check_otbn_insn_cnt(dif_otbn_t *otbn, uint32_t expected_insn_cnt) {
44 CHECK(insn_cnt == expected_insn_cnt,
45 "Expected to execute %d instructions, but got %d.", expected_insn_cnt,
52 static void check_otbn_status(dif_otbn_t *otbn,
56 CHECK(
status == expected_status,
"Unexpected status: expected %d but got %d.",
66 static void run_test_with_irqs(dif_otbn_t *otbn,
otbn_app_t app,
69 uint32_t expected_insn_cnt) {
72 otbn_finished =
false;
90 ATOMIC_WAIT_FOR_INTERRUPT(otbn_finished);
92 check_otbn_status(otbn, expected_status);
93 check_otbn_err_bits(otbn, expected_insn_cnt);
94 check_otbn_insn_cnt(otbn, expected_err_bits);
100 static void plic_init_with_irqs(
void) {
103 CHECK_DIF_OK(dif_rv_plic_init(base_addr, &plic));
124 void ottf_external_isr(uint32_t *exc_info) {
134 "Interrupt from incorrect peripheral: (exp: %d, obs: %s)",
142 CHECK(!otbn_finished);
145 otbn_finished =
true;
149 CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
150 plic_init_with_irqs();
153 irq_global_ctrl(
true);
154 irq_external_ctrl(
true);
159 CHECK_DIF_OK(dif_otbn_init(base_addr, &otbn));
161 run_test_with_irqs(&otbn, kAppErrTest, kDifOtbnStatusIdle,