Pavona Software APIs
isr_testutils.c
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
6// util/autogen_testutils.py
7
8#include "sw/device/lib/testing/autogen/isr_testutils.h"
10
13#include "sw/device/lib/testing/test_framework/check.h"
14
15void isr_testutils_acc_isr(plic_isr_ctx_t plic_ctx, acc_isr_ctx_t acc_ctx,
16 top_egret_plic_peripheral_t *peripheral_serviced,
17 dif_acc_irq_t *irq_serviced) {
18
19 // Claim the IRQ at the PLIC.
20 dif_rv_plic_irq_id_t plic_irq_id;
21 CHECK_DIF_OK(
22 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
23
24 // Get the peripheral the IRQ belongs to.
25 *peripheral_serviced = (top_egret_plic_peripheral_t)
26 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
27
28 // Get the IRQ that was fired from the PLIC IRQ ID.
29 dif_acc_irq_t irq =
30 (dif_acc_irq_t)(plic_irq_id - acc_ctx.plic_acc_start_irq_id);
31 *irq_serviced = irq;
32
33 // Check if it is supposed to be the only IRQ fired.
34 if (acc_ctx.is_only_irq) {
36 CHECK_DIF_OK(dif_acc_irq_get_state(acc_ctx.acc, &snapshot));
37 CHECK(snapshot == (dif_acc_irq_state_snapshot_t)(1 << irq),
38 "Only acc IRQ %d expected to fire. Actual IRQ state = %x", irq,
39 snapshot);
40 }
41
42 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
43 dif_irq_type_t type;
44 CHECK_DIF_OK(dif_acc_irq_get_type(acc_ctx.acc, irq, &type));
45 if (type == kDifIrqTypeEvent) {
46 CHECK_DIF_OK(dif_acc_irq_acknowledge(acc_ctx.acc, irq));
47 }
48
49 // Complete the IRQ at the PLIC.
50 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
51 plic_irq_id));
52}
53
54void isr_testutils_adc_ctrl_isr(
55 plic_isr_ctx_t plic_ctx, adc_ctrl_isr_ctx_t adc_ctrl_ctx,
56 bool mute_status_irq, top_egret_plic_peripheral_t *peripheral_serviced,
57 dif_adc_ctrl_irq_t *irq_serviced) {
58
59 // Claim the IRQ at the PLIC.
60 dif_rv_plic_irq_id_t plic_irq_id;
61 CHECK_DIF_OK(
62 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
63
64 // Get the peripheral the IRQ belongs to.
65 *peripheral_serviced = (top_egret_plic_peripheral_t)
66 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
67
68 // Get the IRQ that was fired from the PLIC IRQ ID.
69 dif_adc_ctrl_irq_t irq =
70 (dif_adc_ctrl_irq_t)(plic_irq_id -
71 adc_ctrl_ctx.plic_adc_ctrl_start_irq_id);
72 *irq_serviced = irq;
73
74 // Check if it is supposed to be the only IRQ fired.
75 if (adc_ctrl_ctx.is_only_irq) {
77 CHECK_DIF_OK(dif_adc_ctrl_irq_get_state(adc_ctrl_ctx.adc_ctrl, &snapshot));
78 CHECK(snapshot == (dif_adc_ctrl_irq_state_snapshot_t)(1 << irq),
79 "Only adc_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
80 snapshot);
81 }
82
83 // TODO(lowRISC/opentitan:#11354): future releases of the ADC Controller HW
84 // should hide the need to also clear the cause CSRs. At which point, this can
85 // be removed.
86 CHECK_DIF_OK(dif_adc_ctrl_irq_clear_causes(adc_ctrl_ctx.adc_ctrl,
88
89 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
90 dif_irq_type_t type;
91 CHECK_DIF_OK(dif_adc_ctrl_irq_get_type(adc_ctrl_ctx.adc_ctrl, irq, &type));
92 if (type == kDifIrqTypeEvent) {
93 CHECK_DIF_OK(dif_adc_ctrl_irq_acknowledge(adc_ctrl_ctx.adc_ctrl, irq));
94 } else if (mute_status_irq) {
95 CHECK_DIF_OK(dif_adc_ctrl_irq_set_enabled(adc_ctrl_ctx.adc_ctrl, irq,
97 }
98
99 // Complete the IRQ at the PLIC.
100 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
101 plic_irq_id));
102}
103
104void isr_testutils_alert_handler_isr(
105 plic_isr_ctx_t plic_ctx, alert_handler_isr_ctx_t alert_handler_ctx,
106 top_egret_plic_peripheral_t *peripheral_serviced,
107 dif_alert_handler_irq_t *irq_serviced) {
108
109 // Claim the IRQ at the PLIC.
110 dif_rv_plic_irq_id_t plic_irq_id;
111 CHECK_DIF_OK(
112 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
113
114 // Get the peripheral the IRQ belongs to.
115 *peripheral_serviced = (top_egret_plic_peripheral_t)
116 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
117
118 // Get the IRQ that was fired from the PLIC IRQ ID.
119 dif_alert_handler_irq_t irq =
120 (dif_alert_handler_irq_t)(plic_irq_id -
121 alert_handler_ctx
122 .plic_alert_handler_start_irq_id);
123 *irq_serviced = irq;
124
125 // Check if it is supposed to be the only IRQ fired.
126 if (alert_handler_ctx.is_only_irq) {
128 CHECK_DIF_OK(dif_alert_handler_irq_get_state(
129 alert_handler_ctx.alert_handler, &snapshot));
130 CHECK(snapshot == (dif_alert_handler_irq_state_snapshot_t)(1 << irq),
131 "Only alert_handler IRQ %d expected to fire. Actual IRQ state = %x",
132 irq, snapshot);
133 }
134
135 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
136 dif_irq_type_t type;
137 CHECK_DIF_OK(dif_alert_handler_irq_get_type(alert_handler_ctx.alert_handler,
138 irq, &type));
139 if (type == kDifIrqTypeEvent) {
140 CHECK_DIF_OK(dif_alert_handler_irq_acknowledge(
141 alert_handler_ctx.alert_handler, irq));
142 }
143
144 // Complete the IRQ at the PLIC.
145 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
146 plic_irq_id));
147}
148
149void isr_testutils_aon_timer_isr(
150 plic_isr_ctx_t plic_ctx, aon_timer_isr_ctx_t aon_timer_ctx,
151 top_egret_plic_peripheral_t *peripheral_serviced,
152 dif_aon_timer_irq_t *irq_serviced) {
153
154 // Claim the IRQ at the PLIC.
155 dif_rv_plic_irq_id_t plic_irq_id;
156 CHECK_DIF_OK(
157 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
158
159 // Get the peripheral the IRQ belongs to.
160 *peripheral_serviced = (top_egret_plic_peripheral_t)
161 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
162
163 // Get the IRQ that was fired from the PLIC IRQ ID.
164 dif_aon_timer_irq_t irq =
165 (dif_aon_timer_irq_t)(plic_irq_id -
166 aon_timer_ctx.plic_aon_timer_start_irq_id);
167 *irq_serviced = irq;
168
169 // Check if it is supposed to be the only IRQ fired.
170 if (aon_timer_ctx.is_only_irq) {
172 CHECK_DIF_OK(
173 dif_aon_timer_irq_get_state(aon_timer_ctx.aon_timer, &snapshot));
174 CHECK(snapshot == (dif_aon_timer_irq_state_snapshot_t)(1 << irq),
175 "Only aon_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
176 snapshot);
177 }
178
179 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
180 dif_irq_type_t type;
181 CHECK_DIF_OK(dif_aon_timer_irq_get_type(aon_timer_ctx.aon_timer, irq, &type));
182 if (type == kDifIrqTypeEvent) {
183 CHECK_DIF_OK(dif_aon_timer_irq_acknowledge(aon_timer_ctx.aon_timer, irq));
184 }
185
186 // Complete the IRQ at the PLIC.
187 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
188 plic_irq_id));
189}
190
191void isr_testutils_csrng_isr(plic_isr_ctx_t plic_ctx, csrng_isr_ctx_t csrng_ctx,
192 top_egret_plic_peripheral_t *peripheral_serviced,
193 dif_csrng_irq_t *irq_serviced) {
194
195 // Claim the IRQ at the PLIC.
196 dif_rv_plic_irq_id_t plic_irq_id;
197 CHECK_DIF_OK(
198 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
199
200 // Get the peripheral the IRQ belongs to.
201 *peripheral_serviced = (top_egret_plic_peripheral_t)
202 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
203
204 // Get the IRQ that was fired from the PLIC IRQ ID.
205 dif_csrng_irq_t irq =
206 (dif_csrng_irq_t)(plic_irq_id - csrng_ctx.plic_csrng_start_irq_id);
207 *irq_serviced = irq;
208
209 // Check if it is supposed to be the only IRQ fired.
210 if (csrng_ctx.is_only_irq) {
212 CHECK_DIF_OK(dif_csrng_irq_get_state(csrng_ctx.csrng, &snapshot));
213 CHECK(snapshot == (dif_csrng_irq_state_snapshot_t)(1 << irq),
214 "Only csrng IRQ %d expected to fire. Actual IRQ state = %x", irq,
215 snapshot);
216 }
217
218 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
219 dif_irq_type_t type;
220 CHECK_DIF_OK(dif_csrng_irq_get_type(csrng_ctx.csrng, irq, &type));
221 if (type == kDifIrqTypeEvent) {
222 CHECK_DIF_OK(dif_csrng_irq_acknowledge(csrng_ctx.csrng, irq));
223 }
224
225 // Complete the IRQ at the PLIC.
226 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
227 plic_irq_id));
228}
229
230void isr_testutils_edn_isr(plic_isr_ctx_t plic_ctx, edn_isr_ctx_t edn_ctx,
231 top_egret_plic_peripheral_t *peripheral_serviced,
232 dif_edn_irq_t *irq_serviced) {
233
234 // Claim the IRQ at the PLIC.
235 dif_rv_plic_irq_id_t plic_irq_id;
236 CHECK_DIF_OK(
237 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
238
239 // Get the peripheral the IRQ belongs to.
240 *peripheral_serviced = (top_egret_plic_peripheral_t)
241 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
242
243 // Get the IRQ that was fired from the PLIC IRQ ID.
244 dif_edn_irq_t irq =
245 (dif_edn_irq_t)(plic_irq_id - edn_ctx.plic_edn_start_irq_id);
246 *irq_serviced = irq;
247
248 // Check if it is supposed to be the only IRQ fired.
249 if (edn_ctx.is_only_irq) {
251 CHECK_DIF_OK(dif_edn_irq_get_state(edn_ctx.edn, &snapshot));
252 CHECK(snapshot == (dif_edn_irq_state_snapshot_t)(1 << irq),
253 "Only edn IRQ %d expected to fire. Actual IRQ state = %x", irq,
254 snapshot);
255 }
256
257 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
258 dif_irq_type_t type;
259 CHECK_DIF_OK(dif_edn_irq_get_type(edn_ctx.edn, irq, &type));
260 if (type == kDifIrqTypeEvent) {
261 CHECK_DIF_OK(dif_edn_irq_acknowledge(edn_ctx.edn, irq));
262 }
263
264 // Complete the IRQ at the PLIC.
265 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
266 plic_irq_id));
267}
268
269void isr_testutils_entropy_src_isr(
270 plic_isr_ctx_t plic_ctx, entropy_src_isr_ctx_t entropy_src_ctx,
271 top_egret_plic_peripheral_t *peripheral_serviced,
272 dif_entropy_src_irq_t *irq_serviced) {
273
274 // Claim the IRQ at the PLIC.
275 dif_rv_plic_irq_id_t plic_irq_id;
276 CHECK_DIF_OK(
277 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
278
279 // Get the peripheral the IRQ belongs to.
280 *peripheral_serviced = (top_egret_plic_peripheral_t)
281 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
282
283 // Get the IRQ that was fired from the PLIC IRQ ID.
284 dif_entropy_src_irq_t irq =
285 (dif_entropy_src_irq_t)(plic_irq_id -
286 entropy_src_ctx.plic_entropy_src_start_irq_id);
287 *irq_serviced = irq;
288
289 // Check if it is supposed to be the only IRQ fired.
290 if (entropy_src_ctx.is_only_irq) {
292 CHECK_DIF_OK(
293 dif_entropy_src_irq_get_state(entropy_src_ctx.entropy_src, &snapshot));
294 CHECK(snapshot == (dif_entropy_src_irq_state_snapshot_t)(1 << irq),
295 "Only entropy_src IRQ %d expected to fire. Actual IRQ state = %x",
296 irq, snapshot);
297 }
298
299 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
300 dif_irq_type_t type;
301 CHECK_DIF_OK(
302 dif_entropy_src_irq_get_type(entropy_src_ctx.entropy_src, irq, &type));
303 if (type == kDifIrqTypeEvent) {
304 CHECK_DIF_OK(
305 dif_entropy_src_irq_acknowledge(entropy_src_ctx.entropy_src, irq));
306 }
307
308 // Complete the IRQ at the PLIC.
309 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
310 plic_irq_id));
311}
312
313void isr_testutils_flash_ctrl_isr(
314 plic_isr_ctx_t plic_ctx, flash_ctrl_isr_ctx_t flash_ctrl_ctx,
315 bool mute_status_irq, top_egret_plic_peripheral_t *peripheral_serviced,
316 dif_flash_ctrl_irq_t *irq_serviced) {
317
318 // Claim the IRQ at the PLIC.
319 dif_rv_plic_irq_id_t plic_irq_id;
320 CHECK_DIF_OK(
321 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
322
323 // Get the peripheral the IRQ belongs to.
324 *peripheral_serviced = (top_egret_plic_peripheral_t)
325 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
326
327 // Get the IRQ that was fired from the PLIC IRQ ID.
328 dif_flash_ctrl_irq_t irq =
329 (dif_flash_ctrl_irq_t)(plic_irq_id -
330 flash_ctrl_ctx.plic_flash_ctrl_start_irq_id);
331 *irq_serviced = irq;
332
333 // Check if it is supposed to be the only IRQ fired.
334 if (flash_ctrl_ctx.is_only_irq) {
336 CHECK_DIF_OK(
337 dif_flash_ctrl_irq_get_state(flash_ctrl_ctx.flash_ctrl, &snapshot));
338 CHECK(snapshot == (dif_flash_ctrl_irq_state_snapshot_t)(1 << irq),
339 "Only flash_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
340 snapshot);
341 }
342
343 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
344 dif_irq_type_t type;
345 CHECK_DIF_OK(
346 dif_flash_ctrl_irq_get_type(flash_ctrl_ctx.flash_ctrl, irq, &type));
347 if (type == kDifIrqTypeEvent) {
348 CHECK_DIF_OK(
349 dif_flash_ctrl_irq_acknowledge(flash_ctrl_ctx.flash_ctrl, irq));
350 } else if (mute_status_irq) {
351 CHECK_DIF_OK(dif_flash_ctrl_irq_set_enabled(flash_ctrl_ctx.flash_ctrl, irq,
353 }
354
355 // Complete the IRQ at the PLIC.
356 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
357 plic_irq_id));
358}
359
360void isr_testutils_gpio_isr(plic_isr_ctx_t plic_ctx, gpio_isr_ctx_t gpio_ctx,
361 top_egret_plic_peripheral_t *peripheral_serviced,
362 dif_gpio_irq_t *irq_serviced) {
363
364 // Claim the IRQ at the PLIC.
365 dif_rv_plic_irq_id_t plic_irq_id;
366 CHECK_DIF_OK(
367 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
368
369 // Get the peripheral the IRQ belongs to.
370 *peripheral_serviced = (top_egret_plic_peripheral_t)
371 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
372
373 // Get the IRQ that was fired from the PLIC IRQ ID.
374 dif_gpio_irq_t irq =
375 (dif_gpio_irq_t)(plic_irq_id - gpio_ctx.plic_gpio_start_irq_id);
376 *irq_serviced = irq;
377
378 // Check if it is supposed to be the only IRQ fired.
379 if (gpio_ctx.is_only_irq) {
381 CHECK_DIF_OK(dif_gpio_irq_get_state(gpio_ctx.gpio, &snapshot));
382 CHECK(snapshot == (dif_gpio_irq_state_snapshot_t)(1 << irq),
383 "Only gpio IRQ %d expected to fire. Actual IRQ state = %x", irq,
384 snapshot);
385 }
386
387 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
388 dif_irq_type_t type;
389 CHECK_DIF_OK(dif_gpio_irq_get_type(gpio_ctx.gpio, irq, &type));
390 if (type == kDifIrqTypeEvent) {
391 CHECK_DIF_OK(dif_gpio_irq_acknowledge(gpio_ctx.gpio, irq));
392 }
393
394 // Complete the IRQ at the PLIC.
395 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
396 plic_irq_id));
397}
398
399void isr_testutils_hmac_isr(plic_isr_ctx_t plic_ctx, hmac_isr_ctx_t hmac_ctx,
400 bool mute_status_irq,
401 top_egret_plic_peripheral_t *peripheral_serviced,
402 dif_hmac_irq_t *irq_serviced) {
403
404 // Claim the IRQ at the PLIC.
405 dif_rv_plic_irq_id_t plic_irq_id;
406 CHECK_DIF_OK(
407 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
408
409 // Get the peripheral the IRQ belongs to.
410 *peripheral_serviced = (top_egret_plic_peripheral_t)
411 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
412
413 // Get the IRQ that was fired from the PLIC IRQ ID.
414 dif_hmac_irq_t irq =
415 (dif_hmac_irq_t)(plic_irq_id - hmac_ctx.plic_hmac_start_irq_id);
416 *irq_serviced = irq;
417
418 // Check if it is supposed to be the only IRQ fired.
419 if (hmac_ctx.is_only_irq) {
421 CHECK_DIF_OK(dif_hmac_irq_get_state(hmac_ctx.hmac, &snapshot));
422 CHECK(snapshot == (dif_hmac_irq_state_snapshot_t)(1 << irq),
423 "Only hmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
424 snapshot);
425 }
426
427 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
428 dif_irq_type_t type;
429 CHECK_DIF_OK(dif_hmac_irq_get_type(hmac_ctx.hmac, irq, &type));
430 if (type == kDifIrqTypeEvent) {
431 CHECK_DIF_OK(dif_hmac_irq_acknowledge(hmac_ctx.hmac, irq));
432 } else if (mute_status_irq) {
433 CHECK_DIF_OK(
434 dif_hmac_irq_set_enabled(hmac_ctx.hmac, irq, kDifToggleDisabled));
435 }
436
437 // Complete the IRQ at the PLIC.
438 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
439 plic_irq_id));
440}
441
442void isr_testutils_i2c_isr(plic_isr_ctx_t plic_ctx, i2c_isr_ctx_t i2c_ctx,
443 bool mute_status_irq,
444 top_egret_plic_peripheral_t *peripheral_serviced,
445 dif_i2c_irq_t *irq_serviced) {
446
447 // Claim the IRQ at the PLIC.
448 dif_rv_plic_irq_id_t plic_irq_id;
449 CHECK_DIF_OK(
450 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
451
452 // Get the peripheral the IRQ belongs to.
453 *peripheral_serviced = (top_egret_plic_peripheral_t)
454 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
455
456 // Get the IRQ that was fired from the PLIC IRQ ID.
457 dif_i2c_irq_t irq =
458 (dif_i2c_irq_t)(plic_irq_id - i2c_ctx.plic_i2c_start_irq_id);
459 *irq_serviced = irq;
460
461 // Check if it is supposed to be the only IRQ fired.
462 if (i2c_ctx.is_only_irq) {
464 CHECK_DIF_OK(dif_i2c_irq_get_state(i2c_ctx.i2c, &snapshot));
465 CHECK(snapshot == (dif_i2c_irq_state_snapshot_t)(1 << irq),
466 "Only i2c IRQ %d expected to fire. Actual IRQ state = %x", irq,
467 snapshot);
468 }
469
470 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
471 dif_irq_type_t type;
472 CHECK_DIF_OK(dif_i2c_irq_get_type(i2c_ctx.i2c, irq, &type));
473 if (type == kDifIrqTypeEvent) {
474 CHECK_DIF_OK(dif_i2c_irq_acknowledge(i2c_ctx.i2c, irq));
475 } else if (mute_status_irq) {
476 CHECK_DIF_OK(dif_i2c_irq_set_enabled(i2c_ctx.i2c, irq, kDifToggleDisabled));
477 }
478
479 // Complete the IRQ at the PLIC.
480 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
481 plic_irq_id));
482}
483
484void isr_testutils_keymgr_isr(plic_isr_ctx_t plic_ctx,
485 keymgr_isr_ctx_t keymgr_ctx,
486 top_egret_plic_peripheral_t *peripheral_serviced,
487 dif_keymgr_irq_t *irq_serviced) {
488
489 // Claim the IRQ at the PLIC.
490 dif_rv_plic_irq_id_t plic_irq_id;
491 CHECK_DIF_OK(
492 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
493
494 // Get the peripheral the IRQ belongs to.
495 *peripheral_serviced = (top_egret_plic_peripheral_t)
496 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
497
498 // Get the IRQ that was fired from the PLIC IRQ ID.
499 dif_keymgr_irq_t irq =
500 (dif_keymgr_irq_t)(plic_irq_id - keymgr_ctx.plic_keymgr_start_irq_id);
501 *irq_serviced = irq;
502
503 // Check if it is supposed to be the only IRQ fired.
504 if (keymgr_ctx.is_only_irq) {
506 CHECK_DIF_OK(dif_keymgr_irq_get_state(keymgr_ctx.keymgr, &snapshot));
507 CHECK(snapshot == (dif_keymgr_irq_state_snapshot_t)(1 << irq),
508 "Only keymgr IRQ %d expected to fire. Actual IRQ state = %x", irq,
509 snapshot);
510 }
511
512 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
513 dif_irq_type_t type;
514 CHECK_DIF_OK(dif_keymgr_irq_get_type(keymgr_ctx.keymgr, irq, &type));
515 if (type == kDifIrqTypeEvent) {
516 CHECK_DIF_OK(dif_keymgr_irq_acknowledge(keymgr_ctx.keymgr, irq));
517 }
518
519 // Complete the IRQ at the PLIC.
520 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
521 plic_irq_id));
522}
523
524void isr_testutils_kmac_isr(plic_isr_ctx_t plic_ctx, kmac_isr_ctx_t kmac_ctx,
525 bool mute_status_irq,
526 top_egret_plic_peripheral_t *peripheral_serviced,
527 dif_kmac_irq_t *irq_serviced) {
528
529 // Claim the IRQ at the PLIC.
530 dif_rv_plic_irq_id_t plic_irq_id;
531 CHECK_DIF_OK(
532 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
533
534 // Get the peripheral the IRQ belongs to.
535 *peripheral_serviced = (top_egret_plic_peripheral_t)
536 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
537
538 // Get the IRQ that was fired from the PLIC IRQ ID.
539 dif_kmac_irq_t irq =
540 (dif_kmac_irq_t)(plic_irq_id - kmac_ctx.plic_kmac_start_irq_id);
541 *irq_serviced = irq;
542
543 // Check if it is supposed to be the only IRQ fired.
544 if (kmac_ctx.is_only_irq) {
546 CHECK_DIF_OK(dif_kmac_irq_get_state(kmac_ctx.kmac, &snapshot));
547 CHECK(snapshot == (dif_kmac_irq_state_snapshot_t)(1 << irq),
548 "Only kmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
549 snapshot);
550 }
551
552 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
553 dif_irq_type_t type;
554 CHECK_DIF_OK(dif_kmac_irq_get_type(kmac_ctx.kmac, irq, &type));
555 if (type == kDifIrqTypeEvent) {
556 CHECK_DIF_OK(dif_kmac_irq_acknowledge(kmac_ctx.kmac, irq));
557 } else if (mute_status_irq) {
558 CHECK_DIF_OK(
559 dif_kmac_irq_set_enabled(kmac_ctx.kmac, irq, kDifToggleDisabled));
560 }
561
562 // Complete the IRQ at the PLIC.
563 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
564 plic_irq_id));
565}
566
567void isr_testutils_otp_ctrl_isr(
568 plic_isr_ctx_t plic_ctx, otp_ctrl_isr_ctx_t otp_ctrl_ctx,
569 top_egret_plic_peripheral_t *peripheral_serviced,
570 dif_otp_ctrl_irq_t *irq_serviced) {
571
572 // Claim the IRQ at the PLIC.
573 dif_rv_plic_irq_id_t plic_irq_id;
574 CHECK_DIF_OK(
575 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
576
577 // Get the peripheral the IRQ belongs to.
578 *peripheral_serviced = (top_egret_plic_peripheral_t)
579 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
580
581 // Get the IRQ that was fired from the PLIC IRQ ID.
582 dif_otp_ctrl_irq_t irq =
583 (dif_otp_ctrl_irq_t)(plic_irq_id -
584 otp_ctrl_ctx.plic_otp_ctrl_start_irq_id);
585 *irq_serviced = irq;
586
587 // Check if it is supposed to be the only IRQ fired.
588 if (otp_ctrl_ctx.is_only_irq) {
590 CHECK_DIF_OK(dif_otp_ctrl_irq_get_state(otp_ctrl_ctx.otp_ctrl, &snapshot));
591 CHECK(snapshot == (dif_otp_ctrl_irq_state_snapshot_t)(1 << irq),
592 "Only otp_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
593 snapshot);
594 }
595
596 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
597 dif_irq_type_t type;
598 CHECK_DIF_OK(dif_otp_ctrl_irq_get_type(otp_ctrl_ctx.otp_ctrl, irq, &type));
599 if (type == kDifIrqTypeEvent) {
600 CHECK_DIF_OK(dif_otp_ctrl_irq_acknowledge(otp_ctrl_ctx.otp_ctrl, irq));
601 }
602
603 // Complete the IRQ at the PLIC.
604 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
605 plic_irq_id));
606}
607
608void isr_testutils_pattgen_isr(plic_isr_ctx_t plic_ctx,
609 pattgen_isr_ctx_t pattgen_ctx,
610 top_egret_plic_peripheral_t *peripheral_serviced,
611 dif_pattgen_irq_t *irq_serviced) {
612
613 // Claim the IRQ at the PLIC.
614 dif_rv_plic_irq_id_t plic_irq_id;
615 CHECK_DIF_OK(
616 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
617
618 // Get the peripheral the IRQ belongs to.
619 *peripheral_serviced = (top_egret_plic_peripheral_t)
620 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
621
622 // Get the IRQ that was fired from the PLIC IRQ ID.
623 dif_pattgen_irq_t irq =
624 (dif_pattgen_irq_t)(plic_irq_id - pattgen_ctx.plic_pattgen_start_irq_id);
625 *irq_serviced = irq;
626
627 // Check if it is supposed to be the only IRQ fired.
628 if (pattgen_ctx.is_only_irq) {
630 CHECK_DIF_OK(dif_pattgen_irq_get_state(pattgen_ctx.pattgen, &snapshot));
631 CHECK(snapshot == (dif_pattgen_irq_state_snapshot_t)(1 << irq),
632 "Only pattgen IRQ %d expected to fire. Actual IRQ state = %x", irq,
633 snapshot);
634 }
635
636 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
637 dif_irq_type_t type;
638 CHECK_DIF_OK(dif_pattgen_irq_get_type(pattgen_ctx.pattgen, irq, &type));
639 if (type == kDifIrqTypeEvent) {
640 CHECK_DIF_OK(dif_pattgen_irq_acknowledge(pattgen_ctx.pattgen, irq));
641 }
642
643 // Complete the IRQ at the PLIC.
644 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
645 plic_irq_id));
646}
647
648void isr_testutils_pwrmgr_isr(plic_isr_ctx_t plic_ctx,
649 pwrmgr_isr_ctx_t pwrmgr_ctx,
650 top_egret_plic_peripheral_t *peripheral_serviced,
651 dif_pwrmgr_irq_t *irq_serviced) {
652
653 // Claim the IRQ at the PLIC.
654 dif_rv_plic_irq_id_t plic_irq_id;
655 CHECK_DIF_OK(
656 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
657
658 // Get the peripheral the IRQ belongs to.
659 *peripheral_serviced = (top_egret_plic_peripheral_t)
660 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
661
662 // Get the IRQ that was fired from the PLIC IRQ ID.
663 dif_pwrmgr_irq_t irq =
664 (dif_pwrmgr_irq_t)(plic_irq_id - pwrmgr_ctx.plic_pwrmgr_start_irq_id);
665 *irq_serviced = irq;
666
667 // Check if it is supposed to be the only IRQ fired.
668 if (pwrmgr_ctx.is_only_irq) {
670 CHECK_DIF_OK(dif_pwrmgr_irq_get_state(pwrmgr_ctx.pwrmgr, &snapshot));
671 CHECK(snapshot == (dif_pwrmgr_irq_state_snapshot_t)(1 << irq),
672 "Only pwrmgr IRQ %d expected to fire. Actual IRQ state = %x", irq,
673 snapshot);
674 }
675
676 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
677 dif_irq_type_t type;
678 CHECK_DIF_OK(dif_pwrmgr_irq_get_type(pwrmgr_ctx.pwrmgr, irq, &type));
679 if (type == kDifIrqTypeEvent) {
680 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(pwrmgr_ctx.pwrmgr, irq));
681 }
682
683 // Complete the IRQ at the PLIC.
684 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
685 plic_irq_id));
686}
687
688void isr_testutils_rv_timer_isr(
689 plic_isr_ctx_t plic_ctx, rv_timer_isr_ctx_t rv_timer_ctx,
690 top_egret_plic_peripheral_t *peripheral_serviced,
691 dif_rv_timer_irq_t *irq_serviced) {
692
693 // Claim the IRQ at the PLIC.
694 dif_rv_plic_irq_id_t plic_irq_id;
695 CHECK_DIF_OK(
696 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
697
698 // Get the peripheral the IRQ belongs to.
699 *peripheral_serviced = (top_egret_plic_peripheral_t)
700 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
701
702 // Get the IRQ that was fired from the PLIC IRQ ID.
703 dif_rv_timer_irq_t irq =
704 (dif_rv_timer_irq_t)(plic_irq_id -
705 rv_timer_ctx.plic_rv_timer_start_irq_id);
706 *irq_serviced = irq;
707
708 // Check if it is supposed to be the only IRQ fired.
709 if (rv_timer_ctx.is_only_irq) {
711 CHECK_DIF_OK(dif_rv_timer_irq_get_state(rv_timer_ctx.rv_timer,
712 plic_ctx.hart_id, &snapshot));
713 CHECK(snapshot == (dif_rv_timer_irq_state_snapshot_t)(1 << irq),
714 "Only rv_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
715 snapshot);
716 }
717
718 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
719 dif_irq_type_t type;
720 CHECK_DIF_OK(dif_rv_timer_irq_get_type(rv_timer_ctx.rv_timer, irq, &type));
721 if (type == kDifIrqTypeEvent) {
722 CHECK_DIF_OK(dif_rv_timer_irq_acknowledge(rv_timer_ctx.rv_timer, irq));
723 }
724
725 // Complete the IRQ at the PLIC.
726 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
727 plic_irq_id));
728}
729
730void isr_testutils_sensor_ctrl_isr(
731 plic_isr_ctx_t plic_ctx, sensor_ctrl_isr_ctx_t sensor_ctrl_ctx,
732 top_egret_plic_peripheral_t *peripheral_serviced,
733 dif_sensor_ctrl_irq_t *irq_serviced) {
734
735 // Claim the IRQ at the PLIC.
736 dif_rv_plic_irq_id_t plic_irq_id;
737 CHECK_DIF_OK(
738 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
739
740 // Get the peripheral the IRQ belongs to.
741 *peripheral_serviced = (top_egret_plic_peripheral_t)
742 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
743
744 // Get the IRQ that was fired from the PLIC IRQ ID.
745 dif_sensor_ctrl_irq_t irq =
746 (dif_sensor_ctrl_irq_t)(plic_irq_id -
747 sensor_ctrl_ctx.plic_sensor_ctrl_start_irq_id);
748 *irq_serviced = irq;
749
750 // Check if it is supposed to be the only IRQ fired.
751 if (sensor_ctrl_ctx.is_only_irq) {
753 CHECK_DIF_OK(
754 dif_sensor_ctrl_irq_get_state(sensor_ctrl_ctx.sensor_ctrl, &snapshot));
755 CHECK(snapshot == (dif_sensor_ctrl_irq_state_snapshot_t)(1 << irq),
756 "Only sensor_ctrl IRQ %d expected to fire. Actual IRQ state = %x",
757 irq, snapshot);
758 }
759
760 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
761 dif_irq_type_t type;
762 CHECK_DIF_OK(
763 dif_sensor_ctrl_irq_get_type(sensor_ctrl_ctx.sensor_ctrl, irq, &type));
764 if (type == kDifIrqTypeEvent) {
765 CHECK_DIF_OK(
766 dif_sensor_ctrl_irq_acknowledge(sensor_ctrl_ctx.sensor_ctrl, irq));
767 }
768
769 // Complete the IRQ at the PLIC.
770 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
771 plic_irq_id));
772}
773
774void isr_testutils_spi_device_isr(
775 plic_isr_ctx_t plic_ctx, spi_device_isr_ctx_t spi_device_ctx,
776 bool mute_status_irq, top_egret_plic_peripheral_t *peripheral_serviced,
777 dif_spi_device_irq_t *irq_serviced) {
778
779 // Claim the IRQ at the PLIC.
780 dif_rv_plic_irq_id_t plic_irq_id;
781 CHECK_DIF_OK(
782 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
783
784 // Get the peripheral the IRQ belongs to.
785 *peripheral_serviced = (top_egret_plic_peripheral_t)
786 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
787
788 // Get the IRQ that was fired from the PLIC IRQ ID.
789 dif_spi_device_irq_t irq =
790 (dif_spi_device_irq_t)(plic_irq_id -
791 spi_device_ctx.plic_spi_device_start_irq_id);
792 *irq_serviced = irq;
793
794 // Check if it is supposed to be the only IRQ fired.
795 if (spi_device_ctx.is_only_irq) {
797 CHECK_DIF_OK(
798 dif_spi_device_irq_get_state(spi_device_ctx.spi_device, &snapshot));
799 CHECK(snapshot == (dif_spi_device_irq_state_snapshot_t)(1 << irq),
800 "Only spi_device IRQ %d expected to fire. Actual IRQ state = %x", irq,
801 snapshot);
802 }
803
804 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
805 dif_irq_type_t type;
806 CHECK_DIF_OK(
807 dif_spi_device_irq_get_type(spi_device_ctx.spi_device, irq, &type));
808 if (type == kDifIrqTypeEvent) {
809 CHECK_DIF_OK(
810 dif_spi_device_irq_acknowledge(spi_device_ctx.spi_device, irq));
811 } else if (mute_status_irq) {
812 CHECK_DIF_OK(dif_spi_device_irq_set_enabled(spi_device_ctx.spi_device, irq,
814 }
815
816 // Complete the IRQ at the PLIC.
817 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
818 plic_irq_id));
819}
820
821void isr_testutils_spi_host_isr(
822 plic_isr_ctx_t plic_ctx, spi_host_isr_ctx_t spi_host_ctx,
823 bool mute_status_irq, top_egret_plic_peripheral_t *peripheral_serviced,
824 dif_spi_host_irq_t *irq_serviced) {
825
826 // Claim the IRQ at the PLIC.
827 dif_rv_plic_irq_id_t plic_irq_id;
828 CHECK_DIF_OK(
829 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
830
831 // Get the peripheral the IRQ belongs to.
832 *peripheral_serviced = (top_egret_plic_peripheral_t)
833 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
834
835 // Get the IRQ that was fired from the PLIC IRQ ID.
836 dif_spi_host_irq_t irq =
837 (dif_spi_host_irq_t)(plic_irq_id -
838 spi_host_ctx.plic_spi_host_start_irq_id);
839 *irq_serviced = irq;
840
841 // Check if it is supposed to be the only IRQ fired.
842 if (spi_host_ctx.is_only_irq) {
844 CHECK_DIF_OK(dif_spi_host_irq_get_state(spi_host_ctx.spi_host, &snapshot));
845 CHECK(snapshot == (dif_spi_host_irq_state_snapshot_t)(1 << irq),
846 "Only spi_host IRQ %d expected to fire. Actual IRQ state = %x", irq,
847 snapshot);
848 }
849
850 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
851 dif_irq_type_t type;
852 CHECK_DIF_OK(dif_spi_host_irq_get_type(spi_host_ctx.spi_host, irq, &type));
853 if (type == kDifIrqTypeEvent) {
854 CHECK_DIF_OK(dif_spi_host_irq_acknowledge(spi_host_ctx.spi_host, irq));
855 } else if (mute_status_irq) {
856 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(spi_host_ctx.spi_host, irq,
858 }
859
860 // Complete the IRQ at the PLIC.
861 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
862 plic_irq_id));
863}
864
865void isr_testutils_sysrst_ctrl_isr(
866 plic_isr_ctx_t plic_ctx, sysrst_ctrl_isr_ctx_t sysrst_ctrl_ctx,
867 bool mute_status_irq, top_egret_plic_peripheral_t *peripheral_serviced,
868 dif_sysrst_ctrl_irq_t *irq_serviced) {
869
870 // Claim the IRQ at the PLIC.
871 dif_rv_plic_irq_id_t plic_irq_id;
872 CHECK_DIF_OK(
873 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
874
875 // Get the peripheral the IRQ belongs to.
876 *peripheral_serviced = (top_egret_plic_peripheral_t)
877 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
878
879 // Get the IRQ that was fired from the PLIC IRQ ID.
880 dif_sysrst_ctrl_irq_t irq =
881 (dif_sysrst_ctrl_irq_t)(plic_irq_id -
882 sysrst_ctrl_ctx.plic_sysrst_ctrl_start_irq_id);
883 *irq_serviced = irq;
884
885 // Check if it is supposed to be the only IRQ fired.
886 if (sysrst_ctrl_ctx.is_only_irq) {
888 CHECK_DIF_OK(
889 dif_sysrst_ctrl_irq_get_state(sysrst_ctrl_ctx.sysrst_ctrl, &snapshot));
890 CHECK(snapshot == (dif_sysrst_ctrl_irq_state_snapshot_t)(1 << irq),
891 "Only sysrst_ctrl IRQ %d expected to fire. Actual IRQ state = %x",
892 irq, snapshot);
893 }
894
895 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
896 dif_irq_type_t type;
897 CHECK_DIF_OK(
898 dif_sysrst_ctrl_irq_get_type(sysrst_ctrl_ctx.sysrst_ctrl, irq, &type));
899 if (type == kDifIrqTypeEvent) {
900 CHECK_DIF_OK(
901 dif_sysrst_ctrl_irq_acknowledge(sysrst_ctrl_ctx.sysrst_ctrl, irq));
902 } else if (mute_status_irq) {
903 CHECK_DIF_OK(dif_sysrst_ctrl_irq_set_enabled(sysrst_ctrl_ctx.sysrst_ctrl,
904 irq, kDifToggleDisabled));
905 }
906
907 // Complete the IRQ at the PLIC.
908 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
909 plic_irq_id));
910}
911
912void isr_testutils_uart_isr(plic_isr_ctx_t plic_ctx, uart_isr_ctx_t uart_ctx,
913 bool mute_status_irq,
914 top_egret_plic_peripheral_t *peripheral_serviced,
915 dif_uart_irq_t *irq_serviced) {
916
917 // Claim the IRQ at the PLIC.
918 dif_rv_plic_irq_id_t plic_irq_id;
919 CHECK_DIF_OK(
920 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
921
922 // Get the peripheral the IRQ belongs to.
923 *peripheral_serviced = (top_egret_plic_peripheral_t)
924 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
925
926 // Get the IRQ that was fired from the PLIC IRQ ID.
927 dif_uart_irq_t irq =
928 (dif_uart_irq_t)(plic_irq_id - uart_ctx.plic_uart_start_irq_id);
929 *irq_serviced = irq;
930
931 // Check if it is supposed to be the only IRQ fired.
932 if (uart_ctx.is_only_irq) {
934 CHECK_DIF_OK(dif_uart_irq_get_state(uart_ctx.uart, &snapshot));
935 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)(1 << irq),
936 "Only uart IRQ %d expected to fire. Actual IRQ state = %x", irq,
937 snapshot);
938 }
939
940 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
941 dif_irq_type_t type;
942 CHECK_DIF_OK(dif_uart_irq_get_type(uart_ctx.uart, irq, &type));
943 if (type == kDifIrqTypeEvent) {
944 CHECK_DIF_OK(dif_uart_irq_acknowledge(uart_ctx.uart, irq));
945 } else if (mute_status_irq) {
946 CHECK_DIF_OK(
947 dif_uart_irq_set_enabled(uart_ctx.uart, irq, kDifToggleDisabled));
948 }
949
950 // Complete the IRQ at the PLIC.
951 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
952 plic_irq_id));
953}
954
955void isr_testutils_usbdev_isr(plic_isr_ctx_t plic_ctx,
956 usbdev_isr_ctx_t usbdev_ctx, bool mute_status_irq,
957 top_egret_plic_peripheral_t *peripheral_serviced,
958 dif_usbdev_irq_t *irq_serviced) {
959
960 // Claim the IRQ at the PLIC.
961 dif_rv_plic_irq_id_t plic_irq_id;
962 CHECK_DIF_OK(
963 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
964
965 // Get the peripheral the IRQ belongs to.
966 *peripheral_serviced = (top_egret_plic_peripheral_t)
967 top_egret_plic_interrupt_for_peripheral[plic_irq_id];
968
969 // Get the IRQ that was fired from the PLIC IRQ ID.
970 dif_usbdev_irq_t irq =
971 (dif_usbdev_irq_t)(plic_irq_id - usbdev_ctx.plic_usbdev_start_irq_id);
972 *irq_serviced = irq;
973
974 // Check if it is supposed to be the only IRQ fired.
975 if (usbdev_ctx.is_only_irq) {
977 CHECK_DIF_OK(dif_usbdev_irq_get_state(usbdev_ctx.usbdev, &snapshot));
978 CHECK(snapshot == (dif_usbdev_irq_state_snapshot_t)(1 << irq),
979 "Only usbdev IRQ %d expected to fire. Actual IRQ state = %x", irq,
980 snapshot);
981 }
982
983 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
984 dif_irq_type_t type;
985 CHECK_DIF_OK(dif_usbdev_irq_get_type(usbdev_ctx.usbdev, irq, &type));
986 if (type == kDifIrqTypeEvent) {
987 CHECK_DIF_OK(dif_usbdev_irq_acknowledge(usbdev_ctx.usbdev, irq));
988 } else if (mute_status_irq) {
989 CHECK_DIF_OK(
990 dif_usbdev_irq_set_enabled(usbdev_ctx.usbdev, irq, kDifToggleDisabled));
991 }
992
993 // Complete the IRQ at the PLIC.
994 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
995 plic_irq_id));
996}