diff --git a/esp-hal-embassy/src/time_driver.rs b/esp-hal-embassy/src/time_driver.rs index e384666c23c..4303e56af4d 100644 --- a/esp-hal-embassy/src/time_driver.rs +++ b/esp-hal-embassy/src/time_driver.rs @@ -5,7 +5,7 @@ use embassy_time_driver::{AlarmHandle, Driver}; use esp_hal::{ interrupt::{InterruptHandler, Priority}, prelude::*, - time::uptime, + time::now, timer::{ErasedTimer, OneShotTimer}, }; @@ -119,7 +119,7 @@ impl EmbassyTimer { } fn arm(timer: &mut Timer, timestamp: u64) { - let now = uptime().duration_since_epoch(); + let now = now().duration_since_epoch(); let ts = timestamp.micros(); // if the TS is already in the past make the timer fire immediately let timeout = if ts > now { ts - now } else { 0.micros() }; @@ -130,7 +130,7 @@ impl EmbassyTimer { impl Driver for EmbassyTimer { fn now(&self) -> u64 { - uptime().ticks() + now().ticks() } unsafe fn allocate_alarm(&self) -> Option { diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index f10b3077453..01bcbcf81ae 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Delay::new()` is now a `const` function (#1999) - You can now create an `AnyPin` out of an `ErasedPin`. (#2072) -- To avoid confusion with the `Rtc::current_time` wall clock time APIs, we've renamed `esp_hal::time::current_time` to `esp_hal::time::uptime()`. (#2091) +- To avoid confusion with the `Rtc::current_time` wall clock time APIs, we've renamed `esp_hal::time::current_time` to `esp_hal::time::now`. (#2091) ### Fixed diff --git a/esp-hal/MIGRATING-0.20.md b/esp-hal/MIGRATING-0.20.md index bc3a690fc41..61a72f2e595 100644 --- a/esp-hal/MIGRATING-0.20.md +++ b/esp-hal/MIGRATING-0.20.md @@ -44,9 +44,9 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c ## `esp_hal::time::current_time` rename -To avoid confusion with the `Rtc::current_time` wall clock time APIs, we've renamed `esp_hal::time::current_time` to `esp_hal::time::uptime()`. +To avoid confusion with the `Rtc::current_time` wall clock time APIs, we've renamed `esp_hal::time::current_time` to `esp_hal::time::now()`. ```diff - use esp_hal::time::current_time; -+ use esp_hal::time::uptime; ++ use esp_hal::time::now; ``` diff --git a/esp-hal/src/delay.rs b/esp-hal/src/delay.rs index f52880c4b98..cae279c4da1 100644 --- a/esp-hal/src/delay.rs +++ b/esp-hal/src/delay.rs @@ -31,7 +31,7 @@ //! [DelayMs]: embedded_hal_02::blocking::delay::DelayMs //! [DelayUs]: embedded_hal_02::blocking::delay::DelayUs //! [embedded-hal]: https://docs.rs/embedded-hal/1.0.0/embedded_hal/delay/index.html -//! [current_time]: crate::time::uptime +//! [current_time]: crate::time::now pub use fugit::MicrosDurationU64; @@ -75,7 +75,7 @@ impl Delay { /// Delay for the specified time pub fn delay(&self, delay: MicrosDurationU64) { - let start = crate::time::uptime(); + let start = crate::time::now(); while elapsed_since(start) < delay {} } @@ -101,7 +101,7 @@ impl Delay { } fn elapsed_since(start: fugit::Instant) -> MicrosDurationU64 { - let now = crate::time::uptime(); + let now = crate::time::now(); if start.ticks() <= now.ticks() { now - start diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index aeb77e3f1f1..5e2663ccb14 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -751,9 +751,9 @@ pub fn init(config: Config) -> Peripherals { rtc.rwdt.disable(); unsafe { - crate::timer::timg::Wdt::::set_wdt_enabled(false); + crate::timer::timg::Wdt::::set_wdt_enabled(false); #[cfg(timg1)] - crate::timer::timg::Wdt::::set_wdt_enabled(false); + crate::timer::timg::Wdt::::set_wdt_enabled(false); } peripherals diff --git a/esp-hal/src/time.rs b/esp-hal/src/time.rs index f801c136395..6e8b16ef521 100644 --- a/esp-hal/src/time.rs +++ b/esp-hal/src/time.rs @@ -1,6 +1,6 @@ //! # Time //! -//! The `time` module offers a way to get the system uptime. +//! The `time` module offers a way to get the system now. /// Provides time since system start in microseconds precision. /// @@ -10,7 +10,7 @@ #[cfg_attr(esp32, doc = "36_558 years")] #[cfg_attr(esp32s2, doc = "7_311 years")] #[cfg_attr(not(any(esp32, esp32s2)), doc = "more than 7 years")] -pub fn uptime() -> fugit::Instant { +pub fn now() -> fugit::Instant { #[cfg(esp32)] let (ticks, div) = { // on ESP32 use LACT diff --git a/esp-wifi/src/timer/riscv.rs b/esp-wifi/src/timer/riscv.rs index ca05936561d..7e3b0bc0d14 100644 --- a/esp-wifi/src/timer/riscv.rs +++ b/esp-wifi/src/timer/riscv.rs @@ -89,7 +89,7 @@ pub fn yield_task() { /// Current systimer count value /// A tick is 1 / 1_000_000 seconds pub fn get_systimer_count() -> u64 { - esp_hal::time::uptime().ticks() + esp_hal::time::now().ticks() } // TODO: use an Instance type instead... diff --git a/esp-wifi/src/timer/xtensa.rs b/esp-wifi/src/timer/xtensa.rs index e4447fb4472..abe045f1f1e 100644 --- a/esp-wifi/src/timer/xtensa.rs +++ b/esp-wifi/src/timer/xtensa.rs @@ -20,7 +20,7 @@ pub const TICKS_PER_SECOND: u64 = 1_000_000; /// This function must not be called in a critical section. Doing so may return /// an incorrect value. pub fn get_systimer_count() -> u64 { - esp_hal::time::uptime().ticks() + esp_hal::time::now().ticks() } pub fn setup_timer(mut timer1: TimeBase) -> Result<(), esp_hal::timer::Error> { diff --git a/examples/src/bin/timer_interrupt.rs b/examples/src/bin/timer_interrupt.rs index 99734293f6a..db8c82aa880 100644 --- a/examples/src/bin/timer_interrupt.rs +++ b/examples/src/bin/timer_interrupt.rs @@ -46,7 +46,7 @@ fn tg0_t0_level() { critical_section::with(|cs| { esp_println::println!( "Interrupt at {} ms", - esp_hal::time::uptime().duration_since_epoch().to_millis() + esp_hal::time::now().duration_since_epoch().to_millis() ); let mut timer0 = TIMER0.borrow_ref_mut(cs); diff --git a/hil-test/tests/delay.rs b/hil-test/tests/delay.rs index a3193ceaa7c..3a9b56a8f6d 100644 --- a/hil-test/tests/delay.rs +++ b/hil-test/tests/delay.rs @@ -29,9 +29,9 @@ mod tests { #[test] #[timeout(2)] fn delay_ns(mut ctx: Context) { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); ctx.delay.delay_ns(600_000_000); - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1); assert!( @@ -44,9 +44,9 @@ mod tests { #[test] #[timeout(2)] fn delay_700millis(ctx: Context) { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); ctx.delay.delay_millis(700); - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1); assert!( @@ -59,9 +59,9 @@ mod tests { #[test] #[timeout(2)] fn delay_1_500_000us(mut ctx: Context) { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); ctx.delay.delay_us(1_500_000); - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1); assert!( @@ -74,9 +74,9 @@ mod tests { #[test] #[timeout(5)] fn delay_3_000ms(mut ctx: Context) { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); ctx.delay.delay_ms(3000); - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1); assert!( diff --git a/hil-test/tests/embassy_timers_executors.rs b/hil-test/tests/embassy_timers_executors.rs index 75342dae275..4b90569143b 100644 --- a/hil-test/tests/embassy_timers_executors.rs +++ b/hil-test/tests/embassy_timers_executors.rs @@ -48,10 +48,10 @@ mod test_cases { use super::*; pub async fn run_test_one_shot_async() { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); Timer::after_millis(50).await; Timer::after_millis(30).await; - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1, "t2: {:?}, t1: {:?}", t2, t1); assert!( @@ -64,11 +64,11 @@ mod test_cases { pub fn run_test_periodic_timer(timer: impl Peripheral

) { let mut periodic = PeriodicTimer::new(timer); - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); periodic.start(100.millis()).unwrap(); nb::block!(periodic.wait()).unwrap(); - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1, "t2: {:?}, t1: {:?}", t2, t1); assert!( @@ -81,9 +81,9 @@ mod test_cases { pub fn run_test_oneshot_timer(timer: impl Peripheral

) { let timer = OneShotTimer::new(timer); - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); timer.delay_millis(50); - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1, "t2: {:?}, t1: {:?}", t2, t1); assert!( @@ -94,10 +94,10 @@ mod test_cases { } pub async fn run_join_test() { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); embassy_futures::join::join(Timer::after_millis(50), Timer::after_millis(30)).await; Timer::after_millis(50).await; - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1, "t2: {:?}, t1: {:?}", t2, t1); assert!( @@ -232,11 +232,11 @@ mod test { let outcome = async { let mut ticker = Ticker::every(Duration::from_millis(30)); - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); ticker.next().await; ticker.next().await; ticker.next().await; - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1, "t2: {:?}, t1: {:?}", t2, t1); assert!( @@ -268,13 +268,13 @@ mod test { // We are retrying 5 times because probe-rs polling RTT may introduce some // jitter. for _ in 0..5 { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); let mut ticker = Ticker::every(Duration::from_hz(100_000)); for _ in 0..2000 { ticker.next().await; } - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1, "t2: {:?}, t1: {:?}", t2, t1); let duration = (t2 - t1).to_micros(); diff --git a/hil-test/tests/get_time.rs b/hil-test/tests/get_time.rs index ba8bfd7b3fa..92985db2e8b 100644 --- a/hil-test/tests/get_time.rs +++ b/hil-test/tests/get_time.rs @@ -13,9 +13,9 @@ struct Context { } fn time_moves_forward_during(ctx: Context, f: F) { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); f(ctx); - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1); } @@ -37,9 +37,9 @@ mod tests { #[test] #[timeout(3)] fn test_current_time(ctx: Context) { - let t1 = esp_hal::time::uptime(); + let t1 = esp_hal::time::now(); ctx.delay.delay_millis(500); - let t2 = esp_hal::time::uptime(); + let t2 = esp_hal::time::now(); assert!(t2 > t1); assert!((t2 - t1).to_millis() >= 500u64);