Fix mono delay (#843)

* rtic-time: Compenstate for timer uncertainty

* Update changelog and incorrect cargo.lock in an example

* Fix Monotonic impls

* Fix tests

* Fix other monotonics, again

* Update changelog

* Fix example

* Fix DelayUs and DelayMs impls

* Minor coding style fix in u64 conversions

* Fix all changelogs

* Fix changelog

* Fix blocking DelayUs

* Minor monotonic rework

* Add delay precision test

* Add more tests

* Add rust-version tags to Cargo.toml

* Fix imxrt, rp2040 and systick timer

* Fix more monotonics

* Fix systick monotonic

* Some reverts

* Fix imxrt

* Fix nrf

* Fix rp2040

* Fix stm32

* Fix systick

* Fix rtic-time tests

* Bump to e-h.rc2

* Apply e-h.rc2 fixes to rtic-time

* Apply fixes from arbiter

* Fix clippy warning

* Minor beautification

* Revert previous changes

* Fix variable name

* Add blocking tests, but disable them by default
This commit is contained in:
Finomnis 2023-12-01 08:59:22 +01:00 committed by GitHub
parent 9f5820da1d
commit 612a47ef4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 560 additions and 141 deletions

View file

@ -17,7 +17,7 @@ static NOW: Mutex<Option<Instant>> = Mutex::new(None);
pub struct Duration(u64);
impl Duration {
pub fn from_ticks(millis: u64) -> Self {
pub const fn from_ticks(millis: u64) -> Self {
Self(millis)
}
@ -161,6 +161,7 @@ impl TestMono {
impl Monotonic for TestMono {
const ZERO: Self::Instant = Instant::ZERO;
const TICK_PERIOD: Self::Duration = Duration::from_ticks(1);
type Instant = Instant;
@ -210,7 +211,8 @@ fn timer_queue() {
let elapsed = start.elapsed().as_ticks();
println!("{total_millis} ticks delay reached after {elapsed} ticks");
if elapsed != total_millis {
// Expect a delay of one longer, to compensate for timer uncertainty
if elapsed != total_millis + 1 {
panic!(
"{total_millis} ticks delay was not on time ({elapsed} ticks passed instead)"
);
@ -263,25 +265,25 @@ fn timer_queue() {
if Instant::now() == 0.into() {
// First, we want to be waiting for our 300 tick delay
assert_eq!(TestMono::compare(), Some(300.into()));
assert_eq!(TestMono::compare(), Some(301.into()));
}
if Instant::now() == 100.into() {
// After 100 ticks, we enqueue a new delay that is supposed to last
// until the 200-tick-mark
assert_eq!(TestMono::compare(), Some(200.into()));
assert_eq!(TestMono::compare(), Some(201.into()));
}
if Instant::now() == 200.into() {
if Instant::now() == 201.into() {
// After 200 ticks, we dequeue the 200-tick-mark delay and
// requeue the 300 tick delay
assert_eq!(TestMono::compare(), Some(300.into()));
assert_eq!(TestMono::compare(), Some(301.into()));
}
if Instant::now() == 300.into() {
if Instant::now() == 301.into() {
// After 300 ticks, we dequeue the 300-tick-mark delay and
// go to the 400 tick delay that is already enqueued
assert_eq!(TestMono::compare(), Some(400.into()));
assert_eq!(TestMono::compare(), Some(401.into()));
}
}