From 472b61b128fab8d53791a75de9e31a02f1f7720e Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Thu, 7 Sep 2023 14:03:40 +0100 Subject: [PATCH] HAL cleanups & remove example macros (#261) * use Systimer from hal where possible * Remove RTC and clocks macros in favour of hal primitives * Remove system! macro * Remove the timer macro * remove the radio macros * Make utils a single file module for remaining util items * Fix rebase issues * Remove redundant example, update esp-now examples --- esp-wifi/src/timer_esp32c2.rs | 21 ++------------------- esp-wifi/src/timer_esp32c3.rs | 21 ++------------------- esp-wifi/src/timer_esp32c6.rs | 21 ++------------------- 3 files changed, 6 insertions(+), 57 deletions(-) diff --git a/esp-wifi/src/timer_esp32c2.rs b/esp-wifi/src/timer_esp32c2.rs index 0525fc7a333..581d792b901 100644 --- a/esp-wifi/src/timer_esp32c2.rs +++ b/esp-wifi/src/timer_esp32c2.rs @@ -4,7 +4,7 @@ use crate::hal::interrupt::{self, TrapFrame}; use crate::hal::peripherals::{self, Interrupt}; use crate::hal::prelude::*; use crate::hal::riscv; -use crate::hal::systimer::{Alarm, Periodic, Target}; +use crate::hal::systimer::{Alarm, Periodic, SystemTimer, Target}; use critical_section::Mutex; use crate::{binary, preempt::preempt::task_switch}; @@ -185,22 +185,5 @@ pub fn yield_task() { /// Current systimer count value /// A tick is 1 / 16_000_000 seconds pub fn get_systimer_count() -> u64 { - critical_section::with(|_| unsafe { - let systimer = &(*peripherals::SYSTIMER::ptr()); - - systimer.unit0_op.write(|w| w.bits(1 << 30)); - - // wait for value available - loop { - let valid = (systimer.unit0_op.read().bits() >> 29) & 1; - if valid != 0 { - break; - } - } - - let value_lo = systimer.unit0_value_lo.read().bits() as u64; - let value_hi = (systimer.unit0_value_hi.read().bits() as u64) << 32; - - (value_lo | value_hi) as u64 - }) + SystemTimer::now() } diff --git a/esp-wifi/src/timer_esp32c3.rs b/esp-wifi/src/timer_esp32c3.rs index becee46dd5a..bd05624b39b 100644 --- a/esp-wifi/src/timer_esp32c3.rs +++ b/esp-wifi/src/timer_esp32c3.rs @@ -6,7 +6,7 @@ use crate::hal::interrupt::{self, TrapFrame}; use crate::hal::peripherals::{self, Interrupt}; use crate::hal::prelude::*; use crate::hal::riscv; -use crate::hal::systimer::{Alarm, Periodic, Target}; +use crate::hal::systimer::{Alarm, Periodic, SystemTimer, Target}; use crate::{binary, preempt::preempt::task_switch}; @@ -197,22 +197,5 @@ pub fn yield_task() { /// Current systimer count value /// A tick is 1 / 16_000_000 seconds pub fn get_systimer_count() -> u64 { - critical_section::with(|_| unsafe { - let systimer = &(*peripherals::SYSTIMER::ptr()); - - systimer.unit0_op.write(|w| w.bits(1 << 30)); - - // wait for value available - loop { - let valid = (systimer.unit0_op.read().bits() >> 29) & 1; - if valid != 0 { - break; - } - } - - let value_lo = systimer.unit0_value_lo.read().bits() as u64; - let value_hi = (systimer.unit0_value_hi.read().bits() as u64) << 32; - - (value_lo | value_hi) as u64 - }) + SystemTimer::now() } diff --git a/esp-wifi/src/timer_esp32c6.rs b/esp-wifi/src/timer_esp32c6.rs index 3a229072057..d9b5a156131 100644 --- a/esp-wifi/src/timer_esp32c6.rs +++ b/esp-wifi/src/timer_esp32c6.rs @@ -6,7 +6,7 @@ use crate::hal::interrupt::{self, TrapFrame}; use crate::hal::peripherals::{self, Interrupt}; use crate::hal::prelude::*; use crate::hal::riscv; -use crate::hal::systimer::{Alarm, Periodic, Target}; +use crate::hal::systimer::{Alarm, Periodic, SystemTimer, Target}; use crate::{binary, preempt::preempt::task_switch}; @@ -216,22 +216,5 @@ pub fn yield_task() { /// Current systimer count value /// A tick is 1 / 16_000_000 seconds pub fn get_systimer_count() -> u64 { - critical_section::with(|_| unsafe { - let systimer = &(*peripherals::SYSTIMER::ptr()); - - systimer.unit0_op.write(|w| w.bits(1 << 30)); - - // wait for value available - loop { - let valid = (systimer.unit0_op.read().bits() >> 29) & 1; - if valid != 0 { - break; - } - } - - let value_lo = systimer.unit0_value_lo.read().bits() as u64; - let value_hi = (systimer.unit0_value_hi.read().bits() as u64) << 32; - - (value_lo | value_hi) as u64 - }) + SystemTimer::now() }