e310x-hal icon indicating copy to clipboard operation
e310x-hal copied to clipboard

Implement DelayUs

Open FoxyHawk opened this issue 6 years ago • 4 comments

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

Changing 1000 by 1000000 could do it for Sleep ?

FoxyHawk avatar Aug 26 '19 06:08 FoxyHawk

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.

Disasm avatar Aug 26 '19 08:08 Disasm

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...

FoxyHawk avatar Aug 27 '19 01:08 FoxyHawk

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.

Disasm avatar Aug 27 '19 11:08 Disasm

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.

almindor avatar Jul 12 '21 17:07 almindor