From efcb9541e86f2423f3f59a4304d9eb4ffc7f3a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 12 Oct 2023 16:03:27 +0200 Subject: [PATCH] Extract common setup fn --- esp-wifi/src/timer/mod.rs | 9 +++++++++ esp-wifi/src/timer/riscv.rs | 5 +++-- esp-wifi/src/timer/timer_esp32.rs | 16 ++-------------- esp-wifi/src/timer/timer_esp32c2.rs | 17 ++--------------- esp-wifi/src/timer/timer_esp32c3.rs | 15 +++------------ esp-wifi/src/timer/timer_esp32c6.rs | 15 +++------------ esp-wifi/src/timer/timer_esp32s2.rs | 21 +++------------------ esp-wifi/src/timer/timer_esp32s3.rs | 16 ++-------------- esp-wifi/src/timer/xtensa.rs | 11 ++++++----- 9 files changed, 33 insertions(+), 92 deletions(-) diff --git a/esp-wifi/src/timer/mod.rs b/esp-wifi/src/timer/mod.rs index 6d037f1b..2a30228b 100644 --- a/esp-wifi/src/timer/mod.rs +++ b/esp-wifi/src/timer/mod.rs @@ -10,4 +10,13 @@ mod chip_specific; #[cfg_attr(any(esp32c2, esp32c3, esp32c6), path = "riscv.rs")] mod arch_specific; +pub use arch_specific::*; pub use chip_specific::*; + +pub fn setup_timer_isr(timebase: TimeBase) { + setup_radio_isr(); + + setup_timer(timebase); + + setup_multitasking(); +} diff --git a/esp-wifi/src/timer/riscv.rs b/esp-wifi/src/timer/riscv.rs index 6e588a7f..c278fa0a 100644 --- a/esp-wifi/src/timer/riscv.rs +++ b/esp-wifi/src/timer/riscv.rs @@ -3,7 +3,6 @@ use core::cell::RefCell; use critical_section::Mutex; use crate::{ - binary, hal::{ interrupt::{self, TrapFrame}, peripherals::{self, Interrupt}, @@ -19,13 +18,15 @@ use peripherals::INTPRI as SystemPeripheral; #[cfg(not(feature = "esp32c6"))] use peripherals::SYSTEM as SystemPeripheral; +pub type TimeBase = Alarm; + pub const TICKS_PER_SECOND: u64 = 16_000_000; const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(crate::CONFIG.tick_rate_hz); static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); -pub fn setup_timer(systimer: Alarm) { +pub fn setup_timer(systimer: TimeBase) { let alarm0 = systimer.into_periodic(); alarm0.set_period(TIMER_DELAY.into()); alarm0.clear_interrupt(); diff --git a/esp-wifi/src/timer/timer_esp32.rs b/esp-wifi/src/timer/timer_esp32.rs index 0e357883..c2a4848e 100644 --- a/esp-wifi/src/timer/timer_esp32.rs +++ b/esp-wifi/src/timer/timer_esp32.rs @@ -1,14 +1,6 @@ -use crate::hal::{ - interrupt, - macros::interrupt, - peripherals::{self, TIMG1}, - timer::{Timer, Timer0}, -}; +use crate::hal::{interrupt, macros::interrupt, peripherals}; -pub use super::arch_specific::{get_systimer_count, yield_task, TICKS_PER_SECOND}; -use super::arch_specific::{setup_multitasking, setup_timer}; - -pub fn setup_timer_isr(timg1_timer0: Timer>) { +pub fn setup_radio_isr() { #[cfg(feature = "wifi")] unwrap!(interrupt::enable( peripherals::Interrupt::WIFI_MAC, @@ -31,10 +23,6 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { interrupt::disable(crate::hal::Cpu::ProCpu, peripherals::Interrupt::ETH_MAC); interrupt::disable(crate::hal::Cpu::ProCpu, peripherals::Interrupt::UART0); } - - setup_timer(timg1_timer0); - - setup_multitasking(); } #[cfg(feature = "ble")] diff --git a/esp-wifi/src/timer/timer_esp32c2.rs b/esp-wifi/src/timer/timer_esp32c2.rs index 4308c103..6495ff6f 100644 --- a/esp-wifi/src/timer/timer_esp32c2.rs +++ b/esp-wifi/src/timer/timer_esp32c2.rs @@ -1,20 +1,9 @@ use crate::{ binary, - hal::{ - interrupt::{self, TrapFrame}, - peripherals::{self, Interrupt}, - prelude::*, - riscv, - systimer::{Alarm, Periodic, SystemTimer, Target}, - }, + hal::{interrupt, macros::interrupt, peripherals::Interrupt}, }; -pub use super::arch_specific::{get_systimer_count, yield_task, TICKS_PER_SECOND}; -use super::arch_specific::{setup_multitasking, setup_timer}; - -pub fn setup_timer_isr(systimer: Alarm) { - setup_timer(systimer); - +pub fn setup_radio_isr() { #[cfg(feature = "wifi")] { unwrap!(interrupt::enable( @@ -38,8 +27,6 @@ pub fn setup_timer_isr(systimer: Alarm) { interrupt::Priority::Priority1 )); } - - setup_multitasking(); } #[cfg(feature = "wifi")] diff --git a/esp-wifi/src/timer/timer_esp32c3.rs b/esp-wifi/src/timer/timer_esp32c3.rs index 5848d909..f131cde3 100644 --- a/esp-wifi/src/timer/timer_esp32c3.rs +++ b/esp-wifi/src/timer/timer_esp32c3.rs @@ -2,19 +2,12 @@ use crate::{ binary, hal::{ interrupt::{self, TrapFrame}, - peripherals::{self, Interrupt}, - prelude::*, - riscv, - systimer::{Alarm, Periodic, SystemTimer, Target}, + macros::interrupt, + peripherals::Interrupt, }, }; -pub use super::arch_specific::{get_systimer_count, yield_task, TICKS_PER_SECOND}; -use super::arch_specific::{setup_multitasking, setup_timer}; - -pub fn setup_timer_isr(systimer: Alarm) { - setup_timer(systimer); - +pub fn setup_radio_isr() { #[cfg(feature = "wifi")] { unwrap!(interrupt::enable( @@ -42,8 +35,6 @@ pub fn setup_timer_isr(systimer: Alarm) { interrupt::Priority::Priority1 )); } - - setup_multitasking(); } #[cfg(feature = "wifi")] diff --git a/esp-wifi/src/timer/timer_esp32c6.rs b/esp-wifi/src/timer/timer_esp32c6.rs index 57727ede..2a033455 100644 --- a/esp-wifi/src/timer/timer_esp32c6.rs +++ b/esp-wifi/src/timer/timer_esp32c6.rs @@ -1,20 +1,13 @@ use crate::{ binary, hal::{ - interrupt::{self, TrapFrame}, + interrupt, + macros::interrupt, peripherals::{self, Interrupt}, - prelude::*, - riscv, - systimer::{Alarm, Periodic, SystemTimer, Target}, }, }; -pub use super::arch_specific::{get_systimer_count, yield_task, TICKS_PER_SECOND}; -use super::arch_specific::{setup_multitasking, setup_timer}; - -pub fn setup_timer_isr(systimer: Alarm) { - setup_timer(systimer); - +pub fn setup_radio_isr() { #[cfg(feature = "wifi")] { unwrap!(interrupt::enable( @@ -48,8 +41,6 @@ pub fn setup_timer_isr(systimer: Alarm) { interrupt::Priority::Priority1 )); } - - setup_multitasking(); } #[cfg(feature = "wifi")] diff --git a/esp-wifi/src/timer/timer_esp32s2.rs b/esp-wifi/src/timer/timer_esp32s2.rs index 971ac702..25708203 100644 --- a/esp-wifi/src/timer/timer_esp32s2.rs +++ b/esp-wifi/src/timer/timer_esp32s2.rs @@ -1,19 +1,6 @@ -use crate::hal::{ - interrupt, - macros::interrupt, - peripherals::{self, TIMG1}, - timer::{Timer, Timer0}, -}; - -pub use super::arch_specific::{get_systimer_count, yield_task, TICKS_PER_SECOND}; -use super::arch_specific::{setup_multitasking, setup_timer}; - -pub fn setup_timer_isr(timg1_timer0: Timer>) { - unwrap!(interrupt::enable( - peripherals::Interrupt::TG1_T0_LEVEL, - interrupt::Priority::Priority2, - )); +use crate::hal::{interrupt, macros::interrupt, peripherals}; +pub fn setup_radio_isr() { #[cfg(feature = "wifi")] { unwrap!(interrupt::enable( @@ -26,9 +13,7 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { )); } - setup_timer(timg1_timer0); - - setup_multitasking(); + // ble not supported } #[cfg(feature = "wifi")] diff --git a/esp-wifi/src/timer/timer_esp32s3.rs b/esp-wifi/src/timer/timer_esp32s3.rs index cc82f648..ade3bc62 100644 --- a/esp-wifi/src/timer/timer_esp32s3.rs +++ b/esp-wifi/src/timer/timer_esp32s3.rs @@ -1,14 +1,6 @@ -use crate::hal::{ - interrupt, - macros::interrupt, - peripherals::{self, TIMG1}, - timer::{Timer, Timer0}, -}; +use crate::hal::{interrupt, macros::interrupt, peripherals}; -pub use super::arch_specific::{get_systimer_count, yield_task, TICKS_PER_SECOND}; -use super::arch_specific::{setup_multitasking, setup_timer}; - -pub fn setup_timer_isr(timg1_timer0: Timer>) { +pub fn setup_radio_isr() { #[cfg(feature = "wifi")] { unwrap!(interrupt::enable( @@ -32,10 +24,6 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { interrupt::Priority::Priority1, )); } - - setup_timer(timg1_timer0); - - setup_multitasking(); } #[cfg(feature = "wifi")] diff --git a/esp-wifi/src/timer/xtensa.rs b/esp-wifi/src/timer/xtensa.rs index a155c8a4..afce7ad8 100644 --- a/esp-wifi/src/timer/xtensa.rs +++ b/esp-wifi/src/timer/xtensa.rs @@ -1,5 +1,7 @@ use core::cell::RefCell; +use critical_section::Mutex; + use crate::{ hal::{ interrupt, @@ -13,9 +15,10 @@ use crate::{ preempt::preempt::task_switch, }; use atomic_polyfill::{AtomicU32, Ordering}; -use critical_section::Mutex; -static TIMER1: Mutex>>>> = Mutex::new(RefCell::new(None)); +pub type TimeBase = Timer>; + +static TIMER1: Mutex>> = Mutex::new(RefCell::new(None)); static TIMER_OVERFLOWS: AtomicU32 = AtomicU32::new(0); @@ -41,9 +44,7 @@ pub fn get_systimer_count() -> u64 { (((overflow as u64) << 32) + counter_after as u64) * 40_000_000 / 240_000_000 } -pub fn setup_timer(timg1_timer0: Timer>) { - let mut timer1 = timg1_timer0; - +pub fn setup_timer(mut timer1: TimeBase) { unwrap!(interrupt::enable( peripherals::Interrupt::TG1_T0_LEVEL, interrupt::Priority::Priority2,