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_cheriot_mem_sys_isr(
153 plic_isr_ctx_t plic_ctx, cheriot_mem_sys_isr_ctx_t cheriot_mem_sys_ctx,
154 top_earlgrey_plic_peripheral_t *peripheral_serviced,
155 dif_cheriot_mem_sys_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_cheriot_mem_sys_irq_t irq =
168 (dif_cheriot_mem_sys_irq_t)(plic_irq_id -
169 cheriot_mem_sys_ctx
170 .plic_cheriot_mem_sys_start_irq_id);
171 *irq_serviced = irq;
172
173 // Check if it is supposed to be the only IRQ fired.
174 if (cheriot_mem_sys_ctx.is_only_irq) {
176 CHECK_DIF_OK(dif_cheriot_mem_sys_irq_get_state(
177 cheriot_mem_sys_ctx.cheriot_mem_sys, &snapshot));
178 CHECK(snapshot == (dif_cheriot_mem_sys_irq_state_snapshot_t)(1 << irq),
179 "Only cheriot_mem_sys IRQ %d expected to fire. Actual IRQ state = %x",
180 irq, snapshot);
181 }
182
183 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
184 dif_irq_type_t type;
185 CHECK_DIF_OK(dif_cheriot_mem_sys_irq_get_type(
186 cheriot_mem_sys_ctx.cheriot_mem_sys, irq, &type));
187 if (type == kDifIrqTypeEvent) {
188 CHECK_DIF_OK(dif_cheriot_mem_sys_irq_acknowledge(
189 cheriot_mem_sys_ctx.cheriot_mem_sys, irq));
190 }
191
192 // Complete the IRQ at the PLIC.
193 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
194 plic_irq_id));
195}
196
197void isr_testutils_csrng_isr(
198 plic_isr_ctx_t plic_ctx, csrng_isr_ctx_t csrng_ctx,
199 top_earlgrey_plic_peripheral_t *peripheral_serviced,
200 dif_csrng_irq_t *irq_serviced) {
201
202 // Claim the IRQ at the PLIC.
203 dif_rv_plic_irq_id_t plic_irq_id;
204 CHECK_DIF_OK(
205 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
206
207 // Get the peripheral the IRQ belongs to.
208 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
209 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
210
211 // Get the IRQ that was fired from the PLIC IRQ ID.
212 dif_csrng_irq_t irq =
213 (dif_csrng_irq_t)(plic_irq_id - csrng_ctx.plic_csrng_start_irq_id);
214 *irq_serviced = irq;
215
216 // Check if it is supposed to be the only IRQ fired.
217 if (csrng_ctx.is_only_irq) {
219 CHECK_DIF_OK(dif_csrng_irq_get_state(csrng_ctx.csrng, &snapshot));
220 CHECK(snapshot == (dif_csrng_irq_state_snapshot_t)(1 << irq),
221 "Only csrng IRQ %d expected to fire. Actual IRQ state = %x", irq,
222 snapshot);
223 }
224
225 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
226 dif_irq_type_t type;
227 CHECK_DIF_OK(dif_csrng_irq_get_type(csrng_ctx.csrng, irq, &type));
228 if (type == kDifIrqTypeEvent) {
229 CHECK_DIF_OK(dif_csrng_irq_acknowledge(csrng_ctx.csrng, irq));
230 }
231
232 // Complete the IRQ at the PLIC.
233 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
234 plic_irq_id));
235}
236
237void isr_testutils_edn_isr(plic_isr_ctx_t plic_ctx, edn_isr_ctx_t edn_ctx,
238 top_earlgrey_plic_peripheral_t *peripheral_serviced,
239 dif_edn_irq_t *irq_serviced) {
240
241 // Claim the IRQ at the PLIC.
242 dif_rv_plic_irq_id_t plic_irq_id;
243 CHECK_DIF_OK(
244 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
245
246 // Get the peripheral the IRQ belongs to.
247 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
248 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
249
250 // Get the IRQ that was fired from the PLIC IRQ ID.
251 dif_edn_irq_t irq =
252 (dif_edn_irq_t)(plic_irq_id - edn_ctx.plic_edn_start_irq_id);
253 *irq_serviced = irq;
254
255 // Check if it is supposed to be the only IRQ fired.
256 if (edn_ctx.is_only_irq) {
258 CHECK_DIF_OK(dif_edn_irq_get_state(edn_ctx.edn, &snapshot));
259 CHECK(snapshot == (dif_edn_irq_state_snapshot_t)(1 << irq),
260 "Only edn IRQ %d expected to fire. Actual IRQ state = %x", irq,
261 snapshot);
262 }
263
264 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
265 dif_irq_type_t type;
266 CHECK_DIF_OK(dif_edn_irq_get_type(edn_ctx.edn, irq, &type));
267 if (type == kDifIrqTypeEvent) {
268 CHECK_DIF_OK(dif_edn_irq_acknowledge(edn_ctx.edn, irq));
269 }
270
271 // Complete the IRQ at the PLIC.
272 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
273 plic_irq_id));
274}
275
276void isr_testutils_entropy_src_isr(
277 plic_isr_ctx_t plic_ctx, entropy_src_isr_ctx_t entropy_src_ctx,
278 top_earlgrey_plic_peripheral_t *peripheral_serviced,
279 dif_entropy_src_irq_t *irq_serviced) {
280
281 // Claim the IRQ at the PLIC.
282 dif_rv_plic_irq_id_t plic_irq_id;
283 CHECK_DIF_OK(
284 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
285
286 // Get the peripheral the IRQ belongs to.
287 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
288 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
289
290 // Get the IRQ that was fired from the PLIC IRQ ID.
291 dif_entropy_src_irq_t irq =
292 (dif_entropy_src_irq_t)(plic_irq_id -
293 entropy_src_ctx.plic_entropy_src_start_irq_id);
294 *irq_serviced = irq;
295
296 // Check if it is supposed to be the only IRQ fired.
297 if (entropy_src_ctx.is_only_irq) {
299 CHECK_DIF_OK(
300 dif_entropy_src_irq_get_state(entropy_src_ctx.entropy_src, &snapshot));
301 CHECK(snapshot == (dif_entropy_src_irq_state_snapshot_t)(1 << irq),
302 "Only entropy_src IRQ %d expected to fire. Actual IRQ state = %x",
303 irq, snapshot);
304 }
305
306 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
307 dif_irq_type_t type;
308 CHECK_DIF_OK(
309 dif_entropy_src_irq_get_type(entropy_src_ctx.entropy_src, irq, &type));
310 if (type == kDifIrqTypeEvent) {
311 CHECK_DIF_OK(
312 dif_entropy_src_irq_acknowledge(entropy_src_ctx.entropy_src, irq));
313 }
314
315 // Complete the IRQ at the PLIC.
316 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
317 plic_irq_id));
318}
319
320void isr_testutils_gpio_isr(plic_isr_ctx_t plic_ctx, gpio_isr_ctx_t gpio_ctx,
321 top_earlgrey_plic_peripheral_t *peripheral_serviced,
322 dif_gpio_irq_t *irq_serviced) {
323
324 // Claim the IRQ at the PLIC.
325 dif_rv_plic_irq_id_t plic_irq_id;
326 CHECK_DIF_OK(
327 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
328
329 // Get the peripheral the IRQ belongs to.
330 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
331 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
332
333 // Get the IRQ that was fired from the PLIC IRQ ID.
334 dif_gpio_irq_t irq =
335 (dif_gpio_irq_t)(plic_irq_id - gpio_ctx.plic_gpio_start_irq_id);
336 *irq_serviced = irq;
337
338 // Check if it is supposed to be the only IRQ fired.
339 if (gpio_ctx.is_only_irq) {
341 CHECK_DIF_OK(dif_gpio_irq_get_state(gpio_ctx.gpio, &snapshot));
342 CHECK(snapshot == (dif_gpio_irq_state_snapshot_t)(1 << irq),
343 "Only gpio IRQ %d expected to fire. Actual IRQ state = %x", irq,
344 snapshot);
345 }
346
347 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
348 dif_irq_type_t type;
349 CHECK_DIF_OK(dif_gpio_irq_get_type(gpio_ctx.gpio, irq, &type));
350 if (type == kDifIrqTypeEvent) {
351 CHECK_DIF_OK(dif_gpio_irq_acknowledge(gpio_ctx.gpio, irq));
352 }
353
354 // Complete the IRQ at the PLIC.
355 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
356 plic_irq_id));
357}
358
359void isr_testutils_hmac_isr(plic_isr_ctx_t plic_ctx, hmac_isr_ctx_t hmac_ctx,
360 bool mute_status_irq,
361 top_earlgrey_plic_peripheral_t *peripheral_serviced,
362 dif_hmac_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_earlgrey_plic_peripheral_t)
371 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
372
373 // Get the IRQ that was fired from the PLIC IRQ ID.
374 dif_hmac_irq_t irq =
375 (dif_hmac_irq_t)(plic_irq_id - hmac_ctx.plic_hmac_start_irq_id);
376 *irq_serviced = irq;
377
378 // Check if it is supposed to be the only IRQ fired.
379 if (hmac_ctx.is_only_irq) {
381 CHECK_DIF_OK(dif_hmac_irq_get_state(hmac_ctx.hmac, &snapshot));
382 CHECK(snapshot == (dif_hmac_irq_state_snapshot_t)(1 << irq),
383 "Only hmac 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_hmac_irq_get_type(hmac_ctx.hmac, irq, &type));
390 if (type == kDifIrqTypeEvent) {
391 CHECK_DIF_OK(dif_hmac_irq_acknowledge(hmac_ctx.hmac, irq));
392 } else if (mute_status_irq) {
393 CHECK_DIF_OK(
394 dif_hmac_irq_set_enabled(hmac_ctx.hmac, irq, kDifToggleDisabled));
395 }
396
397 // Complete the IRQ at the PLIC.
398 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
399 plic_irq_id));
400}
401
402void isr_testutils_i2c_isr(plic_isr_ctx_t plic_ctx, i2c_isr_ctx_t i2c_ctx,
403 bool mute_status_irq,
404 top_earlgrey_plic_peripheral_t *peripheral_serviced,
405 dif_i2c_irq_t *irq_serviced) {
406
407 // Claim the IRQ at the PLIC.
408 dif_rv_plic_irq_id_t plic_irq_id;
409 CHECK_DIF_OK(
410 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
411
412 // Get the peripheral the IRQ belongs to.
413 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
414 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
415
416 // Get the IRQ that was fired from the PLIC IRQ ID.
417 dif_i2c_irq_t irq =
418 (dif_i2c_irq_t)(plic_irq_id - i2c_ctx.plic_i2c_start_irq_id);
419 *irq_serviced = irq;
420
421 // Check if it is supposed to be the only IRQ fired.
422 if (i2c_ctx.is_only_irq) {
424 CHECK_DIF_OK(dif_i2c_irq_get_state(i2c_ctx.i2c, &snapshot));
425 CHECK(snapshot == (dif_i2c_irq_state_snapshot_t)(1 << irq),
426 "Only i2c IRQ %d expected to fire. Actual IRQ state = %x", irq,
427 snapshot);
428 }
429
430 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
431 dif_irq_type_t type;
432 CHECK_DIF_OK(dif_i2c_irq_get_type(i2c_ctx.i2c, irq, &type));
433 if (type == kDifIrqTypeEvent) {
434 CHECK_DIF_OK(dif_i2c_irq_acknowledge(i2c_ctx.i2c, irq));
435 } else if (mute_status_irq) {
436 CHECK_DIF_OK(dif_i2c_irq_set_enabled(i2c_ctx.i2c, irq, kDifToggleDisabled));
437 }
438
439 // Complete the IRQ at the PLIC.
440 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
441 plic_irq_id));
442}
443
444void isr_testutils_keymgr_dpe_isr(
445 plic_isr_ctx_t plic_ctx, keymgr_dpe_isr_ctx_t keymgr_dpe_ctx,
446 top_earlgrey_plic_peripheral_t *peripheral_serviced,
447 dif_keymgr_dpe_irq_t *irq_serviced) {
448
449 // Claim the IRQ at the PLIC.
450 dif_rv_plic_irq_id_t plic_irq_id;
451 CHECK_DIF_OK(
452 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
453
454 // Get the peripheral the IRQ belongs to.
455 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
456 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
457
458 // Get the IRQ that was fired from the PLIC IRQ ID.
459 dif_keymgr_dpe_irq_t irq =
460 (dif_keymgr_dpe_irq_t)(plic_irq_id -
461 keymgr_dpe_ctx.plic_keymgr_dpe_start_irq_id);
462 *irq_serviced = irq;
463
464 // Check if it is supposed to be the only IRQ fired.
465 if (keymgr_dpe_ctx.is_only_irq) {
467 CHECK_DIF_OK(
468 dif_keymgr_dpe_irq_get_state(keymgr_dpe_ctx.keymgr_dpe, &snapshot));
469 CHECK(snapshot == (dif_keymgr_dpe_irq_state_snapshot_t)(1 << irq),
470 "Only keymgr_dpe 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(
477 dif_keymgr_dpe_irq_get_type(keymgr_dpe_ctx.keymgr_dpe, irq, &type));
478 if (type == kDifIrqTypeEvent) {
479 CHECK_DIF_OK(
480 dif_keymgr_dpe_irq_acknowledge(keymgr_dpe_ctx.keymgr_dpe, irq));
481 }
482
483 // Complete the IRQ at the PLIC.
484 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
485 plic_irq_id));
486}
487
488void isr_testutils_kmac_isr(plic_isr_ctx_t plic_ctx, kmac_isr_ctx_t kmac_ctx,
489 bool mute_status_irq,
490 top_earlgrey_plic_peripheral_t *peripheral_serviced,
491 dif_kmac_irq_t *irq_serviced) {
492
493 // Claim the IRQ at the PLIC.
494 dif_rv_plic_irq_id_t plic_irq_id;
495 CHECK_DIF_OK(
496 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
497
498 // Get the peripheral the IRQ belongs to.
499 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
500 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
501
502 // Get the IRQ that was fired from the PLIC IRQ ID.
503 dif_kmac_irq_t irq =
504 (dif_kmac_irq_t)(plic_irq_id - kmac_ctx.plic_kmac_start_irq_id);
505 *irq_serviced = irq;
506
507 // Check if it is supposed to be the only IRQ fired.
508 if (kmac_ctx.is_only_irq) {
510 CHECK_DIF_OK(dif_kmac_irq_get_state(kmac_ctx.kmac, &snapshot));
511 CHECK(snapshot == (dif_kmac_irq_state_snapshot_t)(1 << irq),
512 "Only kmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
513 snapshot);
514 }
515
516 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
517 dif_irq_type_t type;
518 CHECK_DIF_OK(dif_kmac_irq_get_type(kmac_ctx.kmac, irq, &type));
519 if (type == kDifIrqTypeEvent) {
520 CHECK_DIF_OK(dif_kmac_irq_acknowledge(kmac_ctx.kmac, irq));
521 } else if (mute_status_irq) {
522 CHECK_DIF_OK(
523 dif_kmac_irq_set_enabled(kmac_ctx.kmac, irq, kDifToggleDisabled));
524 }
525
526 // Complete the IRQ at the PLIC.
527 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
528 plic_irq_id));
529}
530
531void isr_testutils_otbn_isr(plic_isr_ctx_t plic_ctx, otbn_isr_ctx_t otbn_ctx,
532 top_earlgrey_plic_peripheral_t *peripheral_serviced,
533 dif_otbn_irq_t *irq_serviced) {
534
535 // Claim the IRQ at the PLIC.
536 dif_rv_plic_irq_id_t plic_irq_id;
537 CHECK_DIF_OK(
538 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
539
540 // Get the peripheral the IRQ belongs to.
541 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
542 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
543
544 // Get the IRQ that was fired from the PLIC IRQ ID.
545 dif_otbn_irq_t irq =
546 (dif_otbn_irq_t)(plic_irq_id - otbn_ctx.plic_otbn_start_irq_id);
547 *irq_serviced = irq;
548
549 // Check if it is supposed to be the only IRQ fired.
550 if (otbn_ctx.is_only_irq) {
552 CHECK_DIF_OK(dif_otbn_irq_get_state(otbn_ctx.otbn, &snapshot));
553 CHECK(snapshot == (dif_otbn_irq_state_snapshot_t)(1 << irq),
554 "Only otbn IRQ %d expected to fire. Actual IRQ state = %x", irq,
555 snapshot);
556 }
557
558 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
559 dif_irq_type_t type;
560 CHECK_DIF_OK(dif_otbn_irq_get_type(otbn_ctx.otbn, irq, &type));
561 if (type == kDifIrqTypeEvent) {
562 CHECK_DIF_OK(dif_otbn_irq_acknowledge(otbn_ctx.otbn, irq));
563 }
564
565 // Complete the IRQ at the PLIC.
566 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
567 plic_irq_id));
568}
569
570void isr_testutils_otp_ctrl_isr(
571 plic_isr_ctx_t plic_ctx, otp_ctrl_isr_ctx_t otp_ctrl_ctx,
572 top_earlgrey_plic_peripheral_t *peripheral_serviced,
573 dif_otp_ctrl_irq_t *irq_serviced) {
574
575 // Claim the IRQ at the PLIC.
576 dif_rv_plic_irq_id_t plic_irq_id;
577 CHECK_DIF_OK(
578 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
579
580 // Get the peripheral the IRQ belongs to.
581 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
582 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
583
584 // Get the IRQ that was fired from the PLIC IRQ ID.
585 dif_otp_ctrl_irq_t irq =
586 (dif_otp_ctrl_irq_t)(plic_irq_id -
587 otp_ctrl_ctx.plic_otp_ctrl_start_irq_id);
588 *irq_serviced = irq;
589
590 // Check if it is supposed to be the only IRQ fired.
591 if (otp_ctrl_ctx.is_only_irq) {
593 CHECK_DIF_OK(dif_otp_ctrl_irq_get_state(otp_ctrl_ctx.otp_ctrl, &snapshot));
594 CHECK(snapshot == (dif_otp_ctrl_irq_state_snapshot_t)(1 << irq),
595 "Only otp_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
596 snapshot);
597 }
598
599 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
600 dif_irq_type_t type;
601 CHECK_DIF_OK(dif_otp_ctrl_irq_get_type(otp_ctrl_ctx.otp_ctrl, irq, &type));
602 if (type == kDifIrqTypeEvent) {
603 CHECK_DIF_OK(dif_otp_ctrl_irq_acknowledge(otp_ctrl_ctx.otp_ctrl, irq));
604 }
605
606 // Complete the IRQ at the PLIC.
607 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
608 plic_irq_id));
609}
610
611void isr_testutils_pwrmgr_isr(
612 plic_isr_ctx_t plic_ctx, pwrmgr_isr_ctx_t pwrmgr_ctx,
613 top_earlgrey_plic_peripheral_t *peripheral_serviced,
614 dif_pwrmgr_irq_t *irq_serviced) {
615
616 // Claim the IRQ at the PLIC.
617 dif_rv_plic_irq_id_t plic_irq_id;
618 CHECK_DIF_OK(
619 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
620
621 // Get the peripheral the IRQ belongs to.
622 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
623 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
624
625 // Get the IRQ that was fired from the PLIC IRQ ID.
626 dif_pwrmgr_irq_t irq =
627 (dif_pwrmgr_irq_t)(plic_irq_id - pwrmgr_ctx.plic_pwrmgr_start_irq_id);
628 *irq_serviced = irq;
629
630 // Check if it is supposed to be the only IRQ fired.
631 if (pwrmgr_ctx.is_only_irq) {
633 CHECK_DIF_OK(dif_pwrmgr_irq_get_state(pwrmgr_ctx.pwrmgr, &snapshot));
634 CHECK(snapshot == (dif_pwrmgr_irq_state_snapshot_t)(1 << irq),
635 "Only pwrmgr IRQ %d expected to fire. Actual IRQ state = %x", irq,
636 snapshot);
637 }
638
639 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
640 dif_irq_type_t type;
641 CHECK_DIF_OK(dif_pwrmgr_irq_get_type(pwrmgr_ctx.pwrmgr, irq, &type));
642 if (type == kDifIrqTypeEvent) {
643 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(pwrmgr_ctx.pwrmgr, irq));
644 }
645
646 // Complete the IRQ at the PLIC.
647 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
648 plic_irq_id));
649}
650
651void isr_testutils_rram_ctrl_isr(
652 plic_isr_ctx_t plic_ctx, rram_ctrl_isr_ctx_t rram_ctrl_ctx,
653 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
654 dif_rram_ctrl_irq_t *irq_serviced) {
655
656 // Claim the IRQ at the PLIC.
657 dif_rv_plic_irq_id_t plic_irq_id;
658 CHECK_DIF_OK(
659 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
660
661 // Get the peripheral the IRQ belongs to.
662 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
663 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
664
665 // Get the IRQ that was fired from the PLIC IRQ ID.
666 dif_rram_ctrl_irq_t irq =
667 (dif_rram_ctrl_irq_t)(plic_irq_id -
668 rram_ctrl_ctx.plic_rram_ctrl_start_irq_id);
669 *irq_serviced = irq;
670
671 // Check if it is supposed to be the only IRQ fired.
672 if (rram_ctrl_ctx.is_only_irq) {
674 CHECK_DIF_OK(
675 dif_rram_ctrl_irq_get_state(rram_ctrl_ctx.rram_ctrl, &snapshot));
676 CHECK(snapshot == (dif_rram_ctrl_irq_state_snapshot_t)(1 << irq),
677 "Only rram_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
678 snapshot);
679 }
680
681 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
682 dif_irq_type_t type;
683 CHECK_DIF_OK(dif_rram_ctrl_irq_get_type(rram_ctrl_ctx.rram_ctrl, irq, &type));
684 if (type == kDifIrqTypeEvent) {
685 CHECK_DIF_OK(dif_rram_ctrl_irq_acknowledge(rram_ctrl_ctx.rram_ctrl, irq));
686 } else if (mute_status_irq) {
687 CHECK_DIF_OK(dif_rram_ctrl_irq_set_enabled(rram_ctrl_ctx.rram_ctrl, irq,
689 }
690
691 // Complete the IRQ at the PLIC.
692 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
693 plic_irq_id));
694}
695
696void isr_testutils_rv_timer_isr(
697 plic_isr_ctx_t plic_ctx, rv_timer_isr_ctx_t rv_timer_ctx,
698 top_earlgrey_plic_peripheral_t *peripheral_serviced,
699 dif_rv_timer_irq_t *irq_serviced) {
700
701 // Claim the IRQ at the PLIC.
702 dif_rv_plic_irq_id_t plic_irq_id;
703 CHECK_DIF_OK(
704 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
705
706 // Get the peripheral the IRQ belongs to.
707 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
708 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
709
710 // Get the IRQ that was fired from the PLIC IRQ ID.
711 dif_rv_timer_irq_t irq =
712 (dif_rv_timer_irq_t)(plic_irq_id -
713 rv_timer_ctx.plic_rv_timer_start_irq_id);
714 *irq_serviced = irq;
715
716 // Check if it is supposed to be the only IRQ fired.
717 if (rv_timer_ctx.is_only_irq) {
719 CHECK_DIF_OK(dif_rv_timer_irq_get_state(rv_timer_ctx.rv_timer,
720 plic_ctx.hart_id, &snapshot));
721 CHECK(snapshot == (dif_rv_timer_irq_state_snapshot_t)(1 << irq),
722 "Only rv_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
723 snapshot);
724 }
725
726 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
727 dif_irq_type_t type;
728 CHECK_DIF_OK(dif_rv_timer_irq_get_type(rv_timer_ctx.rv_timer, irq, &type));
729 if (type == kDifIrqTypeEvent) {
730 CHECK_DIF_OK(dif_rv_timer_irq_acknowledge(rv_timer_ctx.rv_timer, irq));
731 }
732
733 // Complete the IRQ at the PLIC.
734 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
735 plic_irq_id));
736}
737
738void isr_testutils_sensor_ctrl_isr(
739 plic_isr_ctx_t plic_ctx, sensor_ctrl_isr_ctx_t sensor_ctrl_ctx,
740 top_earlgrey_plic_peripheral_t *peripheral_serviced,
741 dif_sensor_ctrl_irq_t *irq_serviced) {
742
743 // Claim the IRQ at the PLIC.
744 dif_rv_plic_irq_id_t plic_irq_id;
745 CHECK_DIF_OK(
746 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
747
748 // Get the peripheral the IRQ belongs to.
749 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
750 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
751
752 // Get the IRQ that was fired from the PLIC IRQ ID.
753 dif_sensor_ctrl_irq_t irq =
754 (dif_sensor_ctrl_irq_t)(plic_irq_id -
755 sensor_ctrl_ctx.plic_sensor_ctrl_start_irq_id);
756 *irq_serviced = irq;
757
758 // Check if it is supposed to be the only IRQ fired.
759 if (sensor_ctrl_ctx.is_only_irq) {
761 CHECK_DIF_OK(
762 dif_sensor_ctrl_irq_get_state(sensor_ctrl_ctx.sensor_ctrl, &snapshot));
763 CHECK(snapshot == (dif_sensor_ctrl_irq_state_snapshot_t)(1 << irq),
764 "Only sensor_ctrl IRQ %d expected to fire. Actual IRQ state = %x",
765 irq, snapshot);
766 }
767
768 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
769 dif_irq_type_t type;
770 CHECK_DIF_OK(
771 dif_sensor_ctrl_irq_get_type(sensor_ctrl_ctx.sensor_ctrl, irq, &type));
772 if (type == kDifIrqTypeEvent) {
773 CHECK_DIF_OK(
774 dif_sensor_ctrl_irq_acknowledge(sensor_ctrl_ctx.sensor_ctrl, irq));
775 }
776
777 // Complete the IRQ at the PLIC.
778 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
779 plic_irq_id));
780}
781
782void isr_testutils_spi_device_isr(
783 plic_isr_ctx_t plic_ctx, spi_device_isr_ctx_t spi_device_ctx,
784 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
785 dif_spi_device_irq_t *irq_serviced) {
786
787 // Claim the IRQ at the PLIC.
788 dif_rv_plic_irq_id_t plic_irq_id;
789 CHECK_DIF_OK(
790 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
791
792 // Get the peripheral the IRQ belongs to.
793 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
794 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
795
796 // Get the IRQ that was fired from the PLIC IRQ ID.
797 dif_spi_device_irq_t irq =
798 (dif_spi_device_irq_t)(plic_irq_id -
799 spi_device_ctx.plic_spi_device_start_irq_id);
800 *irq_serviced = irq;
801
802 // Check if it is supposed to be the only IRQ fired.
803 if (spi_device_ctx.is_only_irq) {
805 CHECK_DIF_OK(
806 dif_spi_device_irq_get_state(spi_device_ctx.spi_device, &snapshot));
807 CHECK(snapshot == (dif_spi_device_irq_state_snapshot_t)(1 << irq),
808 "Only spi_device IRQ %d expected to fire. Actual IRQ state = %x", irq,
809 snapshot);
810 }
811
812 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
813 dif_irq_type_t type;
814 CHECK_DIF_OK(
815 dif_spi_device_irq_get_type(spi_device_ctx.spi_device, irq, &type));
816 if (type == kDifIrqTypeEvent) {
817 CHECK_DIF_OK(
818 dif_spi_device_irq_acknowledge(spi_device_ctx.spi_device, irq));
819 } else if (mute_status_irq) {
820 CHECK_DIF_OK(dif_spi_device_irq_set_enabled(spi_device_ctx.spi_device, irq,
822 }
823
824 // Complete the IRQ at the PLIC.
825 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
826 plic_irq_id));
827}
828
829void isr_testutils_spi_host_isr(
830 plic_isr_ctx_t plic_ctx, spi_host_isr_ctx_t spi_host_ctx,
831 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
832 dif_spi_host_irq_t *irq_serviced) {
833
834 // Claim the IRQ at the PLIC.
835 dif_rv_plic_irq_id_t plic_irq_id;
836 CHECK_DIF_OK(
837 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
838
839 // Get the peripheral the IRQ belongs to.
840 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
841 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
842
843 // Get the IRQ that was fired from the PLIC IRQ ID.
844 dif_spi_host_irq_t irq =
845 (dif_spi_host_irq_t)(plic_irq_id -
846 spi_host_ctx.plic_spi_host_start_irq_id);
847 *irq_serviced = irq;
848
849 // Check if it is supposed to be the only IRQ fired.
850 if (spi_host_ctx.is_only_irq) {
852 CHECK_DIF_OK(dif_spi_host_irq_get_state(spi_host_ctx.spi_host, &snapshot));
853 CHECK(snapshot == (dif_spi_host_irq_state_snapshot_t)(1 << irq),
854 "Only spi_host IRQ %d expected to fire. Actual IRQ state = %x", irq,
855 snapshot);
856 }
857
858 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
859 dif_irq_type_t type;
860 CHECK_DIF_OK(dif_spi_host_irq_get_type(spi_host_ctx.spi_host, irq, &type));
861 if (type == kDifIrqTypeEvent) {
862 CHECK_DIF_OK(dif_spi_host_irq_acknowledge(spi_host_ctx.spi_host, irq));
863 } else if (mute_status_irq) {
864 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(spi_host_ctx.spi_host, irq,
866 }
867
868 // Complete the IRQ at the PLIC.
869 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
870 plic_irq_id));
871}
872
873void isr_testutils_sysrst_ctrl_isr(
874 plic_isr_ctx_t plic_ctx, sysrst_ctrl_isr_ctx_t sysrst_ctrl_ctx,
875 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
876 dif_sysrst_ctrl_irq_t *irq_serviced) {
877
878 // Claim the IRQ at the PLIC.
879 dif_rv_plic_irq_id_t plic_irq_id;
880 CHECK_DIF_OK(
881 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
882
883 // Get the peripheral the IRQ belongs to.
884 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
885 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
886
887 // Get the IRQ that was fired from the PLIC IRQ ID.
888 dif_sysrst_ctrl_irq_t irq =
889 (dif_sysrst_ctrl_irq_t)(plic_irq_id -
890 sysrst_ctrl_ctx.plic_sysrst_ctrl_start_irq_id);
891 *irq_serviced = irq;
892
893 // Check if it is supposed to be the only IRQ fired.
894 if (sysrst_ctrl_ctx.is_only_irq) {
896 CHECK_DIF_OK(
897 dif_sysrst_ctrl_irq_get_state(sysrst_ctrl_ctx.sysrst_ctrl, &snapshot));
898 CHECK(snapshot == (dif_sysrst_ctrl_irq_state_snapshot_t)(1 << irq),
899 "Only sysrst_ctrl IRQ %d expected to fire. Actual IRQ state = %x",
900 irq, snapshot);
901 }
902
903 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
904 dif_irq_type_t type;
905 CHECK_DIF_OK(
906 dif_sysrst_ctrl_irq_get_type(sysrst_ctrl_ctx.sysrst_ctrl, irq, &type));
907 if (type == kDifIrqTypeEvent) {
908 CHECK_DIF_OK(
909 dif_sysrst_ctrl_irq_acknowledge(sysrst_ctrl_ctx.sysrst_ctrl, irq));
910 } else if (mute_status_irq) {
911 CHECK_DIF_OK(dif_sysrst_ctrl_irq_set_enabled(sysrst_ctrl_ctx.sysrst_ctrl,
912 irq, kDifToggleDisabled));
913 }
914
915 // Complete the IRQ at the PLIC.
916 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
917 plic_irq_id));
918}
919
920void isr_testutils_uart_isr(plic_isr_ctx_t plic_ctx, uart_isr_ctx_t uart_ctx,
921 bool mute_status_irq,
922 top_earlgrey_plic_peripheral_t *peripheral_serviced,
923 dif_uart_irq_t *irq_serviced) {
924
925 // Claim the IRQ at the PLIC.
926 dif_rv_plic_irq_id_t plic_irq_id;
927 CHECK_DIF_OK(
928 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
929
930 // Get the peripheral the IRQ belongs to.
931 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
932 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
933
934 // Get the IRQ that was fired from the PLIC IRQ ID.
935 dif_uart_irq_t irq =
936 (dif_uart_irq_t)(plic_irq_id - uart_ctx.plic_uart_start_irq_id);
937 *irq_serviced = irq;
938
939 // Check if it is supposed to be the only IRQ fired.
940 if (uart_ctx.is_only_irq) {
942 CHECK_DIF_OK(dif_uart_irq_get_state(uart_ctx.uart, &snapshot));
943 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)(1 << irq),
944 "Only uart IRQ %d expected to fire. Actual IRQ state = %x", irq,
945 snapshot);
946 }
947
948 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
949 dif_irq_type_t type;
950 CHECK_DIF_OK(dif_uart_irq_get_type(uart_ctx.uart, irq, &type));
951 if (type == kDifIrqTypeEvent) {
952 CHECK_DIF_OK(dif_uart_irq_acknowledge(uart_ctx.uart, irq));
953 } else if (mute_status_irq) {
954 CHECK_DIF_OK(
955 dif_uart_irq_set_enabled(uart_ctx.uart, irq, kDifToggleDisabled));
956 }
957
958 // Complete the IRQ at the PLIC.
959 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
960 plic_irq_id));
961}
962
963void isr_testutils_usbdev_isr(
964 plic_isr_ctx_t plic_ctx, usbdev_isr_ctx_t usbdev_ctx, bool mute_status_irq,
965 top_earlgrey_plic_peripheral_t *peripheral_serviced,
966 dif_usbdev_irq_t *irq_serviced) {
967
968 // Claim the IRQ at the PLIC.
969 dif_rv_plic_irq_id_t plic_irq_id;
970 CHECK_DIF_OK(
971 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
972
973 // Get the peripheral the IRQ belongs to.
974 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
975 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
976
977 // Get the IRQ that was fired from the PLIC IRQ ID.
978 dif_usbdev_irq_t irq =
979 (dif_usbdev_irq_t)(plic_irq_id - usbdev_ctx.plic_usbdev_start_irq_id);
980 *irq_serviced = irq;
981
982 // Check if it is supposed to be the only IRQ fired.
983 if (usbdev_ctx.is_only_irq) {
985 CHECK_DIF_OK(dif_usbdev_irq_get_state(usbdev_ctx.usbdev, &snapshot));
986 CHECK(snapshot == (dif_usbdev_irq_state_snapshot_t)(1 << irq),
987 "Only usbdev IRQ %d expected to fire. Actual IRQ state = %x", irq,
988 snapshot);
989 }
990
991 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
992 dif_irq_type_t type;
993 CHECK_DIF_OK(dif_usbdev_irq_get_type(usbdev_ctx.usbdev, irq, &type));
994 if (type == kDifIrqTypeEvent) {
995 CHECK_DIF_OK(dif_usbdev_irq_acknowledge(usbdev_ctx.usbdev, irq));
996 } else if (mute_status_irq) {
997 CHECK_DIF_OK(
998 dif_usbdev_irq_set_enabled(usbdev_ctx.usbdev, irq, kDifToggleDisabled));
999 }
1000
1001 // Complete the IRQ at the PLIC.
1002 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
1003 plic_irq_id));
1004}