mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
8c23e178f3
* Rework timer_queue and monotonic architecture Goals: * make Monotonic purely internal * make Monotonic purely tick passed, no fugit involved * create a wrapper struct in the user's code via a macro that then converts the "now" from the tick based monotonic to a fugit based timestamp We need to proxy the delay functions of the timer queue anyway, so we could simply perform the conversion in those proxy functions. * Update cargo.lock * Update readme of rtic-time * CI: ESP32: Redact esp_image: Too volatile * Fixup: Changelog double entry rebase mistake --------- Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
64 lines
1.9 KiB
Rust
64 lines
1.9 KiB
Rust
//! Time-related traits & structs.
|
|
//!
|
|
//! This crate contains basic definitions and utilities that can be used
|
|
//! to keep track of time.
|
|
|
|
#![no_std]
|
|
#![deny(missing_docs)]
|
|
#![allow(async_fn_in_trait)]
|
|
|
|
pub mod half_period_counter;
|
|
mod linked_list;
|
|
pub mod monotonic;
|
|
pub mod timer_queue;
|
|
|
|
/// This indicates that there was a timeout.
|
|
pub struct TimeoutError;
|
|
|
|
/// Re-export for macros
|
|
pub use embedded_hal;
|
|
/// Re-export for macros
|
|
pub use embedded_hal_async;
|
|
|
|
/// # A monotonic clock / counter definition.
|
|
///
|
|
/// ## Correctness
|
|
///
|
|
/// The trait enforces that proper time-math is implemented between `Instant` and `Duration`. This
|
|
/// is a requirement on the time library that the user chooses to use.
|
|
pub trait Monotonic {
|
|
/// The type for instant, defining an instant in time.
|
|
///
|
|
/// **Note:** In all APIs in RTIC that use instants from this monotonic, this type will be used.
|
|
type Instant: Ord
|
|
+ Copy
|
|
+ core::ops::Add<Self::Duration, Output = Self::Instant>
|
|
+ core::ops::Sub<Self::Duration, Output = Self::Instant>
|
|
+ core::ops::Sub<Self::Instant, Output = Self::Duration>;
|
|
|
|
/// The type for duration, defining a duration of time.
|
|
///
|
|
/// **Note:** In all APIs in RTIC that use duration from this monotonic, this type will be used.
|
|
type Duration: Copy;
|
|
|
|
/// Get the current time.
|
|
fn now() -> Self::Instant;
|
|
|
|
/// Delay for some duration of time.
|
|
async fn delay(duration: Self::Duration);
|
|
|
|
/// Delay to some specific time instant.
|
|
async fn delay_until(instant: Self::Instant);
|
|
|
|
/// Timeout at a specific time.
|
|
async fn timeout_at<F: core::future::Future>(
|
|
instant: Self::Instant,
|
|
future: F,
|
|
) -> Result<F::Output, TimeoutError>;
|
|
|
|
/// Timeout after a specific duration.
|
|
async fn timeout_after<F: core::future::Future>(
|
|
duration: Self::Duration,
|
|
future: F,
|
|
) -> Result<F::Output, TimeoutError>;
|
|
}
|