rust-embedded / rust-embedded/linux-embedded-hal
DelayUs should not be implemented with thread::sleep
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 319
- Forks
- 60
- Avg merge
- 12h 31m
- Merged PRs (30d)
- 1
Description
I believe thread::sleep cannot provide microsecond precision on linux.
Failing example:
extern crate embedded_hal;
extern crate linux_embedded_hal as hal;
use embedded_hal::blocking::delay::DelayUs;
fn main() {
let us = 10u8;
let t = ::std::time::SystemTime::now();
let mut delay = hal::Delay{};
delay.delay_us(us);
println!("Expecting {}us, got {}us", us, t.elapsed().unwrap().subsec_nanos() / 1000);
}
Prints
Running `target/release/test_hal`
Expecting 10us, got 84us
What is the recommended way to get this level of precision?
As an example this very bad loop works:
pub fn delay_us(us: u32) {
let target = Instant::now() + Duration::new(0, us * 1000);
while Instant::now() < target { }
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Delay implementation and its DelayUs::delay_us entry point, then reproduce the provided Rust example on Linux to measure thread::sleep. Compare the observed timing with the requested microsecond precision and document a concrete, tested approach; done means the implementation and recommendation address the demonstrated discrepancy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, rust
- Domain
- embedded-iot, operating-systems
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100