use veecle_freertos_sys::bindings::{TickType_t, portMAX_DELAY, portTICK_PERIOD_MS};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Duration {
ticks: TickType_t,
}
impl Duration {
pub fn max() -> Self {
Self::infinite()
}
pub fn from_ms(milliseconds: TickType_t) -> Self {
Self::from_ticks(milliseconds / portTICK_PERIOD_MS())
}
pub fn from_ticks(ticks: TickType_t) -> Self {
Self { ticks }
}
pub fn infinite() -> Self {
Self::from_ticks(portMAX_DELAY())
}
pub fn zero() -> Self {
Self::from_ticks(0)
}
pub fn eps() -> Self {
Self::from_ticks(1)
}
pub fn ms(&self) -> TickType_t {
self.ticks * portTICK_PERIOD_MS()
}
pub fn ticks(&self) -> TickType_t {
self.ticks
}
}