riscv-rust / e310x-hal

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

Implement DelayUs #23

Open FoxyHawk opened 5 years ago

FoxyHawk commented 5 years ago

https://github.com/riscv-rust/e310x-hal/blob/f8cded2f409b737802bd9a424fdbc052db7798e7/src/delay.rs#L58

Changing 1000 by 1000000 could do it for Sleep ?

Disasm commented 5 years ago

Yes, but no. DelayUs is often used for sub-ms delays, so it's better to use something more precise. You can see one of the examples here: https://github.com/riscv-rust/riscv-rust-quickstart/blob/5ff7048687e807b52d3df0d05dd0729a7c52bf79/examples/spi_wifi.rs#L106-L113, but I'm not sure it works correctly.

FoxyHawk commented 5 years ago

At this point it relies more on the frequency than anything else. I suppose >10MHz is a non issue to get the us accuracy on a busy loop. Although it is not the same for sub MHz...

Disasm commented 5 years ago

I agree that this approach works good for >10MHz (and timer works even better for core frequency <32kHz). However, I do not see how to achieve better precision in general than with counting core clock ticks.

almindor commented 3 years ago

this PR kinda solves this but as mentioned it's low res and anything < ~30us value will just be a slight NOOP slowdown. I think we should keep this open until a higher precision DelayUs is implemented.