Skip to content

Commit b6a63af

Browse files
committed
Add write_csr_as macro
This adds a macro to generate `write(value:T)` function for writing a structured value to a CSR.
1 parent 79d85c6 commit b6a63af

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

riscv/src/register/macros.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,34 @@ macro_rules! write_csr_rv32 {
160160
};
161161
}
162162

163+
/// `RV64`: Convenience macro to write a value with `bits` to a CSR
164+
#[macro_export]
165+
macro_rules! write_csr_as {
166+
($csr_type:ty, $csr_number:literal) => {
167+
$crate::write_csr!($csr_number);
168+
169+
/// Writes the CSR
170+
#[inline]
171+
pub fn write(value: $csr_type) {
172+
unsafe { _write(value.bits) }
173+
}
174+
};
175+
}
176+
177+
/// `RV32`: Convenience macro to write a value to a CSR register.
178+
#[macro_export]
179+
macro_rules! write_csr_as_rv32 {
180+
($csr_type:ty, $csr_number:literal) => {
181+
$crate::write_csr_rv32!($csr_number);
182+
183+
/// Writes the CSR
184+
#[inline]
185+
pub fn write(value: $csr_type) {
186+
unsafe { _write(value.bits) }
187+
}
188+
};
189+
}
190+
163191
/// `RV64`: Convenience macro to write a [`usize`] value to a CSR register.
164192
#[macro_export]
165193
macro_rules! write_csr_as_usize {

0 commit comments

Comments
 (0)