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
12#include "sw/device/lib/testing/test_framework/check.h"
13
14void isr_testutils_aon_timer_isr(
15 plic_isr_ctx_t plic_ctx, aon_timer_isr_ctx_t aon_timer_ctx,
16 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
17 dif_aon_timer_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_englishbreakfast_plic_peripheral_t)
26 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
27
28 // Get the IRQ that was fired from the PLIC IRQ ID.
29 dif_aon_timer_irq_t irq =
30 (dif_aon_timer_irq_t)(plic_irq_id -
31 aon_timer_ctx.plic_aon_timer_start_irq_id);
32 *irq_serviced = irq;
33
34 // Check if it is supposed to be the only IRQ fired.
35 if (aon_timer_ctx.is_only_irq) {
37 CHECK_DIF_OK(
38 dif_aon_timer_irq_get_state(aon_timer_ctx.aon_timer, &snapshot));
39 CHECK(snapshot == (dif_aon_timer_irq_state_snapshot_t)(1 << irq),
40 "Only aon_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
41 snapshot);
42 }
43
44 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
45 dif_irq_type_t type;
46 CHECK_DIF_OK(dif_aon_timer_irq_get_type(aon_timer_ctx.aon_timer, irq, &type));
47 if (type == kDifIrqTypeEvent) {
48 CHECK_DIF_OK(dif_aon_timer_irq_acknowledge(aon_timer_ctx.aon_timer, irq));
49 }
50
51 // Complete the IRQ at the PLIC.
52 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
53 plic_irq_id));
54}
55
56void isr_testutils_flash_ctrl_isr(
57 plic_isr_ctx_t plic_ctx, flash_ctrl_isr_ctx_t flash_ctrl_ctx,
58 bool mute_status_irq,
59 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
60 dif_flash_ctrl_irq_t *irq_serviced) {
61
62 // Claim the IRQ at the PLIC.
63 dif_rv_plic_irq_id_t plic_irq_id;
64 CHECK_DIF_OK(
65 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
66
67 // Get the peripheral the IRQ belongs to.
68 *peripheral_serviced = (top_englishbreakfast_plic_peripheral_t)
69 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
70
71 // Get the IRQ that was fired from the PLIC IRQ ID.
72 dif_flash_ctrl_irq_t irq =
73 (dif_flash_ctrl_irq_t)(plic_irq_id -
74 flash_ctrl_ctx.plic_flash_ctrl_start_irq_id);
75 *irq_serviced = irq;
76
77 // Check if it is supposed to be the only IRQ fired.
78 if (flash_ctrl_ctx.is_only_irq) {
80 CHECK_DIF_OK(
81 dif_flash_ctrl_irq_get_state(flash_ctrl_ctx.flash_ctrl, &snapshot));
82 CHECK(snapshot == (dif_flash_ctrl_irq_state_snapshot_t)(1 << irq),
83 "Only flash_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
84 snapshot);
85 }
86
87 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
88 dif_irq_type_t type;
89 CHECK_DIF_OK(
90 dif_flash_ctrl_irq_get_type(flash_ctrl_ctx.flash_ctrl, irq, &type));
91 if (type == kDifIrqTypeEvent) {
92 CHECK_DIF_OK(
93 dif_flash_ctrl_irq_acknowledge(flash_ctrl_ctx.flash_ctrl, irq));
94 } else if (mute_status_irq) {
95 CHECK_DIF_OK(dif_flash_ctrl_irq_set_enabled(flash_ctrl_ctx.flash_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_gpio_isr(
105 plic_isr_ctx_t plic_ctx, gpio_isr_ctx_t gpio_ctx,
106 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
107 dif_gpio_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_englishbreakfast_plic_peripheral_t)
116 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
117
118 // Get the IRQ that was fired from the PLIC IRQ ID.
119 dif_gpio_irq_t irq =
120 (dif_gpio_irq_t)(plic_irq_id - gpio_ctx.plic_gpio_start_irq_id);
121 *irq_serviced = irq;
122
123 // Check if it is supposed to be the only IRQ fired.
124 if (gpio_ctx.is_only_irq) {
126 CHECK_DIF_OK(dif_gpio_irq_get_state(gpio_ctx.gpio, &snapshot));
127 CHECK(snapshot == (dif_gpio_irq_state_snapshot_t)(1 << irq),
128 "Only gpio IRQ %d expected to fire. Actual IRQ state = %x", irq,
129 snapshot);
130 }
131
132 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
133 dif_irq_type_t type;
134 CHECK_DIF_OK(dif_gpio_irq_get_type(gpio_ctx.gpio, irq, &type));
135 if (type == kDifIrqTypeEvent) {
136 CHECK_DIF_OK(dif_gpio_irq_acknowledge(gpio_ctx.gpio, irq));
137 }
138
139 // Complete the IRQ at the PLIC.
140 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
141 plic_irq_id));
142}
143
144void isr_testutils_pwrmgr_isr(
145 plic_isr_ctx_t plic_ctx, pwrmgr_isr_ctx_t pwrmgr_ctx,
146 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
147 dif_pwrmgr_irq_t *irq_serviced) {
148
149 // Claim the IRQ at the PLIC.
150 dif_rv_plic_irq_id_t plic_irq_id;
151 CHECK_DIF_OK(
152 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
153
154 // Get the peripheral the IRQ belongs to.
155 *peripheral_serviced = (top_englishbreakfast_plic_peripheral_t)
156 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
157
158 // Get the IRQ that was fired from the PLIC IRQ ID.
159 dif_pwrmgr_irq_t irq =
160 (dif_pwrmgr_irq_t)(plic_irq_id - pwrmgr_ctx.plic_pwrmgr_start_irq_id);
161 *irq_serviced = irq;
162
163 // Check if it is supposed to be the only IRQ fired.
164 if (pwrmgr_ctx.is_only_irq) {
166 CHECK_DIF_OK(dif_pwrmgr_irq_get_state(pwrmgr_ctx.pwrmgr, &snapshot));
167 CHECK(snapshot == (dif_pwrmgr_irq_state_snapshot_t)(1 << irq),
168 "Only pwrmgr IRQ %d expected to fire. Actual IRQ state = %x", irq,
169 snapshot);
170 }
171
172 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
173 dif_irq_type_t type;
174 CHECK_DIF_OK(dif_pwrmgr_irq_get_type(pwrmgr_ctx.pwrmgr, irq, &type));
175 if (type == kDifIrqTypeEvent) {
176 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(pwrmgr_ctx.pwrmgr, irq));
177 }
178
179 // Complete the IRQ at the PLIC.
180 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
181 plic_irq_id));
182}
183
184void isr_testutils_rv_timer_isr(
185 plic_isr_ctx_t plic_ctx, rv_timer_isr_ctx_t rv_timer_ctx,
186 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
187 dif_rv_timer_irq_t *irq_serviced) {
188
189 // Claim the IRQ at the PLIC.
190 dif_rv_plic_irq_id_t plic_irq_id;
191 CHECK_DIF_OK(
192 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
193
194 // Get the peripheral the IRQ belongs to.
195 *peripheral_serviced = (top_englishbreakfast_plic_peripheral_t)
196 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
197
198 // Get the IRQ that was fired from the PLIC IRQ ID.
199 dif_rv_timer_irq_t irq =
200 (dif_rv_timer_irq_t)(plic_irq_id -
201 rv_timer_ctx.plic_rv_timer_start_irq_id);
202 *irq_serviced = irq;
203
204 // Check if it is supposed to be the only IRQ fired.
205 if (rv_timer_ctx.is_only_irq) {
207 CHECK_DIF_OK(dif_rv_timer_irq_get_state(rv_timer_ctx.rv_timer,
208 plic_ctx.hart_id, &snapshot));
209 CHECK(snapshot == (dif_rv_timer_irq_state_snapshot_t)(1 << irq),
210 "Only rv_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
211 snapshot);
212 }
213
214 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
215 dif_irq_type_t type;
216 CHECK_DIF_OK(dif_rv_timer_irq_get_type(rv_timer_ctx.rv_timer, irq, &type));
217 if (type == kDifIrqTypeEvent) {
218 CHECK_DIF_OK(dif_rv_timer_irq_acknowledge(rv_timer_ctx.rv_timer, irq));
219 }
220
221 // Complete the IRQ at the PLIC.
222 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
223 plic_irq_id));
224}
225
226void isr_testutils_spi_device_isr(
227 plic_isr_ctx_t plic_ctx, spi_device_isr_ctx_t spi_device_ctx,
228 bool mute_status_irq,
229 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
230 dif_spi_device_irq_t *irq_serviced) {
231
232 // Claim the IRQ at the PLIC.
233 dif_rv_plic_irq_id_t plic_irq_id;
234 CHECK_DIF_OK(
235 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
236
237 // Get the peripheral the IRQ belongs to.
238 *peripheral_serviced = (top_englishbreakfast_plic_peripheral_t)
239 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
240
241 // Get the IRQ that was fired from the PLIC IRQ ID.
242 dif_spi_device_irq_t irq =
243 (dif_spi_device_irq_t)(plic_irq_id -
244 spi_device_ctx.plic_spi_device_start_irq_id);
245 *irq_serviced = irq;
246
247 // Check if it is supposed to be the only IRQ fired.
248 if (spi_device_ctx.is_only_irq) {
250 CHECK_DIF_OK(
251 dif_spi_device_irq_get_state(spi_device_ctx.spi_device, &snapshot));
252 CHECK(snapshot == (dif_spi_device_irq_state_snapshot_t)(1 << irq),
253 "Only spi_device 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(
260 dif_spi_device_irq_get_type(spi_device_ctx.spi_device, irq, &type));
261 if (type == kDifIrqTypeEvent) {
262 CHECK_DIF_OK(
263 dif_spi_device_irq_acknowledge(spi_device_ctx.spi_device, irq));
264 } else if (mute_status_irq) {
265 CHECK_DIF_OK(dif_spi_device_irq_set_enabled(spi_device_ctx.spi_device, irq,
267 }
268
269 // Complete the IRQ at the PLIC.
270 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
271 plic_irq_id));
272}
273
274void isr_testutils_spi_host_isr(
275 plic_isr_ctx_t plic_ctx, spi_host_isr_ctx_t spi_host_ctx,
276 bool mute_status_irq,
277 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
278 dif_spi_host_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_englishbreakfast_plic_peripheral_t)
287 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
288
289 // Get the IRQ that was fired from the PLIC IRQ ID.
290 dif_spi_host_irq_t irq =
291 (dif_spi_host_irq_t)(plic_irq_id -
292 spi_host_ctx.plic_spi_host_start_irq_id);
293 *irq_serviced = irq;
294
295 // Check if it is supposed to be the only IRQ fired.
296 if (spi_host_ctx.is_only_irq) {
298 CHECK_DIF_OK(dif_spi_host_irq_get_state(spi_host_ctx.spi_host, &snapshot));
299 CHECK(snapshot == (dif_spi_host_irq_state_snapshot_t)(1 << irq),
300 "Only spi_host IRQ %d expected to fire. Actual IRQ state = %x", irq,
301 snapshot);
302 }
303
304 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
305 dif_irq_type_t type;
306 CHECK_DIF_OK(dif_spi_host_irq_get_type(spi_host_ctx.spi_host, irq, &type));
307 if (type == kDifIrqTypeEvent) {
308 CHECK_DIF_OK(dif_spi_host_irq_acknowledge(spi_host_ctx.spi_host, irq));
309 } else if (mute_status_irq) {
310 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(spi_host_ctx.spi_host, irq,
312 }
313
314 // Complete the IRQ at the PLIC.
315 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
316 plic_irq_id));
317}
318
319void isr_testutils_uart_isr(
320 plic_isr_ctx_t plic_ctx, uart_isr_ctx_t uart_ctx, bool mute_status_irq,
321 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
322 dif_uart_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_englishbreakfast_plic_peripheral_t)
331 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
332
333 // Get the IRQ that was fired from the PLIC IRQ ID.
334 dif_uart_irq_t irq =
335 (dif_uart_irq_t)(plic_irq_id - uart_ctx.plic_uart_start_irq_id);
336 *irq_serviced = irq;
337
338 // Check if it is supposed to be the only IRQ fired.
339 if (uart_ctx.is_only_irq) {
341 CHECK_DIF_OK(dif_uart_irq_get_state(uart_ctx.uart, &snapshot));
342 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)(1 << irq),
343 "Only uart 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_uart_irq_get_type(uart_ctx.uart, irq, &type));
350 if (type == kDifIrqTypeEvent) {
351 CHECK_DIF_OK(dif_uart_irq_acknowledge(uart_ctx.uart, irq));
352 } else if (mute_status_irq) {
353 CHECK_DIF_OK(
354 dif_uart_irq_set_enabled(uart_ctx.uart, irq, kDifToggleDisabled));
355 }
356
357 // Complete the IRQ at the PLIC.
358 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
359 plic_irq_id));
360}
361
362void isr_testutils_usbdev_isr(
363 plic_isr_ctx_t plic_ctx, usbdev_isr_ctx_t usbdev_ctx, bool mute_status_irq,
364 top_englishbreakfast_plic_peripheral_t *peripheral_serviced,
365 dif_usbdev_irq_t *irq_serviced) {
366
367 // Claim the IRQ at the PLIC.
368 dif_rv_plic_irq_id_t plic_irq_id;
369 CHECK_DIF_OK(
370 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
371
372 // Get the peripheral the IRQ belongs to.
373 *peripheral_serviced = (top_englishbreakfast_plic_peripheral_t)
374 top_englishbreakfast_plic_interrupt_for_peripheral[plic_irq_id];
375
376 // Get the IRQ that was fired from the PLIC IRQ ID.
377 dif_usbdev_irq_t irq =
378 (dif_usbdev_irq_t)(plic_irq_id - usbdev_ctx.plic_usbdev_start_irq_id);
379 *irq_serviced = irq;
380
381 // Check if it is supposed to be the only IRQ fired.
382 if (usbdev_ctx.is_only_irq) {
384 CHECK_DIF_OK(dif_usbdev_irq_get_state(usbdev_ctx.usbdev, &snapshot));
385 CHECK(snapshot == (dif_usbdev_irq_state_snapshot_t)(1 << irq),
386 "Only usbdev IRQ %d expected to fire. Actual IRQ state = %x", irq,
387 snapshot);
388 }
389
390 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
391 dif_irq_type_t type;
392 CHECK_DIF_OK(dif_usbdev_irq_get_type(usbdev_ctx.usbdev, irq, &type));
393 if (type == kDifIrqTypeEvent) {
394 CHECK_DIF_OK(dif_usbdev_irq_acknowledge(usbdev_ctx.usbdev, irq));
395 } else if (mute_status_irq) {
396 CHECK_DIF_OK(
397 dif_usbdev_irq_set_enabled(usbdev_ctx.usbdev, irq, kDifToggleDisabled));
398 }
399
400 // Complete the IRQ at the PLIC.
401 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
402 plic_irq_id));
403}