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