Skip to content

Commit

Permalink
s/uptime/now/g
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Sep 5, 2024
1 parent e1ab580 commit caf5872
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 48 deletions.
6 changes: 3 additions & 3 deletions esp-hal-embassy/src/time_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use embassy_time_driver::{AlarmHandle, Driver};
use esp_hal::{
interrupt::{InterruptHandler, Priority},
prelude::*,
time::uptime,
time::now,
timer::{ErasedTimer, OneShotTimer},
};

Expand Down Expand Up @@ -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() };
Expand All @@ -130,7 +130,7 @@ impl EmbassyTimer {

impl Driver for EmbassyTimer {
fn now(&self) -> u64 {
uptime().ticks()
now().ticks()
}

unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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)
- `Input`, `Output`, `OutputOpenDrain` and `Flex` are now type-erased by default. Use the new `new_typed` constructor to keep using the ZST pin types. (#2075)
- 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
- SHA driver can now be safely used in multiple contexts concurrently (#2049)
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/MIGRATING-0.20.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ let pin = Input::new_typed(io.gpio0); // pin will have the type `Input<'some, Gp

## `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;
```
10 changes: 5 additions & 5 deletions esp-hal/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! ## Overview
//!
//! The Delay driver provides blocking delay functionalities using the
//! [current_time] function.
//! [now] function.
//!
//! ## Configuration
//!
Expand Down Expand Up @@ -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
//! [now]: crate::time::now
pub use fugit::MicrosDurationU64;

Expand Down Expand Up @@ -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 {}
}
Expand All @@ -101,12 +101,12 @@ impl Delay {
}

fn elapsed_since(start: fugit::Instant<u64, 1, 1_000_000>) -> MicrosDurationU64 {
let now = crate::time::uptime();
let now = crate::time::now();

if start.ticks() <= now.ticks() {
now - start
} else {
// current_time specifies at least 7 happy years, let's ignore this issue for
// now specifies at least 7 happy years, let's ignore this issue for
// now.
panic!("Time has wrapped around, which we currently don't handle");
}
Expand Down
9 changes: 4 additions & 5 deletions esp-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ pub struct Config {
///
/// This function sets up the CPU clock and returns the peripherals and clocks.
pub fn init(config: Config) -> Peripherals {
use self::peripherals::*;
let peripherals = Peripherals::take();
let mut peripherals = Peripherals::take();

Clocks::init(config.cpu_clock);

Expand All @@ -745,15 +744,15 @@ pub fn init(config: Config) -> Peripherals {
crate::time::time_init();

// RTC domain must be enabled before we try to disable
let mut rtc = crate::rtc_cntl::Rtc::new(unsafe { LPWR::steal() });
let mut rtc = crate::rtc_cntl::Rtc::new(&mut peripherals.LPWR);
#[cfg(not(any(esp32, esp32s2)))]
rtc.swd.disable();
rtc.rwdt.disable();

unsafe {
crate::timer::timg::Wdt::<TIMG0, crate::Blocking>::set_wdt_enabled(false);
crate::timer::timg::Wdt::<self::peripherals::TIMG0, Blocking>::set_wdt_enabled(false);
#[cfg(timg1)]
crate::timer::timg::Wdt::<TIMG1, crate::Blocking>::set_wdt_enabled(false);
crate::timer::timg::Wdt::<self::peripherals::TIMG1, Blocking>::set_wdt_enabled(false);
}

peripherals
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/time.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand All @@ -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<u64, 1, 1_000_000> {
pub fn now() -> fugit::Instant<u64, 1, 1_000_000> {
#[cfg(esp32)]
let (ticks, div) = {
// on ESP32 use LACT
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/timer/systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<'d> SystemTimer<'d> {

/// Create a new instance.
pub fn new(_systimer: impl Peripheral<P = SYSTIMER> + 'd) -> Self {
// Don't reset Systimer as it will break `current_time`, only enable it
// Don't reset Systimer as it will break `time::now`, only enable it
PeripheralClockControl::enable(PeripheralEnable::Systimer);

#[cfg(soc_etm)]
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/timer/timg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl TimerGroupInstance for TIMG0 {
}

fn reset_peripheral() {
// for TIMG0 do nothing for now because the reset breaks `current_time`
// for TIMG0 do nothing for now because the reset breaks `time::now`
}

#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/src/timer/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/src/timer/xtensa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/timer_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions hil-test/tests/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -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!(
Expand Down
24 changes: 12 additions & 12 deletions hil-test/tests/embassy_timers_executors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -64,11 +64,11 @@ mod test_cases {
pub fn run_test_periodic_timer<T: esp_hal::timer::Timer>(timer: impl Peripheral<P = T>) {
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!(
Expand All @@ -81,9 +81,9 @@ mod test_cases {
pub fn run_test_oneshot_timer<T: esp_hal::timer::Timer>(timer: impl Peripheral<P = T>) {
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!(
Expand All @@ -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!(
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions hil-test/tests/get_time.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! current_time Test
//! time::now Test
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3

Expand All @@ -13,9 +13,9 @@ struct Context {
}

fn time_moves_forward_during<F: FnOnce(Context)>(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);
}
Expand All @@ -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);
Expand Down

0 comments on commit caf5872

Please sign in to comment.