1 /*
2  * Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _HARDWARE_HAZARD3_H
8 #define _HARDWARE_HAZARD3_H
9 
10 #include "pico.h"
11 #include "hardware/riscv.h"
12 
13 // This includes both standard and Hazard3 custom CSRs:
14 #include "hardware/regs/rvcsr.h"
15 
16 #include "hardware/hazard3/features.h"
17 #include "hardware/hazard3/instructions.h"
18 
19 /** \file hardware/hazard3.h
20  *  \defgroup hardware_hazard3 hardware_hazard3
21  *
22  * \brief Accessors for Hazard3-specific RISC-V CSRs, and intrinsics for Hazard3 custom instructions
23  *
24  */
25 
26 #ifndef __ASSEMBLER__
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #ifdef __hazard3_extension_xh3irq
33 #define hazard3_irqarray_read(csr, index) (riscv_read_set_csr(csr, (index)) >> 16)
34 #else
35 #define hazard3_irqarray_read(csr, index) static_assert(false, "Not supported: Xh3irq extension")
36 #endif
37 
38 #ifdef __hazard3_extension_xh3irq
39 #define hazard3_irqarray_write(csr, index, data) (riscv_write_csr(csr, (index) | ((uint32_t)(data) << 16)))
40 #else
41 #define hazard3_irqarray_write(csr, index, data) static_assert(false, "Not supported: Xh3irq extension")
42 #endif
43 
44 #ifdef __hazard3_extension_xh3irq
45 #define hazard3_irqarray_set(csr, index, data) (riscv_set_csr(csr, (index) | ((uint32_t)(data) << 16)))
46 #else
47 #define hazard3_irqarray_set(csr, index, data) static_assert(false, "Not supported: Xh3irq extension")
48 #endif
49 
50 #ifdef __hazard3_extension_xh3irq
51 #define hazard3_irqarray_clear(csr, index, data) (riscv_clear_csr(csr, (index) | ((uint32_t)(data) << 16)))
52 #else
53 #define hazard3_irqarray_clear(csr, index, data) static_assert(false, "Not supported: Xh3irq extension")
54 #endif
55 
56 #ifdef __cplusplus
57 }
58 #endif
59 
60 #endif
61 
62 #endif
63