Skip to content

Commit 9c94616

Browse files
committed
Implement DelayNs for McycleDelay
1 parent 0c9b484 commit 9c94616

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

riscv/src/delay.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Delay devices and providers
22
use crate::register::mcycle;
3-
use embedded_hal::delay::DelayUs;
3+
use embedded_hal::delay::DelayNs;
44

55
/// Machine mode cycle counter (`mcycle`) as a delay provider
66
#[derive(Copy, Clone)]
@@ -19,12 +19,17 @@ impl McycleDelay {
1919
}
2020
}
2121

22-
impl DelayUs for McycleDelay {
22+
impl DelayNs for McycleDelay {
2323
#[inline]
2424
fn delay_us(&mut self, us: u32) {
25+
self.delay_ns(us * 1000)
26+
}
27+
28+
#[inline]
29+
fn delay_ns(&mut self, ns: u32) {
2530
let t0 = mcycle::read64();
26-
let us_64: u64 = us.into();
27-
let clock = (us_64 * (self.ticks_second as u64)) / 1_000_000u64;
31+
let us_64: u64 = ns.into();
32+
let clock = (us_64 * (self.ticks_second as u64)) / 1_000_000_000u64;
2833
while mcycle::read64().wrapping_sub(t0) <= clock {}
29-
}
34+
}
3035
}

0 commit comments

Comments
 (0)