Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fugit for timing #107

Merged
merged 8 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
introduce Clock trait
fugit only has types for Duration and Instant therefore here separate Clock trait is introduced
  • Loading branch information
andresv committed Nov 4, 2021
commit d808637db3428264ad43702a0e6614ff1cd47ab0
1 change: 1 addition & 0 deletions atat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ maintenance = { status = "actively-developed" }

[dependencies]
embedded-hal = { version = "=1.0.0-alpha.4" }
fugit = "0.3"
nb = "^1"
heapless = { version = "^0.7.0", features = ["serde"] }
serde_at = { path = "../serde_at", version = "^0.13.2-alpha.0", optional = true }
Expand Down
18 changes: 18 additions & 0 deletions atat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@ pub use queues::{ComQueue, Queues};
pub use traits::{AtatClient, AtatCmd, AtatResp, AtatUrc};
pub use urc_matcher::{DefaultUrcMatcher, UrcMatcher, UrcMatcherResult};

/// For timing `atat` uses [fugit](https://lib.rs/crates/fugit) crate which only provides`Duration` and `Instant` types.
/// It does not provide any clock or timer traits.
/// Therefore `atat` has its own `Clock` trait that provides all timing capabilities that are needed for the library.
/// User must implement this trait for the timer by itself.
pub trait Clock<const TIMER_HZ: u32> {
/// An error that might happen during waiting
type Error;

/// Return current time `Instant`
fn now(&mut self) -> fugit::TimerInstantU32<TIMER_HZ>;

/// Start countdown with a `duration`
fn start(&mut self, duration: fugit::TimerDurationU32<TIMER_HZ>) -> Result<(), Self::Error>;

/// Wait until countdown `duration` set with the `fn start` has expired
fn wait(&mut self) -> Result<(), Self::Error>;
}

/// Commands that can be sent from the client to the ingress manager, for
/// configuration after initial setup. This is also used for stuff like clearing
/// the receive buffer on command timeouts.
Expand Down