rust-embedded / riscv

Low level access to RISC-V processors
818 stars 160 forks source link

riscv: add CSR-defining macros #219

Open rmsyn opened 2 months ago

rmsyn commented 2 months ago

Adds helper macros for defining CSR types:

Related to: https://github.com/rust-embedded/riscv/issues/218

romancardenas commented 2 months ago

Thanks! I'll review it ASAP

rmsyn commented 2 months ago

Using custom types (mainly enums) for setters and getters.

We could add another branch that takes an $var_ty: ident, [$($variant:ident, $variant_val:literal),*]$(,). That would allow to define a custom enum type, and use that enum in the getters/setters.

I can try to work something out.

rmsyn commented 2 months ago

I can try to work something out.

I added the enum branches, and an extra helper macro.

Let me know what you think.

romancardenas commented 2 months ago

@rmsyn I'm on it, but macros are difficult to review... 😥

Looks great. The only thing now is that I prefer to leave some macros out of the equation, and then let us call the proper sequence of macros according to the CSR. I think this will help us in the future to deal with macros (modular vs monolithic).

Regarding from and into: if we can get help from From and TryFrom traits, I'd go for them instead of maintaining repetitive methods.

Great job!! I'll keep studying all your code 😁