20 #ifndef TEST_MIN_IRQ_PERIPHERAL
21 #define TEST_MIN_IRQ_PERIPHERAL 0
24 #ifndef TEST_MAX_IRQ_PERIPHERAL
25 #define TEST_MAX_IRQ_PERIPHERAL 23
31 #include "sw/device/lib/dif/autogen/dif_adc_ctrl_autogen.h"
32 #include "sw/device/lib/dif/autogen/dif_alert_handler_autogen.h"
33 #include "sw/device/lib/dif/autogen/dif_aon_timer_autogen.h"
34 #include "sw/device/lib/dif/autogen/dif_csrng_autogen.h"
35 #include "sw/device/lib/dif/autogen/dif_edn_autogen.h"
36 #include "sw/device/lib/dif/autogen/dif_entropy_src_autogen.h"
37 #include "sw/device/lib/dif/autogen/dif_flash_ctrl_autogen.h"
38 #include "sw/device/lib/dif/autogen/dif_gpio_autogen.h"
39 #include "sw/device/lib/dif/autogen/dif_hmac_autogen.h"
40 #include "sw/device/lib/dif/autogen/dif_i2c_autogen.h"
41 #include "sw/device/lib/dif/autogen/dif_keymgr_autogen.h"
42 #include "sw/device/lib/dif/autogen/dif_kmac_autogen.h"
43 #include "sw/device/lib/dif/autogen/dif_otbn_autogen.h"
44 #include "sw/device/lib/dif/autogen/dif_otp_ctrl_autogen.h"
45 #include "sw/device/lib/dif/autogen/dif_pattgen_autogen.h"
46 #include "sw/device/lib/dif/autogen/dif_pwrmgr_autogen.h"
47 #include "sw/device/lib/dif/autogen/dif_rv_plic_autogen.h"
48 #include "sw/device/lib/dif/autogen/dif_rv_timer_autogen.h"
49 #include "sw/device/lib/dif/autogen/dif_sensor_ctrl_autogen.h"
50 #include "sw/device/lib/dif/autogen/dif_spi_device_autogen.h"
51 #include "sw/device/lib/dif/autogen/dif_spi_host_autogen.h"
52 #include "sw/device/lib/dif/autogen/dif_sysrst_ctrl_autogen.h"
53 #include "sw/device/lib/dif/autogen/dif_uart_autogen.h"
54 #include "sw/device/lib/dif/autogen/dif_usbdev_autogen.h"
56 #include "sw/device/lib/runtime/irq.h"
58 #include "sw/device/lib/testing/rv_plic_testutils.h"
59 #include "sw/device/lib/testing/test_framework/check.h"
61 #include "sw/device/lib/testing/test_framework/status.h"
65 #if TEST_MIN_IRQ_PERIPHERAL <= 0 && 0 < TEST_MAX_IRQ_PERIPHERAL
66 static dif_adc_ctrl_t adc_ctrl_aon;
69 #if TEST_MIN_IRQ_PERIPHERAL <= 1 && 1 < TEST_MAX_IRQ_PERIPHERAL
70 static dif_alert_handler_t alert_handler;
73 #if TEST_MIN_IRQ_PERIPHERAL <= 2 && 2 < TEST_MAX_IRQ_PERIPHERAL
74 static dif_aon_timer_t aon_timer_aon;
77 #if TEST_MIN_IRQ_PERIPHERAL <= 3 && 3 < TEST_MAX_IRQ_PERIPHERAL
78 static dif_csrng_t csrng;
81 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
82 static dif_edn_t edn0;
85 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
86 static dif_edn_t edn1;
89 #if TEST_MIN_IRQ_PERIPHERAL <= 5 && 5 < TEST_MAX_IRQ_PERIPHERAL
90 static dif_entropy_src_t entropy_src;
93 #if TEST_MIN_IRQ_PERIPHERAL <= 6 && 6 < TEST_MAX_IRQ_PERIPHERAL
94 static dif_flash_ctrl_t flash_ctrl;
97 #if TEST_MIN_IRQ_PERIPHERAL <= 7 && 7 < TEST_MAX_IRQ_PERIPHERAL
98 static dif_gpio_t gpio;
101 #if TEST_MIN_IRQ_PERIPHERAL <= 8 && 8 < TEST_MAX_IRQ_PERIPHERAL
102 static dif_hmac_t hmac;
105 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
106 static dif_i2c_t i2c0;
109 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
110 static dif_i2c_t i2c1;
113 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
114 static dif_i2c_t i2c2;
117 #if TEST_MIN_IRQ_PERIPHERAL <= 10 && 10 < TEST_MAX_IRQ_PERIPHERAL
118 static dif_keymgr_t keymgr;
121 #if TEST_MIN_IRQ_PERIPHERAL <= 11 && 11 < TEST_MAX_IRQ_PERIPHERAL
122 static dif_kmac_t kmac;
125 #if TEST_MIN_IRQ_PERIPHERAL <= 12 && 12 < TEST_MAX_IRQ_PERIPHERAL
126 static dif_otbn_t otbn;
129 #if TEST_MIN_IRQ_PERIPHERAL <= 13 && 13 < TEST_MAX_IRQ_PERIPHERAL
130 static dif_otp_ctrl_t otp_ctrl;
133 #if TEST_MIN_IRQ_PERIPHERAL <= 14 && 14 < TEST_MAX_IRQ_PERIPHERAL
134 static dif_pattgen_t pattgen;
137 #if TEST_MIN_IRQ_PERIPHERAL <= 15 && 15 < TEST_MAX_IRQ_PERIPHERAL
138 static dif_pwrmgr_t pwrmgr_aon;
141 #if TEST_MIN_IRQ_PERIPHERAL <= 16 && 16 < TEST_MAX_IRQ_PERIPHERAL
142 static dif_rv_timer_t rv_timer;
145 #if TEST_MIN_IRQ_PERIPHERAL <= 17 && 17 < TEST_MAX_IRQ_PERIPHERAL
146 static dif_sensor_ctrl_t sensor_ctrl_aon;
149 #if TEST_MIN_IRQ_PERIPHERAL <= 18 && 18 < TEST_MAX_IRQ_PERIPHERAL
150 static dif_spi_device_t spi_device;
153 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
154 static dif_spi_host_t spi_host0;
157 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
158 static dif_spi_host_t spi_host1;
161 #if TEST_MIN_IRQ_PERIPHERAL <= 20 && 20 < TEST_MAX_IRQ_PERIPHERAL
162 static dif_sysrst_ctrl_t sysrst_ctrl_aon;
165 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
166 static dif_uart_t uart0;
169 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
170 static dif_uart_t uart1;
173 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
174 static dif_uart_t uart2;
177 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
178 static dif_uart_t uart3;
181 #if TEST_MIN_IRQ_PERIPHERAL <= 22 && 22 < TEST_MAX_IRQ_PERIPHERAL
182 static dif_usbdev_t usbdev;
185 static dif_rv_plic_t plic;
204 #if TEST_MIN_IRQ_PERIPHERAL <= 0 && 0 < TEST_MAX_IRQ_PERIPHERAL
205 static volatile dif_adc_ctrl_irq_t adc_ctrl_irq_expected;
206 static volatile dif_adc_ctrl_irq_t adc_ctrl_irq_serviced;
209 #if TEST_MIN_IRQ_PERIPHERAL <= 1 && 1 < TEST_MAX_IRQ_PERIPHERAL
210 static volatile dif_alert_handler_irq_t alert_handler_irq_expected;
211 static volatile dif_alert_handler_irq_t alert_handler_irq_serviced;
214 #if TEST_MIN_IRQ_PERIPHERAL <= 2 && 2 < TEST_MAX_IRQ_PERIPHERAL
215 static volatile dif_aon_timer_irq_t aon_timer_irq_expected;
216 static volatile dif_aon_timer_irq_t aon_timer_irq_serviced;
219 #if TEST_MIN_IRQ_PERIPHERAL <= 3 && 3 < TEST_MAX_IRQ_PERIPHERAL
220 static volatile dif_csrng_irq_t csrng_irq_expected;
221 static volatile dif_csrng_irq_t csrng_irq_serviced;
224 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
225 static volatile dif_edn_irq_t edn_irq_expected;
226 static volatile dif_edn_irq_t edn_irq_serviced;
229 #if TEST_MIN_IRQ_PERIPHERAL <= 5 && 5 < TEST_MAX_IRQ_PERIPHERAL
230 static volatile dif_entropy_src_irq_t entropy_src_irq_expected;
231 static volatile dif_entropy_src_irq_t entropy_src_irq_serviced;
234 #if TEST_MIN_IRQ_PERIPHERAL <= 6 && 6 < TEST_MAX_IRQ_PERIPHERAL
235 static volatile dif_flash_ctrl_irq_t flash_ctrl_irq_expected;
236 static volatile dif_flash_ctrl_irq_t flash_ctrl_irq_serviced;
239 #if TEST_MIN_IRQ_PERIPHERAL <= 7 && 7 < TEST_MAX_IRQ_PERIPHERAL
240 static volatile dif_gpio_irq_t gpio_irq_expected;
241 static volatile dif_gpio_irq_t gpio_irq_serviced;
244 #if TEST_MIN_IRQ_PERIPHERAL <= 8 && 8 < TEST_MAX_IRQ_PERIPHERAL
245 static volatile dif_hmac_irq_t hmac_irq_expected;
246 static volatile dif_hmac_irq_t hmac_irq_serviced;
249 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
250 static volatile dif_i2c_irq_t i2c_irq_expected;
251 static volatile dif_i2c_irq_t i2c_irq_serviced;
254 #if TEST_MIN_IRQ_PERIPHERAL <= 10 && 10 < TEST_MAX_IRQ_PERIPHERAL
255 static volatile dif_keymgr_irq_t keymgr_irq_expected;
256 static volatile dif_keymgr_irq_t keymgr_irq_serviced;
259 #if TEST_MIN_IRQ_PERIPHERAL <= 11 && 11 < TEST_MAX_IRQ_PERIPHERAL
260 static volatile dif_kmac_irq_t kmac_irq_expected;
261 static volatile dif_kmac_irq_t kmac_irq_serviced;
264 #if TEST_MIN_IRQ_PERIPHERAL <= 12 && 12 < TEST_MAX_IRQ_PERIPHERAL
265 static volatile dif_otbn_irq_t otbn_irq_expected;
266 static volatile dif_otbn_irq_t otbn_irq_serviced;
269 #if TEST_MIN_IRQ_PERIPHERAL <= 13 && 13 < TEST_MAX_IRQ_PERIPHERAL
270 static volatile dif_otp_ctrl_irq_t otp_ctrl_irq_expected;
271 static volatile dif_otp_ctrl_irq_t otp_ctrl_irq_serviced;
274 #if TEST_MIN_IRQ_PERIPHERAL <= 14 && 14 < TEST_MAX_IRQ_PERIPHERAL
275 static volatile dif_pattgen_irq_t pattgen_irq_expected;
276 static volatile dif_pattgen_irq_t pattgen_irq_serviced;
279 #if TEST_MIN_IRQ_PERIPHERAL <= 15 && 15 < TEST_MAX_IRQ_PERIPHERAL
280 static volatile dif_pwrmgr_irq_t pwrmgr_irq_expected;
281 static volatile dif_pwrmgr_irq_t pwrmgr_irq_serviced;
284 #if TEST_MIN_IRQ_PERIPHERAL <= 16 && 16 < TEST_MAX_IRQ_PERIPHERAL
285 static volatile dif_rv_timer_irq_t rv_timer_irq_expected;
286 static volatile dif_rv_timer_irq_t rv_timer_irq_serviced;
289 #if TEST_MIN_IRQ_PERIPHERAL <= 17 && 17 < TEST_MAX_IRQ_PERIPHERAL
290 static volatile dif_sensor_ctrl_irq_t sensor_ctrl_irq_expected;
291 static volatile dif_sensor_ctrl_irq_t sensor_ctrl_irq_serviced;
294 #if TEST_MIN_IRQ_PERIPHERAL <= 18 && 18 < TEST_MAX_IRQ_PERIPHERAL
295 static volatile dif_spi_device_irq_t spi_device_irq_expected;
296 static volatile dif_spi_device_irq_t spi_device_irq_serviced;
299 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
300 static volatile dif_spi_host_irq_t spi_host_irq_expected;
301 static volatile dif_spi_host_irq_t spi_host_irq_serviced;
304 #if TEST_MIN_IRQ_PERIPHERAL <= 20 && 20 < TEST_MAX_IRQ_PERIPHERAL
305 static volatile dif_sysrst_ctrl_irq_t sysrst_ctrl_irq_expected;
306 static volatile dif_sysrst_ctrl_irq_t sysrst_ctrl_irq_serviced;
309 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
310 static volatile dif_uart_irq_t uart_irq_expected;
311 static volatile dif_uart_irq_t uart_irq_serviced;
314 #if TEST_MIN_IRQ_PERIPHERAL <= 22 && 22 < TEST_MAX_IRQ_PERIPHERAL
315 static volatile dif_usbdev_irq_t usbdev_irq_expected;
316 static volatile dif_usbdev_irq_t usbdev_irq_serviced;
332 void ottf_external_isr(uint32_t *exc_info) {
338 CHECK(peripheral == peripheral_expected,
339 "Interrupt from incorrect peripheral: exp = %d, obs = %d",
340 peripheral_expected, peripheral);
342 switch (peripheral) {
343 #if TEST_MIN_IRQ_PERIPHERAL <= 0 && 0 < TEST_MAX_IRQ_PERIPHERAL
345 dif_adc_ctrl_irq_t irq =
346 (dif_adc_ctrl_irq_t)(plic_irq_id -
349 CHECK(irq == adc_ctrl_irq_expected,
350 "Incorrect adc_ctrl_aon IRQ triggered: exp = %d, obs = %d",
351 adc_ctrl_irq_expected, irq);
352 adc_ctrl_irq_serviced = irq;
354 dif_adc_ctrl_irq_state_snapshot_t snapshot;
355 CHECK_DIF_OK(dif_adc_ctrl_irq_get_state(&adc_ctrl_aon, &snapshot));
356 CHECK(snapshot == (dif_adc_ctrl_irq_state_snapshot_t)(1 << irq),
357 "Only adc_ctrl_aon IRQ %d expected to fire. Actual interrupt "
361 if (0x1 & (1 << irq)) {
364 CHECK_DIF_OK(dif_adc_ctrl_irq_force(&adc_ctrl_aon, irq,
false));
368 if ((0x0 & (1 << irq))) {
369 CHECK_DIF_OK(dif_adc_ctrl_irq_set_enabled(&adc_ctrl_aon, irq,
false));
373 CHECK_DIF_OK(dif_adc_ctrl_irq_acknowledge(&adc_ctrl_aon, irq));
379 #if TEST_MIN_IRQ_PERIPHERAL <= 1 && 1 < TEST_MAX_IRQ_PERIPHERAL
381 dif_alert_handler_irq_t irq =
382 (dif_alert_handler_irq_t)(plic_irq_id -
385 CHECK(irq == alert_handler_irq_expected,
386 "Incorrect alert_handler IRQ triggered: exp = %d, obs = %d",
387 alert_handler_irq_expected, irq);
388 alert_handler_irq_serviced = irq;
390 dif_alert_handler_irq_state_snapshot_t snapshot;
391 CHECK_DIF_OK(dif_alert_handler_irq_get_state(&alert_handler, &snapshot));
392 CHECK(snapshot == (dif_alert_handler_irq_state_snapshot_t)(1 << irq),
393 "Only alert_handler IRQ %d expected to fire. Actual interrupt "
397 CHECK_DIF_OK(dif_alert_handler_irq_acknowledge(&alert_handler, irq));
402 #if TEST_MIN_IRQ_PERIPHERAL <= 2 && 2 < TEST_MAX_IRQ_PERIPHERAL
404 dif_aon_timer_irq_t irq =
405 (dif_aon_timer_irq_t)(plic_irq_id -
408 CHECK(irq == aon_timer_irq_expected,
409 "Incorrect aon_timer_aon IRQ triggered: exp = %d, obs = %d",
410 aon_timer_irq_expected, irq);
411 aon_timer_irq_serviced = irq;
413 dif_aon_timer_irq_state_snapshot_t snapshot;
414 CHECK_DIF_OK(dif_aon_timer_irq_get_state(&aon_timer_aon, &snapshot));
415 CHECK(snapshot == (dif_aon_timer_irq_state_snapshot_t)(1 << irq),
416 "Only aon_timer_aon IRQ %d expected to fire. Actual interrupt "
420 CHECK_DIF_OK(dif_aon_timer_irq_acknowledge(&aon_timer_aon, irq));
425 #if TEST_MIN_IRQ_PERIPHERAL <= 3 && 3 < TEST_MAX_IRQ_PERIPHERAL
427 dif_csrng_irq_t irq =
428 (dif_csrng_irq_t)(plic_irq_id -
431 CHECK(irq == csrng_irq_expected,
432 "Incorrect csrng IRQ triggered: exp = %d, obs = %d",
433 csrng_irq_expected, irq);
434 csrng_irq_serviced = irq;
436 dif_csrng_irq_state_snapshot_t snapshot;
437 CHECK_DIF_OK(dif_csrng_irq_get_state(&csrng, &snapshot));
438 CHECK(snapshot == (dif_csrng_irq_state_snapshot_t)(1 << irq),
439 "Only csrng IRQ %d expected to fire. Actual interrupt "
443 CHECK_DIF_OK(dif_csrng_irq_acknowledge(&csrng, irq));
448 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
451 (dif_edn_irq_t)(plic_irq_id -
454 CHECK(irq == edn_irq_expected,
455 "Incorrect edn0 IRQ triggered: exp = %d, obs = %d",
456 edn_irq_expected, irq);
457 edn_irq_serviced = irq;
459 dif_edn_irq_state_snapshot_t snapshot;
460 CHECK_DIF_OK(dif_edn_irq_get_state(&edn0, &snapshot));
461 CHECK(snapshot == (dif_edn_irq_state_snapshot_t)(1 << irq),
462 "Only edn0 IRQ %d expected to fire. Actual interrupt "
466 CHECK_DIF_OK(dif_edn_irq_acknowledge(&edn0, irq));
471 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
474 (dif_edn_irq_t)(plic_irq_id -
477 CHECK(irq == edn_irq_expected,
478 "Incorrect edn1 IRQ triggered: exp = %d, obs = %d",
479 edn_irq_expected, irq);
480 edn_irq_serviced = irq;
482 dif_edn_irq_state_snapshot_t snapshot;
483 CHECK_DIF_OK(dif_edn_irq_get_state(&edn1, &snapshot));
484 CHECK(snapshot == (dif_edn_irq_state_snapshot_t)(1 << irq),
485 "Only edn1 IRQ %d expected to fire. Actual interrupt "
489 CHECK_DIF_OK(dif_edn_irq_acknowledge(&edn1, irq));
494 #if TEST_MIN_IRQ_PERIPHERAL <= 5 && 5 < TEST_MAX_IRQ_PERIPHERAL
496 dif_entropy_src_irq_t irq =
497 (dif_entropy_src_irq_t)(plic_irq_id -
500 CHECK(irq == entropy_src_irq_expected,
501 "Incorrect entropy_src IRQ triggered: exp = %d, obs = %d",
502 entropy_src_irq_expected, irq);
503 entropy_src_irq_serviced = irq;
505 dif_entropy_src_irq_state_snapshot_t snapshot;
506 CHECK_DIF_OK(dif_entropy_src_irq_get_state(&entropy_src, &snapshot));
507 CHECK(snapshot == (dif_entropy_src_irq_state_snapshot_t)(1 << irq),
508 "Only entropy_src IRQ %d expected to fire. Actual interrupt "
512 CHECK_DIF_OK(dif_entropy_src_irq_acknowledge(&entropy_src, irq));
517 #if TEST_MIN_IRQ_PERIPHERAL <= 6 && 6 < TEST_MAX_IRQ_PERIPHERAL
519 dif_flash_ctrl_irq_t irq =
520 (dif_flash_ctrl_irq_t)(plic_irq_id -
523 CHECK(irq == flash_ctrl_irq_expected,
524 "Incorrect flash_ctrl IRQ triggered: exp = %d, obs = %d",
525 flash_ctrl_irq_expected, irq);
526 flash_ctrl_irq_serviced = irq;
528 dif_flash_ctrl_irq_state_snapshot_t snapshot;
529 CHECK_DIF_OK(dif_flash_ctrl_irq_get_state(&flash_ctrl, &snapshot));
530 CHECK(snapshot == (dif_flash_ctrl_irq_state_snapshot_t)((1 << irq) | 0x3),
531 "Expected flash_ctrl interrupt status %x. Actual interrupt "
533 (1 << irq) | 0x3, snapshot);
535 if (0xf & (1 << irq)) {
538 CHECK_DIF_OK(dif_flash_ctrl_irq_force(&flash_ctrl, irq,
false));
542 if ((0x3 & (1 << irq))) {
543 CHECK_DIF_OK(dif_flash_ctrl_irq_set_enabled(&flash_ctrl, irq,
false));
547 CHECK_DIF_OK(dif_flash_ctrl_irq_acknowledge(&flash_ctrl, irq));
553 #if TEST_MIN_IRQ_PERIPHERAL <= 7 && 7 < TEST_MAX_IRQ_PERIPHERAL
556 (dif_gpio_irq_t)(plic_irq_id -
559 CHECK(irq == gpio_irq_expected,
560 "Incorrect gpio IRQ triggered: exp = %d, obs = %d",
561 gpio_irq_expected, irq);
562 gpio_irq_serviced = irq;
564 dif_gpio_irq_state_snapshot_t snapshot;
565 CHECK_DIF_OK(dif_gpio_irq_get_state(&gpio, &snapshot));
566 CHECK(snapshot == (dif_gpio_irq_state_snapshot_t)(1 << irq),
567 "Only gpio IRQ %d expected to fire. Actual interrupt "
571 CHECK_DIF_OK(dif_gpio_irq_acknowledge(&gpio, irq));
576 #if TEST_MIN_IRQ_PERIPHERAL <= 8 && 8 < TEST_MAX_IRQ_PERIPHERAL
579 (dif_hmac_irq_t)(plic_irq_id -
582 CHECK(irq == hmac_irq_expected,
583 "Incorrect hmac IRQ triggered: exp = %d, obs = %d",
584 hmac_irq_expected, irq);
585 hmac_irq_serviced = irq;
587 dif_hmac_irq_state_snapshot_t snapshot;
588 CHECK_DIF_OK(dif_hmac_irq_get_state(&hmac, &snapshot));
589 CHECK(snapshot == (dif_hmac_irq_state_snapshot_t)(1 << irq),
590 "Only hmac IRQ %d expected to fire. Actual interrupt "
594 if (0x2 & (1 << irq)) {
597 CHECK_DIF_OK(dif_hmac_irq_force(&hmac, irq,
false));
601 if ((0x0 & (1 << irq))) {
602 CHECK_DIF_OK(dif_hmac_irq_set_enabled(&hmac, irq,
false));
606 CHECK_DIF_OK(dif_hmac_irq_acknowledge(&hmac, irq));
612 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
615 (dif_i2c_irq_t)(plic_irq_id -
618 CHECK(irq == i2c_irq_expected,
619 "Incorrect i2c0 IRQ triggered: exp = %d, obs = %d",
620 i2c_irq_expected, irq);
621 i2c_irq_serviced = irq;
623 dif_i2c_irq_state_snapshot_t snapshot;
624 CHECK_DIF_OK(dif_i2c_irq_get_state(&i2c0, &snapshot));
625 CHECK(snapshot == (dif_i2c_irq_state_snapshot_t)(1 << irq),
626 "Only i2c0 IRQ %d expected to fire. Actual interrupt "
630 if (0x1c17 & (1 << irq)) {
633 CHECK_DIF_OK(dif_i2c_irq_force(&i2c0, irq,
false));
637 if ((0x0 & (1 << irq))) {
638 CHECK_DIF_OK(dif_i2c_irq_set_enabled(&i2c0, irq,
false));
642 CHECK_DIF_OK(dif_i2c_irq_acknowledge(&i2c0, irq));
648 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
651 (dif_i2c_irq_t)(plic_irq_id -
654 CHECK(irq == i2c_irq_expected,
655 "Incorrect i2c1 IRQ triggered: exp = %d, obs = %d",
656 i2c_irq_expected, irq);
657 i2c_irq_serviced = irq;
659 dif_i2c_irq_state_snapshot_t snapshot;
660 CHECK_DIF_OK(dif_i2c_irq_get_state(&i2c1, &snapshot));
661 CHECK(snapshot == (dif_i2c_irq_state_snapshot_t)(1 << irq),
662 "Only i2c1 IRQ %d expected to fire. Actual interrupt "
666 if (0x1c17 & (1 << irq)) {
669 CHECK_DIF_OK(dif_i2c_irq_force(&i2c1, irq,
false));
673 if ((0x0 & (1 << irq))) {
674 CHECK_DIF_OK(dif_i2c_irq_set_enabled(&i2c1, irq,
false));
678 CHECK_DIF_OK(dif_i2c_irq_acknowledge(&i2c1, irq));
684 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
687 (dif_i2c_irq_t)(plic_irq_id -
690 CHECK(irq == i2c_irq_expected,
691 "Incorrect i2c2 IRQ triggered: exp = %d, obs = %d",
692 i2c_irq_expected, irq);
693 i2c_irq_serviced = irq;
695 dif_i2c_irq_state_snapshot_t snapshot;
696 CHECK_DIF_OK(dif_i2c_irq_get_state(&i2c2, &snapshot));
697 CHECK(snapshot == (dif_i2c_irq_state_snapshot_t)(1 << irq),
698 "Only i2c2 IRQ %d expected to fire. Actual interrupt "
702 if (0x1c17 & (1 << irq)) {
705 CHECK_DIF_OK(dif_i2c_irq_force(&i2c2, irq,
false));
709 if ((0x0 & (1 << irq))) {
710 CHECK_DIF_OK(dif_i2c_irq_set_enabled(&i2c2, irq,
false));
714 CHECK_DIF_OK(dif_i2c_irq_acknowledge(&i2c2, irq));
720 #if TEST_MIN_IRQ_PERIPHERAL <= 10 && 10 < TEST_MAX_IRQ_PERIPHERAL
722 dif_keymgr_irq_t irq =
723 (dif_keymgr_irq_t)(plic_irq_id -
726 CHECK(irq == keymgr_irq_expected,
727 "Incorrect keymgr IRQ triggered: exp = %d, obs = %d",
728 keymgr_irq_expected, irq);
729 keymgr_irq_serviced = irq;
731 dif_keymgr_irq_state_snapshot_t snapshot;
732 CHECK_DIF_OK(dif_keymgr_irq_get_state(&keymgr, &snapshot));
733 CHECK(snapshot == (dif_keymgr_irq_state_snapshot_t)(1 << irq),
734 "Only keymgr IRQ %d expected to fire. Actual interrupt "
738 CHECK_DIF_OK(dif_keymgr_irq_acknowledge(&keymgr, irq));
743 #if TEST_MIN_IRQ_PERIPHERAL <= 11 && 11 < TEST_MAX_IRQ_PERIPHERAL
746 (dif_kmac_irq_t)(plic_irq_id -
749 CHECK(irq == kmac_irq_expected,
750 "Incorrect kmac IRQ triggered: exp = %d, obs = %d",
751 kmac_irq_expected, irq);
752 kmac_irq_serviced = irq;
754 dif_kmac_irq_state_snapshot_t snapshot;
755 CHECK_DIF_OK(dif_kmac_irq_get_state(&kmac, &snapshot));
756 CHECK(snapshot == (dif_kmac_irq_state_snapshot_t)(1 << irq),
757 "Only kmac IRQ %d expected to fire. Actual interrupt "
761 if (0x2 & (1 << irq)) {
764 CHECK_DIF_OK(dif_kmac_irq_force(&kmac, irq,
false));
768 if ((0x0 & (1 << irq))) {
769 CHECK_DIF_OK(dif_kmac_irq_set_enabled(&kmac, irq,
false));
773 CHECK_DIF_OK(dif_kmac_irq_acknowledge(&kmac, irq));
779 #if TEST_MIN_IRQ_PERIPHERAL <= 12 && 12 < TEST_MAX_IRQ_PERIPHERAL
782 (dif_otbn_irq_t)(plic_irq_id -
785 CHECK(irq == otbn_irq_expected,
786 "Incorrect otbn IRQ triggered: exp = %d, obs = %d",
787 otbn_irq_expected, irq);
788 otbn_irq_serviced = irq;
790 dif_otbn_irq_state_snapshot_t snapshot;
791 CHECK_DIF_OK(dif_otbn_irq_get_state(&otbn, &snapshot));
792 CHECK(snapshot == (dif_otbn_irq_state_snapshot_t)(1 << irq),
793 "Only otbn IRQ %d expected to fire. Actual interrupt "
797 CHECK_DIF_OK(dif_otbn_irq_acknowledge(&otbn, irq));
802 #if TEST_MIN_IRQ_PERIPHERAL <= 13 && 13 < TEST_MAX_IRQ_PERIPHERAL
804 dif_otp_ctrl_irq_t irq =
805 (dif_otp_ctrl_irq_t)(plic_irq_id -
808 CHECK(irq == otp_ctrl_irq_expected,
809 "Incorrect otp_ctrl IRQ triggered: exp = %d, obs = %d",
810 otp_ctrl_irq_expected, irq);
811 otp_ctrl_irq_serviced = irq;
813 dif_otp_ctrl_irq_state_snapshot_t snapshot;
814 CHECK_DIF_OK(dif_otp_ctrl_irq_get_state(&otp_ctrl, &snapshot));
815 CHECK(snapshot == (dif_otp_ctrl_irq_state_snapshot_t)(1 << irq),
816 "Only otp_ctrl IRQ %d expected to fire. Actual interrupt "
820 CHECK_DIF_OK(dif_otp_ctrl_irq_acknowledge(&otp_ctrl, irq));
825 #if TEST_MIN_IRQ_PERIPHERAL <= 14 && 14 < TEST_MAX_IRQ_PERIPHERAL
827 dif_pattgen_irq_t irq =
828 (dif_pattgen_irq_t)(plic_irq_id -
831 CHECK(irq == pattgen_irq_expected,
832 "Incorrect pattgen IRQ triggered: exp = %d, obs = %d",
833 pattgen_irq_expected, irq);
834 pattgen_irq_serviced = irq;
836 dif_pattgen_irq_state_snapshot_t snapshot;
837 CHECK_DIF_OK(dif_pattgen_irq_get_state(&pattgen, &snapshot));
838 CHECK(snapshot == (dif_pattgen_irq_state_snapshot_t)(1 << irq),
839 "Only pattgen IRQ %d expected to fire. Actual interrupt "
843 CHECK_DIF_OK(dif_pattgen_irq_acknowledge(&pattgen, irq));
848 #if TEST_MIN_IRQ_PERIPHERAL <= 15 && 15 < TEST_MAX_IRQ_PERIPHERAL
850 dif_pwrmgr_irq_t irq =
851 (dif_pwrmgr_irq_t)(plic_irq_id -
854 CHECK(irq == pwrmgr_irq_expected,
855 "Incorrect pwrmgr_aon IRQ triggered: exp = %d, obs = %d",
856 pwrmgr_irq_expected, irq);
857 pwrmgr_irq_serviced = irq;
859 dif_pwrmgr_irq_state_snapshot_t snapshot;
860 CHECK_DIF_OK(dif_pwrmgr_irq_get_state(&pwrmgr_aon, &snapshot));
861 CHECK(snapshot == (dif_pwrmgr_irq_state_snapshot_t)(1 << irq),
862 "Only pwrmgr_aon IRQ %d expected to fire. Actual interrupt "
866 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(&pwrmgr_aon, irq));
871 #if TEST_MIN_IRQ_PERIPHERAL <= 16 && 16 < TEST_MAX_IRQ_PERIPHERAL
873 dif_rv_timer_irq_t irq =
874 (dif_rv_timer_irq_t)(plic_irq_id -
877 CHECK(irq == rv_timer_irq_expected,
878 "Incorrect rv_timer IRQ triggered: exp = %d, obs = %d",
879 rv_timer_irq_expected, irq);
880 rv_timer_irq_serviced = irq;
882 dif_rv_timer_irq_state_snapshot_t snapshot;
883 CHECK_DIF_OK(dif_rv_timer_irq_get_state(&rv_timer, kHart, &snapshot));
884 CHECK(snapshot == (dif_rv_timer_irq_state_snapshot_t)(1 << irq),
885 "Only rv_timer IRQ %d expected to fire. Actual interrupt "
889 CHECK_DIF_OK(dif_rv_timer_irq_acknowledge(&rv_timer, irq));
894 #if TEST_MIN_IRQ_PERIPHERAL <= 17 && 17 < TEST_MAX_IRQ_PERIPHERAL
896 dif_sensor_ctrl_irq_t irq =
897 (dif_sensor_ctrl_irq_t)(plic_irq_id -
900 CHECK(irq == sensor_ctrl_irq_expected,
901 "Incorrect sensor_ctrl_aon IRQ triggered: exp = %d, obs = %d",
902 sensor_ctrl_irq_expected, irq);
903 sensor_ctrl_irq_serviced = irq;
905 dif_sensor_ctrl_irq_state_snapshot_t snapshot;
906 CHECK_DIF_OK(dif_sensor_ctrl_irq_get_state(&sensor_ctrl_aon, &snapshot));
907 CHECK(snapshot == (dif_sensor_ctrl_irq_state_snapshot_t)(1 << irq),
908 "Only sensor_ctrl_aon IRQ %d expected to fire. Actual interrupt "
912 CHECK_DIF_OK(dif_sensor_ctrl_irq_acknowledge(&sensor_ctrl_aon, irq));
917 #if TEST_MIN_IRQ_PERIPHERAL <= 18 && 18 < TEST_MAX_IRQ_PERIPHERAL
919 dif_spi_device_irq_t irq =
920 (dif_spi_device_irq_t)(plic_irq_id -
923 CHECK(irq == spi_device_irq_expected,
924 "Incorrect spi_device IRQ triggered: exp = %d, obs = %d",
925 spi_device_irq_expected, irq);
926 spi_device_irq_serviced = irq;
928 dif_spi_device_irq_state_snapshot_t snapshot;
929 CHECK_DIF_OK(dif_spi_device_irq_get_state(&spi_device, &snapshot));
930 CHECK(snapshot == (dif_spi_device_irq_state_snapshot_t)(1 << irq),
931 "Only spi_device IRQ %d expected to fire. Actual interrupt "
935 if (0x20 & (1 << irq)) {
938 CHECK_DIF_OK(dif_spi_device_irq_force(&spi_device, irq,
false));
942 if ((0x0 & (1 << irq))) {
943 CHECK_DIF_OK(dif_spi_device_irq_set_enabled(&spi_device, irq,
false));
947 CHECK_DIF_OK(dif_spi_device_irq_acknowledge(&spi_device, irq));
953 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
955 dif_spi_host_irq_t irq =
956 (dif_spi_host_irq_t)(plic_irq_id -
959 CHECK(irq == spi_host_irq_expected,
960 "Incorrect spi_host0 IRQ triggered: exp = %d, obs = %d",
961 spi_host_irq_expected, irq);
962 spi_host_irq_serviced = irq;
964 dif_spi_host_irq_state_snapshot_t snapshot;
965 CHECK_DIF_OK(dif_spi_host_irq_get_state(&spi_host0, &snapshot));
966 CHECK(snapshot == (dif_spi_host_irq_state_snapshot_t)(1 << irq),
967 "Only spi_host0 IRQ %d expected to fire. Actual interrupt "
971 if (0x2 & (1 << irq)) {
974 CHECK_DIF_OK(dif_spi_host_irq_force(&spi_host0, irq,
false));
978 if ((0x0 & (1 << irq))) {
979 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(&spi_host0, irq,
false));
983 CHECK_DIF_OK(dif_spi_host_irq_acknowledge(&spi_host0, irq));
989 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
991 dif_spi_host_irq_t irq =
992 (dif_spi_host_irq_t)(plic_irq_id -
995 CHECK(irq == spi_host_irq_expected,
996 "Incorrect spi_host1 IRQ triggered: exp = %d, obs = %d",
997 spi_host_irq_expected, irq);
998 spi_host_irq_serviced = irq;
1000 dif_spi_host_irq_state_snapshot_t snapshot;
1001 CHECK_DIF_OK(dif_spi_host_irq_get_state(&spi_host1, &snapshot));
1002 CHECK(snapshot == (dif_spi_host_irq_state_snapshot_t)(1 << irq),
1003 "Only spi_host1 IRQ %d expected to fire. Actual interrupt "
1007 if (0x2 & (1 << irq)) {
1010 CHECK_DIF_OK(dif_spi_host_irq_force(&spi_host1, irq,
false));
1014 if ((0x0 & (1 << irq))) {
1015 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(&spi_host1, irq,
false));
1019 CHECK_DIF_OK(dif_spi_host_irq_acknowledge(&spi_host1, irq));
1025 #if TEST_MIN_IRQ_PERIPHERAL <= 20 && 20 < TEST_MAX_IRQ_PERIPHERAL
1027 dif_sysrst_ctrl_irq_t irq =
1028 (dif_sysrst_ctrl_irq_t)(plic_irq_id -
1031 CHECK(irq == sysrst_ctrl_irq_expected,
1032 "Incorrect sysrst_ctrl_aon IRQ triggered: exp = %d, obs = %d",
1033 sysrst_ctrl_irq_expected, irq);
1034 sysrst_ctrl_irq_serviced = irq;
1036 dif_sysrst_ctrl_irq_state_snapshot_t snapshot;
1037 CHECK_DIF_OK(dif_sysrst_ctrl_irq_get_state(&sysrst_ctrl_aon, &snapshot));
1038 CHECK(snapshot == (dif_sysrst_ctrl_irq_state_snapshot_t)(1 << irq),
1039 "Only sysrst_ctrl_aon IRQ %d expected to fire. Actual interrupt "
1043 if (0x1 & (1 << irq)) {
1046 CHECK_DIF_OK(dif_sysrst_ctrl_irq_force(&sysrst_ctrl_aon, irq,
false));
1050 if ((0x0 & (1 << irq))) {
1051 CHECK_DIF_OK(dif_sysrst_ctrl_irq_set_enabled(&sysrst_ctrl_aon, irq,
false));
1055 CHECK_DIF_OK(dif_sysrst_ctrl_irq_acknowledge(&sysrst_ctrl_aon, irq));
1061 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1063 dif_uart_irq_t irq =
1064 (dif_uart_irq_t)(plic_irq_id -
1067 CHECK(irq == uart_irq_expected,
1068 "Incorrect uart0 IRQ triggered: exp = %d, obs = %d",
1069 uart_irq_expected, irq);
1070 uart_irq_serviced = irq;
1072 dif_uart_irq_state_snapshot_t snapshot;
1073 CHECK_DIF_OK(dif_uart_irq_get_state(&uart0, &snapshot));
1074 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)((1 << irq) | 0x101),
1075 "Expected uart0 interrupt status %x. Actual interrupt "
1077 (1 << irq) | 0x101, snapshot);
1079 if (0x103 & (1 << irq)) {
1082 CHECK_DIF_OK(dif_uart_irq_force(&uart0, irq,
false));
1086 if ((0x101 & (1 << irq))) {
1087 CHECK_DIF_OK(dif_uart_irq_set_enabled(&uart0, irq,
false));
1091 CHECK_DIF_OK(dif_uart_irq_acknowledge(&uart0, irq));
1097 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1099 dif_uart_irq_t irq =
1100 (dif_uart_irq_t)(plic_irq_id -
1103 CHECK(irq == uart_irq_expected,
1104 "Incorrect uart1 IRQ triggered: exp = %d, obs = %d",
1105 uart_irq_expected, irq);
1106 uart_irq_serviced = irq;
1108 dif_uart_irq_state_snapshot_t snapshot;
1109 CHECK_DIF_OK(dif_uart_irq_get_state(&uart1, &snapshot));
1110 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)((1 << irq) | 0x101),
1111 "Expected uart1 interrupt status %x. Actual interrupt "
1113 (1 << irq) | 0x101, snapshot);
1115 if (0x103 & (1 << irq)) {
1118 CHECK_DIF_OK(dif_uart_irq_force(&uart1, irq,
false));
1122 if ((0x101 & (1 << irq))) {
1123 CHECK_DIF_OK(dif_uart_irq_set_enabled(&uart1, irq,
false));
1127 CHECK_DIF_OK(dif_uart_irq_acknowledge(&uart1, irq));
1133 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1135 dif_uart_irq_t irq =
1136 (dif_uart_irq_t)(plic_irq_id -
1139 CHECK(irq == uart_irq_expected,
1140 "Incorrect uart2 IRQ triggered: exp = %d, obs = %d",
1141 uart_irq_expected, irq);
1142 uart_irq_serviced = irq;
1144 dif_uart_irq_state_snapshot_t snapshot;
1145 CHECK_DIF_OK(dif_uart_irq_get_state(&uart2, &snapshot));
1146 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)((1 << irq) | 0x101),
1147 "Expected uart2 interrupt status %x. Actual interrupt "
1149 (1 << irq) | 0x101, snapshot);
1151 if (0x103 & (1 << irq)) {
1154 CHECK_DIF_OK(dif_uart_irq_force(&uart2, irq,
false));
1158 if ((0x101 & (1 << irq))) {
1159 CHECK_DIF_OK(dif_uart_irq_set_enabled(&uart2, irq,
false));
1163 CHECK_DIF_OK(dif_uart_irq_acknowledge(&uart2, irq));
1169 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1171 dif_uart_irq_t irq =
1172 (dif_uart_irq_t)(plic_irq_id -
1175 CHECK(irq == uart_irq_expected,
1176 "Incorrect uart3 IRQ triggered: exp = %d, obs = %d",
1177 uart_irq_expected, irq);
1178 uart_irq_serviced = irq;
1180 dif_uart_irq_state_snapshot_t snapshot;
1181 CHECK_DIF_OK(dif_uart_irq_get_state(&uart3, &snapshot));
1182 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)((1 << irq) | 0x101),
1183 "Expected uart3 interrupt status %x. Actual interrupt "
1185 (1 << irq) | 0x101, snapshot);
1187 if (0x103 & (1 << irq)) {
1190 CHECK_DIF_OK(dif_uart_irq_force(&uart3, irq,
false));
1194 if ((0x101 & (1 << irq))) {
1195 CHECK_DIF_OK(dif_uart_irq_set_enabled(&uart3, irq,
false));
1199 CHECK_DIF_OK(dif_uart_irq_acknowledge(&uart3, irq));
1205 #if TEST_MIN_IRQ_PERIPHERAL <= 22 && 22 < TEST_MAX_IRQ_PERIPHERAL
1207 dif_usbdev_irq_t irq =
1208 (dif_usbdev_irq_t)(plic_irq_id -
1211 CHECK(irq == usbdev_irq_expected,
1212 "Incorrect usbdev IRQ triggered: exp = %d, obs = %d",
1213 usbdev_irq_expected, irq);
1214 usbdev_irq_serviced = irq;
1216 dif_usbdev_irq_state_snapshot_t snapshot;
1217 CHECK_DIF_OK(dif_usbdev_irq_get_state(&usbdev, &snapshot));
1218 CHECK(snapshot == (dif_usbdev_irq_state_snapshot_t)(1 << irq),
1219 "Only usbdev IRQ %d expected to fire. Actual interrupt "
1223 if (0x20183 & (1 << irq)) {
1226 CHECK_DIF_OK(dif_usbdev_irq_force(&usbdev, irq,
false));
1230 if ((0x0 & (1 << irq))) {
1231 CHECK_DIF_OK(dif_usbdev_irq_set_enabled(&usbdev, irq,
false));
1235 CHECK_DIF_OK(dif_usbdev_irq_acknowledge(&usbdev, irq));
1243 test_status_set(kTestStatusFailed);
1252 static void peripherals_init(
void) {
1255 #if TEST_MIN_IRQ_PERIPHERAL <= 0 && 0 < TEST_MAX_IRQ_PERIPHERAL
1257 CHECK_DIF_OK(dif_adc_ctrl_init(base_addr, &adc_ctrl_aon));
1260 #if TEST_MIN_IRQ_PERIPHERAL <= 1 && 1 < TEST_MAX_IRQ_PERIPHERAL
1262 CHECK_DIF_OK(dif_alert_handler_init(base_addr, &alert_handler));
1265 #if TEST_MIN_IRQ_PERIPHERAL <= 2 && 2 < TEST_MAX_IRQ_PERIPHERAL
1267 CHECK_DIF_OK(dif_aon_timer_init(base_addr, &aon_timer_aon));
1270 #if TEST_MIN_IRQ_PERIPHERAL <= 3 && 3 < TEST_MAX_IRQ_PERIPHERAL
1272 CHECK_DIF_OK(dif_csrng_init(base_addr, &csrng));
1275 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1277 CHECK_DIF_OK(dif_edn_init(base_addr, &edn0));
1280 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1282 CHECK_DIF_OK(dif_edn_init(base_addr, &edn1));
1285 #if TEST_MIN_IRQ_PERIPHERAL <= 5 && 5 < TEST_MAX_IRQ_PERIPHERAL
1287 CHECK_DIF_OK(dif_entropy_src_init(base_addr, &entropy_src));
1290 #if TEST_MIN_IRQ_PERIPHERAL <= 6 && 6 < TEST_MAX_IRQ_PERIPHERAL
1292 CHECK_DIF_OK(dif_flash_ctrl_init(base_addr, &flash_ctrl));
1295 #if TEST_MIN_IRQ_PERIPHERAL <= 7 && 7 < TEST_MAX_IRQ_PERIPHERAL
1297 CHECK_DIF_OK(dif_gpio_init(base_addr, &gpio));
1300 #if TEST_MIN_IRQ_PERIPHERAL <= 8 && 8 < TEST_MAX_IRQ_PERIPHERAL
1302 CHECK_DIF_OK(dif_hmac_init(base_addr, &hmac));
1305 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1307 CHECK_DIF_OK(dif_i2c_init(base_addr, &i2c0));
1310 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1312 CHECK_DIF_OK(dif_i2c_init(base_addr, &i2c1));
1315 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1317 CHECK_DIF_OK(dif_i2c_init(base_addr, &i2c2));
1320 #if TEST_MIN_IRQ_PERIPHERAL <= 10 && 10 < TEST_MAX_IRQ_PERIPHERAL
1322 CHECK_DIF_OK(dif_keymgr_init(base_addr, &keymgr));
1325 #if TEST_MIN_IRQ_PERIPHERAL <= 11 && 11 < TEST_MAX_IRQ_PERIPHERAL
1327 CHECK_DIF_OK(dif_kmac_init(base_addr, &kmac));
1330 #if TEST_MIN_IRQ_PERIPHERAL <= 12 && 12 < TEST_MAX_IRQ_PERIPHERAL
1332 CHECK_DIF_OK(dif_otbn_init(base_addr, &otbn));
1335 #if TEST_MIN_IRQ_PERIPHERAL <= 13 && 13 < TEST_MAX_IRQ_PERIPHERAL
1337 CHECK_DIF_OK(dif_otp_ctrl_init(base_addr, &otp_ctrl));
1340 #if TEST_MIN_IRQ_PERIPHERAL <= 14 && 14 < TEST_MAX_IRQ_PERIPHERAL
1342 CHECK_DIF_OK(dif_pattgen_init(base_addr, &pattgen));
1345 #if TEST_MIN_IRQ_PERIPHERAL <= 15 && 15 < TEST_MAX_IRQ_PERIPHERAL
1347 CHECK_DIF_OK(dif_pwrmgr_init(base_addr, &pwrmgr_aon));
1350 #if TEST_MIN_IRQ_PERIPHERAL <= 16 && 16 < TEST_MAX_IRQ_PERIPHERAL
1352 CHECK_DIF_OK(dif_rv_timer_init(base_addr, &rv_timer));
1355 #if TEST_MIN_IRQ_PERIPHERAL <= 17 && 17 < TEST_MAX_IRQ_PERIPHERAL
1357 CHECK_DIF_OK(dif_sensor_ctrl_init(base_addr, &sensor_ctrl_aon));
1360 #if TEST_MIN_IRQ_PERIPHERAL <= 18 && 18 < TEST_MAX_IRQ_PERIPHERAL
1362 CHECK_DIF_OK(dif_spi_device_init(base_addr, &spi_device));
1365 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
1367 CHECK_DIF_OK(dif_spi_host_init(base_addr, &spi_host0));
1370 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
1372 CHECK_DIF_OK(dif_spi_host_init(base_addr, &spi_host1));
1375 #if TEST_MIN_IRQ_PERIPHERAL <= 20 && 20 < TEST_MAX_IRQ_PERIPHERAL
1377 CHECK_DIF_OK(dif_sysrst_ctrl_init(base_addr, &sysrst_ctrl_aon));
1380 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1382 CHECK_DIF_OK(dif_uart_init(base_addr, &uart0));
1385 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1387 CHECK_DIF_OK(dif_uart_init(base_addr, &uart1));
1390 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1392 CHECK_DIF_OK(dif_uart_init(base_addr, &uart2));
1395 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1397 CHECK_DIF_OK(dif_uart_init(base_addr, &uart3));
1400 #if TEST_MIN_IRQ_PERIPHERAL <= 22 && 22 < TEST_MAX_IRQ_PERIPHERAL
1402 CHECK_DIF_OK(dif_usbdev_init(base_addr, &usbdev));
1406 CHECK_DIF_OK(dif_rv_plic_init(base_addr, &plic));
1412 static void peripheral_irqs_clear(
void) {
1413 #if TEST_MIN_IRQ_PERIPHERAL <= 0 && 0 < TEST_MAX_IRQ_PERIPHERAL
1414 CHECK_DIF_OK(dif_adc_ctrl_irq_acknowledge_all(&adc_ctrl_aon));
1417 #if TEST_MIN_IRQ_PERIPHERAL <= 1 && 1 < TEST_MAX_IRQ_PERIPHERAL
1418 CHECK_DIF_OK(dif_alert_handler_irq_acknowledge_all(&alert_handler));
1421 #if TEST_MIN_IRQ_PERIPHERAL <= 2 && 2 < TEST_MAX_IRQ_PERIPHERAL
1422 CHECK_DIF_OK(dif_aon_timer_irq_acknowledge_all(&aon_timer_aon));
1425 #if TEST_MIN_IRQ_PERIPHERAL <= 3 && 3 < TEST_MAX_IRQ_PERIPHERAL
1426 CHECK_DIF_OK(dif_csrng_irq_acknowledge_all(&csrng));
1429 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1430 CHECK_DIF_OK(dif_edn_irq_acknowledge_all(&edn0));
1433 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1434 CHECK_DIF_OK(dif_edn_irq_acknowledge_all(&edn1));
1437 #if TEST_MIN_IRQ_PERIPHERAL <= 5 && 5 < TEST_MAX_IRQ_PERIPHERAL
1438 CHECK_DIF_OK(dif_entropy_src_irq_acknowledge_all(&entropy_src));
1441 #if TEST_MIN_IRQ_PERIPHERAL <= 6 && 6 < TEST_MAX_IRQ_PERIPHERAL
1442 CHECK_DIF_OK(dif_flash_ctrl_irq_acknowledge_all(&flash_ctrl));
1445 #if TEST_MIN_IRQ_PERIPHERAL <= 7 && 7 < TEST_MAX_IRQ_PERIPHERAL
1446 CHECK_DIF_OK(dif_gpio_irq_acknowledge_all(&gpio));
1449 #if TEST_MIN_IRQ_PERIPHERAL <= 8 && 8 < TEST_MAX_IRQ_PERIPHERAL
1450 CHECK_DIF_OK(dif_hmac_irq_acknowledge_all(&hmac));
1453 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1454 CHECK_DIF_OK(dif_i2c_irq_acknowledge_all(&i2c0));
1457 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1458 CHECK_DIF_OK(dif_i2c_irq_acknowledge_all(&i2c1));
1461 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1462 CHECK_DIF_OK(dif_i2c_irq_acknowledge_all(&i2c2));
1465 #if TEST_MIN_IRQ_PERIPHERAL <= 10 && 10 < TEST_MAX_IRQ_PERIPHERAL
1466 CHECK_DIF_OK(dif_keymgr_irq_acknowledge_all(&keymgr));
1469 #if TEST_MIN_IRQ_PERIPHERAL <= 11 && 11 < TEST_MAX_IRQ_PERIPHERAL
1470 CHECK_DIF_OK(dif_kmac_irq_acknowledge_all(&kmac));
1473 #if TEST_MIN_IRQ_PERIPHERAL <= 12 && 12 < TEST_MAX_IRQ_PERIPHERAL
1474 CHECK_DIF_OK(dif_otbn_irq_acknowledge_all(&otbn));
1477 #if TEST_MIN_IRQ_PERIPHERAL <= 13 && 13 < TEST_MAX_IRQ_PERIPHERAL
1479 CHECK_DIF_OK(dif_otp_ctrl_irq_acknowledge_all(&otp_ctrl));
1483 #if TEST_MIN_IRQ_PERIPHERAL <= 14 && 14 < TEST_MAX_IRQ_PERIPHERAL
1484 CHECK_DIF_OK(dif_pattgen_irq_acknowledge_all(&pattgen));
1487 #if TEST_MIN_IRQ_PERIPHERAL <= 15 && 15 < TEST_MAX_IRQ_PERIPHERAL
1488 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge_all(&pwrmgr_aon));
1491 #if TEST_MIN_IRQ_PERIPHERAL <= 16 && 16 < TEST_MAX_IRQ_PERIPHERAL
1492 CHECK_DIF_OK(dif_rv_timer_irq_acknowledge_all(&rv_timer, kHart));
1495 #if TEST_MIN_IRQ_PERIPHERAL <= 17 && 17 < TEST_MAX_IRQ_PERIPHERAL
1496 CHECK_DIF_OK(dif_sensor_ctrl_irq_acknowledge_all(&sensor_ctrl_aon));
1499 #if TEST_MIN_IRQ_PERIPHERAL <= 18 && 18 < TEST_MAX_IRQ_PERIPHERAL
1500 CHECK_DIF_OK(dif_spi_device_irq_acknowledge_all(&spi_device));
1503 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
1504 CHECK_DIF_OK(dif_spi_host_irq_acknowledge_all(&spi_host0));
1507 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
1508 CHECK_DIF_OK(dif_spi_host_irq_acknowledge_all(&spi_host1));
1511 #if TEST_MIN_IRQ_PERIPHERAL <= 20 && 20 < TEST_MAX_IRQ_PERIPHERAL
1512 CHECK_DIF_OK(dif_sysrst_ctrl_irq_acknowledge_all(&sysrst_ctrl_aon));
1515 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1516 CHECK_DIF_OK(dif_uart_irq_acknowledge_all(&uart0));
1519 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1520 CHECK_DIF_OK(dif_uart_irq_acknowledge_all(&uart1));
1523 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1524 CHECK_DIF_OK(dif_uart_irq_acknowledge_all(&uart2));
1527 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1528 CHECK_DIF_OK(dif_uart_irq_acknowledge_all(&uart3));
1531 #if TEST_MIN_IRQ_PERIPHERAL <= 22 && 22 < TEST_MAX_IRQ_PERIPHERAL
1532 CHECK_DIF_OK(dif_usbdev_irq_acknowledge_all(&usbdev));
1539 static void peripheral_irqs_enable(
void) {
1540 #if TEST_MIN_IRQ_PERIPHERAL <= 0 && 0 < TEST_MAX_IRQ_PERIPHERAL
1541 dif_adc_ctrl_irq_state_snapshot_t adc_ctrl_irqs =
1542 (dif_adc_ctrl_irq_state_snapshot_t)0xffffffff;
1545 #if TEST_MIN_IRQ_PERIPHERAL <= 1 && 1 < TEST_MAX_IRQ_PERIPHERAL
1546 dif_alert_handler_irq_state_snapshot_t alert_handler_irqs =
1547 (dif_alert_handler_irq_state_snapshot_t)0xffffffff;
1550 #if TEST_MIN_IRQ_PERIPHERAL <= 3 && 3 < TEST_MAX_IRQ_PERIPHERAL
1551 dif_csrng_irq_state_snapshot_t csrng_irqs =
1552 (dif_csrng_irq_state_snapshot_t)0xffffffff;
1555 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1556 dif_edn_irq_state_snapshot_t edn_irqs =
1557 (dif_edn_irq_state_snapshot_t)0xffffffff;
1560 #if TEST_MIN_IRQ_PERIPHERAL <= 5 && 5 < TEST_MAX_IRQ_PERIPHERAL
1561 dif_entropy_src_irq_state_snapshot_t entropy_src_irqs =
1562 (dif_entropy_src_irq_state_snapshot_t)0xffffffff;
1565 #if TEST_MIN_IRQ_PERIPHERAL <= 6 && 6 < TEST_MAX_IRQ_PERIPHERAL
1570 dif_flash_ctrl_irq_state_snapshot_t flash_ctrl_irqs =
1571 (dif_flash_ctrl_irq_state_snapshot_t)0xfffffffc;
1574 #if TEST_MIN_IRQ_PERIPHERAL <= 7 && 7 < TEST_MAX_IRQ_PERIPHERAL
1575 dif_gpio_irq_state_snapshot_t gpio_irqs =
1576 (dif_gpio_irq_state_snapshot_t)0xffffffff;
1579 #if TEST_MIN_IRQ_PERIPHERAL <= 8 && 8 < TEST_MAX_IRQ_PERIPHERAL
1580 dif_hmac_irq_state_snapshot_t hmac_irqs =
1581 (dif_hmac_irq_state_snapshot_t)0xffffffff;
1584 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1585 dif_i2c_irq_state_snapshot_t i2c_irqs =
1586 (dif_i2c_irq_state_snapshot_t)0xffffffff;
1589 #if TEST_MIN_IRQ_PERIPHERAL <= 10 && 10 < TEST_MAX_IRQ_PERIPHERAL
1590 dif_keymgr_irq_state_snapshot_t keymgr_irqs =
1591 (dif_keymgr_irq_state_snapshot_t)0xffffffff;
1594 #if TEST_MIN_IRQ_PERIPHERAL <= 11 && 11 < TEST_MAX_IRQ_PERIPHERAL
1595 dif_kmac_irq_state_snapshot_t kmac_irqs =
1596 (dif_kmac_irq_state_snapshot_t)0xffffffff;
1599 #if TEST_MIN_IRQ_PERIPHERAL <= 12 && 12 < TEST_MAX_IRQ_PERIPHERAL
1600 dif_otbn_irq_state_snapshot_t otbn_irqs =
1601 (dif_otbn_irq_state_snapshot_t)0xffffffff;
1604 #if TEST_MIN_IRQ_PERIPHERAL <= 13 && 13 < TEST_MAX_IRQ_PERIPHERAL
1605 dif_otp_ctrl_irq_state_snapshot_t otp_ctrl_irqs =
1606 (dif_otp_ctrl_irq_state_snapshot_t)0xffffffff;
1609 #if TEST_MIN_IRQ_PERIPHERAL <= 14 && 14 < TEST_MAX_IRQ_PERIPHERAL
1610 dif_pattgen_irq_state_snapshot_t pattgen_irqs =
1611 (dif_pattgen_irq_state_snapshot_t)0xffffffff;
1614 #if TEST_MIN_IRQ_PERIPHERAL <= 15 && 15 < TEST_MAX_IRQ_PERIPHERAL
1615 dif_pwrmgr_irq_state_snapshot_t pwrmgr_irqs =
1616 (dif_pwrmgr_irq_state_snapshot_t)0xffffffff;
1619 #if TEST_MIN_IRQ_PERIPHERAL <= 16 && 16 < TEST_MAX_IRQ_PERIPHERAL
1620 dif_rv_timer_irq_state_snapshot_t rv_timer_irqs =
1621 (dif_rv_timer_irq_state_snapshot_t)0xffffffff;
1624 #if TEST_MIN_IRQ_PERIPHERAL <= 17 && 17 < TEST_MAX_IRQ_PERIPHERAL
1625 dif_sensor_ctrl_irq_state_snapshot_t sensor_ctrl_irqs =
1626 (dif_sensor_ctrl_irq_state_snapshot_t)0xffffffff;
1629 #if TEST_MIN_IRQ_PERIPHERAL <= 18 && 18 < TEST_MAX_IRQ_PERIPHERAL
1630 dif_spi_device_irq_state_snapshot_t spi_device_irqs =
1631 (dif_spi_device_irq_state_snapshot_t)0xffffffff;
1634 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
1635 dif_spi_host_irq_state_snapshot_t spi_host_irqs =
1636 (dif_spi_host_irq_state_snapshot_t)0xffffffff;
1639 #if TEST_MIN_IRQ_PERIPHERAL <= 20 && 20 < TEST_MAX_IRQ_PERIPHERAL
1640 dif_sysrst_ctrl_irq_state_snapshot_t sysrst_ctrl_irqs =
1641 (dif_sysrst_ctrl_irq_state_snapshot_t)0xffffffff;
1644 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1649 dif_uart_irq_state_snapshot_t uart_irqs =
1650 (dif_uart_irq_state_snapshot_t)0xfffffefe;
1653 #if TEST_MIN_IRQ_PERIPHERAL <= 22 && 22 < TEST_MAX_IRQ_PERIPHERAL
1654 dif_usbdev_irq_state_snapshot_t usbdev_irqs =
1655 (dif_usbdev_irq_state_snapshot_t)0xffffffff;
1658 #if TEST_MIN_IRQ_PERIPHERAL <= 0 && 0 < TEST_MAX_IRQ_PERIPHERAL
1659 CHECK_DIF_OK(dif_adc_ctrl_irq_restore_all(&adc_ctrl_aon, &adc_ctrl_irqs));
1662 #if TEST_MIN_IRQ_PERIPHERAL <= 1 && 1 < TEST_MAX_IRQ_PERIPHERAL
1663 CHECK_DIF_OK(dif_alert_handler_irq_restore_all(&alert_handler, &alert_handler_irqs));
1666 #if TEST_MIN_IRQ_PERIPHERAL <= 3 && 3 < TEST_MAX_IRQ_PERIPHERAL
1667 CHECK_DIF_OK(dif_csrng_irq_restore_all(&csrng, &csrng_irqs));
1670 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1671 CHECK_DIF_OK(dif_edn_irq_restore_all(&edn0, &edn_irqs));
1674 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1675 CHECK_DIF_OK(dif_edn_irq_restore_all(&edn1, &edn_irqs));
1678 #if TEST_MIN_IRQ_PERIPHERAL <= 5 && 5 < TEST_MAX_IRQ_PERIPHERAL
1679 CHECK_DIF_OK(dif_entropy_src_irq_restore_all(&entropy_src, &entropy_src_irqs));
1682 #if TEST_MIN_IRQ_PERIPHERAL <= 6 && 6 < TEST_MAX_IRQ_PERIPHERAL
1683 CHECK_DIF_OK(dif_flash_ctrl_irq_restore_all(&flash_ctrl, &flash_ctrl_irqs));
1686 #if TEST_MIN_IRQ_PERIPHERAL <= 7 && 7 < TEST_MAX_IRQ_PERIPHERAL
1687 CHECK_DIF_OK(dif_gpio_irq_restore_all(&gpio, &gpio_irqs));
1690 #if TEST_MIN_IRQ_PERIPHERAL <= 8 && 8 < TEST_MAX_IRQ_PERIPHERAL
1691 CHECK_DIF_OK(dif_hmac_irq_restore_all(&hmac, &hmac_irqs));
1694 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1695 CHECK_DIF_OK(dif_i2c_irq_restore_all(&i2c0, &i2c_irqs));
1698 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1699 CHECK_DIF_OK(dif_i2c_irq_restore_all(&i2c1, &i2c_irqs));
1702 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1703 CHECK_DIF_OK(dif_i2c_irq_restore_all(&i2c2, &i2c_irqs));
1706 #if TEST_MIN_IRQ_PERIPHERAL <= 10 && 10 < TEST_MAX_IRQ_PERIPHERAL
1707 CHECK_DIF_OK(dif_keymgr_irq_restore_all(&keymgr, &keymgr_irqs));
1710 #if TEST_MIN_IRQ_PERIPHERAL <= 11 && 11 < TEST_MAX_IRQ_PERIPHERAL
1711 CHECK_DIF_OK(dif_kmac_irq_restore_all(&kmac, &kmac_irqs));
1714 #if TEST_MIN_IRQ_PERIPHERAL <= 12 && 12 < TEST_MAX_IRQ_PERIPHERAL
1715 CHECK_DIF_OK(dif_otbn_irq_restore_all(&otbn, &otbn_irqs));
1718 #if TEST_MIN_IRQ_PERIPHERAL <= 13 && 13 < TEST_MAX_IRQ_PERIPHERAL
1720 CHECK_DIF_OK(dif_otp_ctrl_irq_restore_all(&otp_ctrl, &otp_ctrl_irqs));
1724 #if TEST_MIN_IRQ_PERIPHERAL <= 14 && 14 < TEST_MAX_IRQ_PERIPHERAL
1725 CHECK_DIF_OK(dif_pattgen_irq_restore_all(&pattgen, &pattgen_irqs));
1728 #if TEST_MIN_IRQ_PERIPHERAL <= 15 && 15 < TEST_MAX_IRQ_PERIPHERAL
1729 CHECK_DIF_OK(dif_pwrmgr_irq_restore_all(&pwrmgr_aon, &pwrmgr_irqs));
1732 #if TEST_MIN_IRQ_PERIPHERAL <= 16 && 16 < TEST_MAX_IRQ_PERIPHERAL
1733 CHECK_DIF_OK(dif_rv_timer_irq_restore_all(&rv_timer, kHart, &rv_timer_irqs));
1736 #if TEST_MIN_IRQ_PERIPHERAL <= 17 && 17 < TEST_MAX_IRQ_PERIPHERAL
1737 CHECK_DIF_OK(dif_sensor_ctrl_irq_restore_all(&sensor_ctrl_aon, &sensor_ctrl_irqs));
1740 #if TEST_MIN_IRQ_PERIPHERAL <= 18 && 18 < TEST_MAX_IRQ_PERIPHERAL
1741 CHECK_DIF_OK(dif_spi_device_irq_restore_all(&spi_device, &spi_device_irqs));
1744 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
1745 CHECK_DIF_OK(dif_spi_host_irq_restore_all(&spi_host0, &spi_host_irqs));
1748 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
1749 CHECK_DIF_OK(dif_spi_host_irq_restore_all(&spi_host1, &spi_host_irqs));
1752 #if TEST_MIN_IRQ_PERIPHERAL <= 20 && 20 < TEST_MAX_IRQ_PERIPHERAL
1753 CHECK_DIF_OK(dif_sysrst_ctrl_irq_restore_all(&sysrst_ctrl_aon, &sysrst_ctrl_irqs));
1756 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1760 CHECK_DIF_OK(dif_uart_irq_restore_all(&uart0, &uart_irqs));
1764 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1765 CHECK_DIF_OK(dif_uart_irq_restore_all(&uart1, &uart_irqs));
1768 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1769 CHECK_DIF_OK(dif_uart_irq_restore_all(&uart2, &uart_irqs));
1772 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
1773 CHECK_DIF_OK(dif_uart_irq_restore_all(&uart3, &uart_irqs));
1776 #if TEST_MIN_IRQ_PERIPHERAL <= 22 && 22 < TEST_MAX_IRQ_PERIPHERAL
1777 CHECK_DIF_OK(dif_usbdev_irq_restore_all(&usbdev, &usbdev_irqs));
1790 static void peripheral_irqs_trigger(
void) {
1791 unsigned int status_default_mask;
1794 (void)status_default_mask;
1796 #if TEST_MIN_IRQ_PERIPHERAL <= 0 && 0 < TEST_MAX_IRQ_PERIPHERAL
1798 status_default_mask = 0x0;
1799 for (dif_adc_ctrl_irq_t irq = kDifAdcCtrlIrqMatchPending; irq <= kDifAdcCtrlIrqMatchPending;
1801 adc_ctrl_irq_expected = irq;
1802 LOG_INFO(
"Triggering adc_ctrl_aon IRQ %d.", irq);
1803 CHECK_DIF_OK(dif_adc_ctrl_irq_force(&adc_ctrl_aon, irq,
true));
1808 if ((status_default_mask & 0x1)) {
1809 CHECK_DIF_OK(dif_adc_ctrl_irq_set_enabled(&adc_ctrl_aon, irq,
true));
1811 status_default_mask >>= 1;
1816 LOG_INFO(
"IRQ %d from adc_ctrl_aon is serviced.", irq);
1820 #if TEST_MIN_IRQ_PERIPHERAL <= 1 && 1 < TEST_MAX_IRQ_PERIPHERAL
1822 for (dif_alert_handler_irq_t irq = kDifAlertHandlerIrqClassa; irq <= kDifAlertHandlerIrqClassd;
1824 alert_handler_irq_expected = irq;
1825 LOG_INFO(
"Triggering alert_handler IRQ %d.", irq);
1826 CHECK_DIF_OK(dif_alert_handler_irq_force(&alert_handler, irq,
true));
1831 LOG_INFO(
"IRQ %d from alert_handler is serviced.", irq);
1835 #if TEST_MIN_IRQ_PERIPHERAL <= 2 && 2 < TEST_MAX_IRQ_PERIPHERAL
1843 for (dif_aon_timer_irq_t irq = kDifAonTimerIrqWkupTimerExpired; irq <= kDifAonTimerIrqWdogTimerBark;
1845 aon_timer_irq_expected = irq;
1846 LOG_INFO(
"Triggering aon_timer_aon IRQ %d.", irq);
1847 CHECK_DIF_OK(dif_aon_timer_irq_force(&aon_timer_aon, irq,
true));
1852 LOG_INFO(
"IRQ %d from aon_timer_aon is serviced.", irq);
1857 #if TEST_MIN_IRQ_PERIPHERAL <= 3 && 3 < TEST_MAX_IRQ_PERIPHERAL
1859 for (dif_csrng_irq_t irq = kDifCsrngIrqCsCmdReqDone; irq <= kDifCsrngIrqCsFatalErr;
1861 csrng_irq_expected = irq;
1862 LOG_INFO(
"Triggering csrng IRQ %d.", irq);
1863 CHECK_DIF_OK(dif_csrng_irq_force(&csrng, irq,
true));
1868 LOG_INFO(
"IRQ %d from csrng is serviced.", irq);
1872 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1874 for (dif_edn_irq_t irq = kDifEdnIrqEdnCmdReqDone; irq <= kDifEdnIrqEdnFatalErr;
1876 edn_irq_expected = irq;
1877 LOG_INFO(
"Triggering edn0 IRQ %d.", irq);
1878 CHECK_DIF_OK(dif_edn_irq_force(&edn0, irq,
true));
1883 LOG_INFO(
"IRQ %d from edn0 is serviced.", irq);
1887 #if TEST_MIN_IRQ_PERIPHERAL <= 4 && 4 < TEST_MAX_IRQ_PERIPHERAL
1889 for (dif_edn_irq_t irq = kDifEdnIrqEdnCmdReqDone; irq <= kDifEdnIrqEdnFatalErr;
1891 edn_irq_expected = irq;
1892 LOG_INFO(
"Triggering edn1 IRQ %d.", irq);
1893 CHECK_DIF_OK(dif_edn_irq_force(&edn1, irq,
true));
1898 LOG_INFO(
"IRQ %d from edn1 is serviced.", irq);
1902 #if TEST_MIN_IRQ_PERIPHERAL <= 5 && 5 < TEST_MAX_IRQ_PERIPHERAL
1904 for (dif_entropy_src_irq_t irq = kDifEntropySrcIrqEsEntropyValid; irq <= kDifEntropySrcIrqEsFatalErr;
1906 entropy_src_irq_expected = irq;
1907 LOG_INFO(
"Triggering entropy_src IRQ %d.", irq);
1908 CHECK_DIF_OK(dif_entropy_src_irq_force(&entropy_src, irq,
true));
1913 LOG_INFO(
"IRQ %d from entropy_src is serviced.", irq);
1917 #if TEST_MIN_IRQ_PERIPHERAL <= 6 && 6 < TEST_MAX_IRQ_PERIPHERAL
1919 status_default_mask = 0x3;
1920 for (dif_flash_ctrl_irq_t irq = kDifFlashCtrlIrqProgEmpty; irq <= kDifFlashCtrlIrqCorrErr;
1922 flash_ctrl_irq_expected = irq;
1923 LOG_INFO(
"Triggering flash_ctrl IRQ %d.", irq);
1924 CHECK_DIF_OK(dif_flash_ctrl_irq_force(&flash_ctrl, irq,
true));
1929 if ((status_default_mask & 0x1)) {
1930 CHECK_DIF_OK(dif_flash_ctrl_irq_set_enabled(&flash_ctrl, irq,
true));
1932 status_default_mask >>= 1;
1937 LOG_INFO(
"IRQ %d from flash_ctrl is serviced.", irq);
1941 #if TEST_MIN_IRQ_PERIPHERAL <= 7 && 7 < TEST_MAX_IRQ_PERIPHERAL
1943 for (dif_gpio_irq_t irq = kDifGpioIrqGpio0; irq <= kDifGpioIrqGpio31;
1945 gpio_irq_expected = irq;
1946 LOG_INFO(
"Triggering gpio IRQ %d.", irq);
1947 CHECK_DIF_OK(dif_gpio_irq_force(&gpio, irq,
true));
1952 LOG_INFO(
"IRQ %d from gpio is serviced.", irq);
1956 #if TEST_MIN_IRQ_PERIPHERAL <= 8 && 8 < TEST_MAX_IRQ_PERIPHERAL
1958 status_default_mask = 0x0;
1959 for (dif_hmac_irq_t irq = kDifHmacIrqHmacDone; irq <= kDifHmacIrqHmacErr;
1961 hmac_irq_expected = irq;
1962 LOG_INFO(
"Triggering hmac IRQ %d.", irq);
1963 CHECK_DIF_OK(dif_hmac_irq_force(&hmac, irq,
true));
1968 if ((status_default_mask & 0x1)) {
1969 CHECK_DIF_OK(dif_hmac_irq_set_enabled(&hmac, irq,
true));
1971 status_default_mask >>= 1;
1976 LOG_INFO(
"IRQ %d from hmac is serviced.", irq);
1980 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
1982 status_default_mask = 0x0;
1983 for (dif_i2c_irq_t irq = kDifI2cIrqFmtThreshold; irq <= kDifI2cIrqHostTimeout;
1985 i2c_irq_expected = irq;
1986 LOG_INFO(
"Triggering i2c0 IRQ %d.", irq);
1987 CHECK_DIF_OK(dif_i2c_irq_force(&i2c0, irq,
true));
1992 if ((status_default_mask & 0x1)) {
1993 CHECK_DIF_OK(dif_i2c_irq_set_enabled(&i2c0, irq,
true));
1995 status_default_mask >>= 1;
2000 LOG_INFO(
"IRQ %d from i2c0 is serviced.", irq);
2004 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
2006 status_default_mask = 0x0;
2007 for (dif_i2c_irq_t irq = kDifI2cIrqFmtThreshold; irq <= kDifI2cIrqHostTimeout;
2009 i2c_irq_expected = irq;
2010 LOG_INFO(
"Triggering i2c1 IRQ %d.", irq);
2011 CHECK_DIF_OK(dif_i2c_irq_force(&i2c1, irq,
true));
2016 if ((status_default_mask & 0x1)) {
2017 CHECK_DIF_OK(dif_i2c_irq_set_enabled(&i2c1, irq,
true));
2019 status_default_mask >>= 1;
2024 LOG_INFO(
"IRQ %d from i2c1 is serviced.", irq);
2028 #if TEST_MIN_IRQ_PERIPHERAL <= 9 && 9 < TEST_MAX_IRQ_PERIPHERAL
2030 status_default_mask = 0x0;
2031 for (dif_i2c_irq_t irq = kDifI2cIrqFmtThreshold; irq <= kDifI2cIrqHostTimeout;
2033 i2c_irq_expected = irq;
2034 LOG_INFO(
"Triggering i2c2 IRQ %d.", irq);
2035 CHECK_DIF_OK(dif_i2c_irq_force(&i2c2, irq,
true));
2040 if ((status_default_mask & 0x1)) {
2041 CHECK_DIF_OK(dif_i2c_irq_set_enabled(&i2c2, irq,
true));
2043 status_default_mask >>= 1;
2048 LOG_INFO(
"IRQ %d from i2c2 is serviced.", irq);
2052 #if TEST_MIN_IRQ_PERIPHERAL <= 10 && 10 < TEST_MAX_IRQ_PERIPHERAL
2054 for (dif_keymgr_irq_t irq = kDifKeymgrIrqOpDone; irq <= kDifKeymgrIrqOpDone;
2056 keymgr_irq_expected = irq;
2057 LOG_INFO(
"Triggering keymgr IRQ %d.", irq);
2058 CHECK_DIF_OK(dif_keymgr_irq_force(&keymgr, irq,
true));
2063 LOG_INFO(
"IRQ %d from keymgr is serviced.", irq);
2067 #if TEST_MIN_IRQ_PERIPHERAL <= 11 && 11 < TEST_MAX_IRQ_PERIPHERAL
2069 status_default_mask = 0x0;
2070 for (dif_kmac_irq_t irq = kDifKmacIrqKmacDone; irq <= kDifKmacIrqKmacErr;
2072 kmac_irq_expected = irq;
2073 LOG_INFO(
"Triggering kmac IRQ %d.", irq);
2074 CHECK_DIF_OK(dif_kmac_irq_force(&kmac, irq,
true));
2079 if ((status_default_mask & 0x1)) {
2080 CHECK_DIF_OK(dif_kmac_irq_set_enabled(&kmac, irq,
true));
2082 status_default_mask >>= 1;
2087 LOG_INFO(
"IRQ %d from kmac is serviced.", irq);
2091 #if TEST_MIN_IRQ_PERIPHERAL <= 12 && 12 < TEST_MAX_IRQ_PERIPHERAL
2093 for (dif_otbn_irq_t irq = kDifOtbnIrqDone; irq <= kDifOtbnIrqDone;
2095 otbn_irq_expected = irq;
2096 LOG_INFO(
"Triggering otbn IRQ %d.", irq);
2097 CHECK_DIF_OK(dif_otbn_irq_force(&otbn, irq,
true));
2102 LOG_INFO(
"IRQ %d from otbn is serviced.", irq);
2106 #if TEST_MIN_IRQ_PERIPHERAL <= 13 && 13 < TEST_MAX_IRQ_PERIPHERAL
2111 for (dif_otp_ctrl_irq_t irq = kDifOtpCtrlIrqOtpOperationDone; irq <= kDifOtpCtrlIrqOtpError;
2113 otp_ctrl_irq_expected = irq;
2114 LOG_INFO(
"Triggering otp_ctrl IRQ %d.", irq);
2115 CHECK_DIF_OK(dif_otp_ctrl_irq_force(&otp_ctrl, irq,
true));
2120 LOG_INFO(
"IRQ %d from otp_ctrl is serviced.", irq);
2125 #if TEST_MIN_IRQ_PERIPHERAL <= 14 && 14 < TEST_MAX_IRQ_PERIPHERAL
2127 for (dif_pattgen_irq_t irq = kDifPattgenIrqDoneCh0; irq <= kDifPattgenIrqDoneCh1;
2129 pattgen_irq_expected = irq;
2130 LOG_INFO(
"Triggering pattgen IRQ %d.", irq);
2131 CHECK_DIF_OK(dif_pattgen_irq_force(&pattgen, irq,
true));
2136 LOG_INFO(
"IRQ %d from pattgen is serviced.", irq);
2140 #if TEST_MIN_IRQ_PERIPHERAL <= 15 && 15 < TEST_MAX_IRQ_PERIPHERAL
2142 for (dif_pwrmgr_irq_t irq = kDifPwrmgrIrqWakeup; irq <= kDifPwrmgrIrqWakeup;
2144 pwrmgr_irq_expected = irq;
2145 LOG_INFO(
"Triggering pwrmgr_aon IRQ %d.", irq);
2146 CHECK_DIF_OK(dif_pwrmgr_irq_force(&pwrmgr_aon, irq,
true));
2151 LOG_INFO(
"IRQ %d from pwrmgr_aon is serviced.", irq);
2155 #if TEST_MIN_IRQ_PERIPHERAL <= 16 && 16 < TEST_MAX_IRQ_PERIPHERAL
2157 for (dif_rv_timer_irq_t irq = kDifRvTimerIrqTimerExpiredHart0Timer0; irq <= kDifRvTimerIrqTimerExpiredHart0Timer0;
2159 rv_timer_irq_expected = irq;
2160 LOG_INFO(
"Triggering rv_timer IRQ %d.", irq);
2161 CHECK_DIF_OK(dif_rv_timer_irq_force(&rv_timer, irq,
true));
2166 LOG_INFO(
"IRQ %d from rv_timer is serviced.", irq);
2170 #if TEST_MIN_IRQ_PERIPHERAL <= 17 && 17 < TEST_MAX_IRQ_PERIPHERAL
2172 for (dif_sensor_ctrl_irq_t irq = kDifSensorCtrlIrqIoStatusChange; irq <= kDifSensorCtrlIrqInitStatusChange;
2174 sensor_ctrl_irq_expected = irq;
2175 LOG_INFO(
"Triggering sensor_ctrl_aon IRQ %d.", irq);
2176 CHECK_DIF_OK(dif_sensor_ctrl_irq_force(&sensor_ctrl_aon, irq,
true));
2181 LOG_INFO(
"IRQ %d from sensor_ctrl_aon is serviced.", irq);
2185 #if TEST_MIN_IRQ_PERIPHERAL <= 18 && 18 < TEST_MAX_IRQ_PERIPHERAL
2187 status_default_mask = 0x0;
2188 for (dif_spi_device_irq_t irq = kDifSpiDeviceIrqUploadCmdfifoNotEmpty; irq <= kDifSpiDeviceIrqTpmRdfifoDrop;
2190 spi_device_irq_expected = irq;
2191 LOG_INFO(
"Triggering spi_device IRQ %d.", irq);
2192 CHECK_DIF_OK(dif_spi_device_irq_force(&spi_device, irq,
true));
2197 if ((status_default_mask & 0x1)) {
2198 CHECK_DIF_OK(dif_spi_device_irq_set_enabled(&spi_device, irq,
true));
2200 status_default_mask >>= 1;
2205 LOG_INFO(
"IRQ %d from spi_device is serviced.", irq);
2209 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
2211 status_default_mask = 0x0;
2212 for (dif_spi_host_irq_t irq = kDifSpiHostIrqError; irq <= kDifSpiHostIrqSpiEvent;
2214 spi_host_irq_expected = irq;
2215 LOG_INFO(
"Triggering spi_host0 IRQ %d.", irq);
2216 CHECK_DIF_OK(dif_spi_host_irq_force(&spi_host0, irq,
true));
2221 if ((status_default_mask & 0x1)) {
2222 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(&spi_host0, irq,
true));
2224 status_default_mask >>= 1;
2229 LOG_INFO(
"IRQ %d from spi_host0 is serviced.", irq);
2233 #if TEST_MIN_IRQ_PERIPHERAL <= 19 && 19 < TEST_MAX_IRQ_PERIPHERAL
2235 status_default_mask = 0x0;
2236 for (dif_spi_host_irq_t irq = kDifSpiHostIrqError; irq <= kDifSpiHostIrqSpiEvent;
2238 spi_host_irq_expected = irq;
2239 LOG_INFO(
"Triggering spi_host1 IRQ %d.", irq);
2240 CHECK_DIF_OK(dif_spi_host_irq_force(&spi_host1, irq,
true));
2245 if ((status_default_mask & 0x1)) {
2246 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(&spi_host1, irq,
true));
2248 status_default_mask >>= 1;
2253 LOG_INFO(
"IRQ %d from spi_host1 is serviced.", irq);
2257 #if TEST_MIN_IRQ_PERIPHERAL <= 20 && 20 < TEST_MAX_IRQ_PERIPHERAL
2259 status_default_mask = 0x0;
2260 for (dif_sysrst_ctrl_irq_t irq = kDifSysrstCtrlIrqEventDetected; irq <= kDifSysrstCtrlIrqEventDetected;
2262 sysrst_ctrl_irq_expected = irq;
2263 LOG_INFO(
"Triggering sysrst_ctrl_aon IRQ %d.", irq);
2264 CHECK_DIF_OK(dif_sysrst_ctrl_irq_force(&sysrst_ctrl_aon, irq,
true));
2269 if ((status_default_mask & 0x1)) {
2270 CHECK_DIF_OK(dif_sysrst_ctrl_irq_set_enabled(&sysrst_ctrl_aon, irq,
true));
2272 status_default_mask >>= 1;
2277 LOG_INFO(
"IRQ %d from sysrst_ctrl_aon is serviced.", irq);
2281 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
2289 status_default_mask = 0x101;
2290 for (dif_uart_irq_t irq = kDifUartIrqTxWatermark; irq <= kDifUartIrqTxEmpty;
2292 uart_irq_expected = irq;
2293 LOG_INFO(
"Triggering uart0 IRQ %d.", irq);
2294 CHECK_DIF_OK(dif_uart_irq_force(&uart0, irq,
true));
2299 if ((status_default_mask & 0x1)) {
2300 CHECK_DIF_OK(dif_uart_irq_set_enabled(&uart0, irq,
true));
2302 status_default_mask >>= 1;
2307 LOG_INFO(
"IRQ %d from uart0 is serviced.", irq);
2312 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
2314 status_default_mask = 0x101;
2315 for (dif_uart_irq_t irq = kDifUartIrqTxWatermark; irq <= kDifUartIrqTxEmpty;
2317 uart_irq_expected = irq;
2318 LOG_INFO(
"Triggering uart1 IRQ %d.", irq);
2319 CHECK_DIF_OK(dif_uart_irq_force(&uart1, irq,
true));
2324 if ((status_default_mask & 0x1)) {
2325 CHECK_DIF_OK(dif_uart_irq_set_enabled(&uart1, irq,
true));
2327 status_default_mask >>= 1;
2332 LOG_INFO(
"IRQ %d from uart1 is serviced.", irq);
2336 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
2338 status_default_mask = 0x101;
2339 for (dif_uart_irq_t irq = kDifUartIrqTxWatermark; irq <= kDifUartIrqTxEmpty;
2341 uart_irq_expected = irq;
2342 LOG_INFO(
"Triggering uart2 IRQ %d.", irq);
2343 CHECK_DIF_OK(dif_uart_irq_force(&uart2, irq,
true));
2348 if ((status_default_mask & 0x1)) {
2349 CHECK_DIF_OK(dif_uart_irq_set_enabled(&uart2, irq,
true));
2351 status_default_mask >>= 1;
2356 LOG_INFO(
"IRQ %d from uart2 is serviced.", irq);
2360 #if TEST_MIN_IRQ_PERIPHERAL <= 21 && 21 < TEST_MAX_IRQ_PERIPHERAL
2362 status_default_mask = 0x101;
2363 for (dif_uart_irq_t irq = kDifUartIrqTxWatermark; irq <= kDifUartIrqTxEmpty;
2365 uart_irq_expected = irq;
2366 LOG_INFO(
"Triggering uart3 IRQ %d.", irq);
2367 CHECK_DIF_OK(dif_uart_irq_force(&uart3, irq,
true));
2372 if ((status_default_mask & 0x1)) {
2373 CHECK_DIF_OK(dif_uart_irq_set_enabled(&uart3, irq,
true));
2375 status_default_mask >>= 1;
2380 LOG_INFO(
"IRQ %d from uart3 is serviced.", irq);
2384 #if TEST_MIN_IRQ_PERIPHERAL <= 22 && 22 < TEST_MAX_IRQ_PERIPHERAL
2386 status_default_mask = 0x0;
2387 for (dif_usbdev_irq_t irq = kDifUsbdevIrqPktReceived; irq <= kDifUsbdevIrqAvSetupEmpty;
2389 usbdev_irq_expected = irq;
2390 LOG_INFO(
"Triggering usbdev IRQ %d.", irq);
2391 CHECK_DIF_OK(dif_usbdev_irq_force(&usbdev, irq,
true));
2396 if ((status_default_mask & 0x1)) {
2397 CHECK_DIF_OK(dif_usbdev_irq_set_enabled(&usbdev, irq,
true));
2399 status_default_mask >>= 1;
2404 LOG_INFO(
"IRQ %d from usbdev is serviced.", irq);
2414 static void check_hart_id(uint32_t exp_hart_id) {
2415 uint32_t act_hart_id;
2416 CSR_READ(CSR_REG_MHARTID, &act_hart_id);
2417 CHECK(act_hart_id == exp_hart_id,
"Processor has unexpected HART ID.");
2420 OTTF_DEFINE_TEST_CONFIG();
2423 irq_global_ctrl(
true);
2424 irq_external_ctrl(
true);
2426 check_hart_id((uint32_t)kHart);
2427 rv_plic_testutils_irq_range_enable(
2429 peripheral_irqs_clear();
2430 peripheral_irqs_enable();
2431 peripheral_irqs_trigger();