Skip to content

Commit

Permalink
HAL cleanups & remove example macros (esp-rs#261)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MabezDev authored and bjoernQ committed May 23, 2024
1 parent 298f0f2 commit 472b61b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 57 deletions.
21 changes: 2 additions & 19 deletions esp-wifi/src/timer_esp32c2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
}
21 changes: 2 additions & 19 deletions esp-wifi/src/timer_esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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()
}
21 changes: 2 additions & 19 deletions esp-wifi/src/timer_esp32c6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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()
}

0 comments on commit 472b61b

Please sign in to comment.