riscv-rust / e310x-hal

Implementation of the `embedded-hal` traits for E310x microcontrollers
17 stars 18 forks source link

Complicated read64 macro #21

Closed lukwol closed 5 years ago

lukwol commented 5 years ago

What is the reason for the following macro to be so complicated?

https://github.com/riscv-rust/e310x-hal/blob/ceb3e7f42f7ce0ef8cfef26bfd43ba5d506f7af3/src/core/clint.rs#L5

Can it be changed to this simple one line macro?

macro_rules! read64 {
    ($hi:expr, $lo:expr) => { (($hi as u64) << 32) | $lo as u64 }
}
Disasm commented 5 years ago

It is used for consistent reading of a pair of 32-bit registers. The problem is that you can't read both halves at the same time: while reading the second half, the first one can change its value. That's why you need to repeat reading until you get something consistent.

lukwol commented 5 years ago

Oh, ok that makes sense. Thank you for clarification.