2023-04-13 18:42:48 +02:00
|
|
|
//! Time-related traits & structs.
|
|
|
|
//!
|
|
|
|
//! This crate contains basic definitions and utilities that can be used
|
|
|
|
//! to keep track of time.
|
2023-01-23 20:05:47 +01:00
|
|
|
|
2023-01-14 21:11:55 +01:00
|
|
|
#![no_std]
|
2023-01-23 20:05:47 +01:00
|
|
|
#![deny(missing_docs)]
|
2024-04-11 00:00:38 +02:00
|
|
|
#![allow(async_fn_in_trait)]
|
2023-01-14 21:11:55 +01:00
|
|
|
|
2023-12-04 15:53:02 +01:00
|
|
|
pub mod half_period_counter;
|
2023-01-23 20:05:47 +01:00
|
|
|
mod linked_list;
|
2024-04-11 00:00:38 +02:00
|
|
|
pub mod monotonic;
|
|
|
|
pub mod timer_queue;
|
2023-01-14 21:11:55 +01:00
|
|
|
|
2023-01-23 20:05:47 +01:00
|
|
|
/// This indicates that there was a timeout.
|
|
|
|
pub struct TimeoutError;
|
|
|
|
|
2024-04-11 00:00:38 +02:00
|
|
|
/// Re-export for macros
|
|
|
|
pub use embedded_hal;
|
|
|
|
/// Re-export for macros
|
|
|
|
pub use embedded_hal_async;
|
2023-01-23 20:05:47 +01:00
|
|
|
|
2024-04-11 00:00:38 +02:00
|
|
|
/// # 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.
|
2023-01-14 21:11:55 +01:00
|
|
|
///
|
2024-04-11 00:00:38 +02:00
|
|
|
/// **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.
|
2023-01-14 21:11:55 +01:00
|
|
|
///
|
2024-04-11 00:00:38 +02:00
|
|
|
/// **Note:** In all APIs in RTIC that use duration from this monotonic, this type will be used.
|
|
|
|
type Duration: Copy;
|
2023-01-24 11:55:48 +01:00
|
|
|
|
2024-04-11 00:00:38 +02:00
|
|
|
/// Get the current time.
|
|
|
|
fn now() -> Self::Instant;
|
2023-01-14 21:11:55 +01:00
|
|
|
|
2024-04-11 00:00:38 +02:00
|
|
|
/// Delay for some duration of time.
|
|
|
|
async fn delay(duration: Self::Duration);
|
2023-01-14 21:11:55 +01:00
|
|
|
|
2024-04-11 00:00:38 +02:00
|
|
|
/// Delay to some specific time instant.
|
|
|
|
async fn delay_until(instant: Self::Instant);
|
2023-01-14 21:11:55 +01:00
|
|
|
|
2023-01-23 20:05:47 +01:00
|
|
|
/// Timeout at a specific time.
|
2024-04-11 00:00:38 +02:00
|
|
|
async fn timeout_at<F: core::future::Future>(
|
|
|
|
instant: Self::Instant,
|
2023-01-23 20:05:47 +01:00
|
|
|
future: F,
|
2024-04-11 00:00:38 +02:00
|
|
|
) -> Result<F::Output, TimeoutError>;
|
2023-01-14 21:11:55 +01:00
|
|
|
|
2024-04-11 00:00:38 +02:00
|
|
|
/// Timeout after a specific duration.
|
|
|
|
async fn timeout_after<F: core::future::Future>(
|
|
|
|
duration: Self::Duration,
|
2023-01-23 20:05:47 +01:00
|
|
|
future: F,
|
2024-04-11 00:00:38 +02:00
|
|
|
) -> Result<F::Output, TimeoutError>;
|
2023-01-14 21:11:55 +01:00
|
|
|
}
|