From 19c430bfb2bc3304932a06dec54717b33cb25b0b Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Wed, 18 Sep 2024 16:00:28 +0100 Subject: [PATCH] move rtc_clk_xtal_freq_get to esp-hal --- esp-hal/src/rtc_cntl/mod.rs | 8 ++++++++ esp-hal/src/rtc_cntl/rtc/esp32c6.rs | 8 ++++---- esp-hal/src/rtc_cntl/rtc/esp32h2.rs | 13 ++++++++----- esp-ieee802154/Cargo.toml | 2 +- esp-wifi/Cargo.toml | 4 ++-- .../src/common_adapter/common_adapter_esp32c2.rs | 7 ------- .../src/common_adapter/common_adapter_esp32c6.rs | 6 ------ .../src/common_adapter/common_adapter_esp32h2.rs | 6 ------ esp-wifi/src/wifi/os_adapter.rs | 14 +++++++------- examples/src/bin/ieee802154_receive_all_frames.rs | 4 ++-- examples/src/bin/ieee802154_receive_frame.rs | 4 ++-- .../src/bin/ieee802154_send_broadcast_frame.rs | 4 ++-- examples/src/bin/ieee802154_send_frame.rs | 4 ++-- examples/src/bin/ieee802154_sniffer.rs | 4 ++-- 14 files changed, 40 insertions(+), 48 deletions(-) diff --git a/esp-hal/src/rtc_cntl/mod.rs b/esp-hal/src/rtc_cntl/mod.rs index 97d8ed95706..11a2c7a0192 100644 --- a/esp-hal/src/rtc_cntl/mod.rs +++ b/esp-hal/src/rtc_cntl/mod.rs @@ -1116,3 +1116,11 @@ pub fn get_wakeup_cause() -> SleepSource { SleepSource::Undefined } + +// libphy.a can pull this in on some chips, we provide it here in the hal +// so that either ieee or esp-wifi gets it for free without duplicating in both +#[no_mangle] +extern "C" fn rtc_clk_xtal_freq_get() -> i32 { + let xtal = RtcClock::get_xtal_freq(); + xtal.mhz() as i32 +} diff --git a/esp-hal/src/rtc_cntl/rtc/esp32c6.rs b/esp-hal/src/rtc_cntl/rtc/esp32c6.rs index 456701a936c..425570e4d08 100644 --- a/esp-hal/src/rtc_cntl/rtc/esp32c6.rs +++ b/esp-hal/src/rtc_cntl/rtc/esp32c6.rs @@ -1372,7 +1372,7 @@ impl Clock for RtcFastClock { #[allow(clippy::enum_variant_names)] #[derive(Debug, Clone, Copy, PartialEq)] /// RTC SLOW_CLK frequency values -pub(crate) enum RtcSlowClock { +pub enum RtcSlowClock { /// Select RC_SLOW_CLK as RTC_SLOW_CLK source RtcSlowClockRcSlow = 0, /// Select XTAL32K_CLK as RTC_SLOW_CLK source @@ -1426,7 +1426,7 @@ impl RtcClock { const CAL_FRACT: u32 = 19; // rtc_clk_xtal_freq_get - fn get_xtal_freq_mhz() -> u32 { + pub(crate) fn get_xtal_freq_mhz() -> u32 { let xtal_freq_reg = unsafe { lp_aon().store4().read().bits() }; // Values of RTC_XTAL_FREQ_REG and RTC_APB_FREQ_REG are stored as two copies in @@ -1447,7 +1447,7 @@ impl RtcClock { /// Get main XTAL frequency /// This is the value stored in RTC register RTC_XTAL_FREQ_REG by the /// bootloader, as passed to rtc_clk_init function. - fn get_xtal_freq() -> XtalClock { + pub fn get_xtal_freq() -> XtalClock { match Self::get_xtal_freq_mhz() { 40 => XtalClock::RtcXtalFreq40M, other => XtalClock::RtcXtalFreqOther(other), @@ -1455,7 +1455,7 @@ impl RtcClock { } /// Get the RTC_SLOW_CLK source - pub(crate) fn get_slow_freq() -> RtcSlowClock { + pub fn get_slow_freq() -> RtcSlowClock { let lp_clrst = unsafe { lp_clkrst() }; let slow_freq = lp_clrst.lp_clk_conf().read().slow_clk_sel().bits(); diff --git a/esp-hal/src/rtc_cntl/rtc/esp32h2.rs b/esp-hal/src/rtc_cntl/rtc/esp32h2.rs index 67bf9c39387..904faa2b95a 100644 --- a/esp-hal/src/rtc_cntl/rtc/esp32h2.rs +++ b/esp-hal/src/rtc_cntl/rtc/esp32h2.rs @@ -215,8 +215,9 @@ impl Clock for RtcFastClock { /// RTC SLOW_CLK frequency values #[allow(clippy::enum_variant_names)] -#[derive(Debug, Clone, Copy, PartialEq)] -pub(crate) enum RtcSlowClock { +#[derive(Debug, Clone, Copy)] +#[non_exhaustive] +pub enum RtcSlowClock { /// Select RC_SLOW_CLK as RTC_SLOW_CLK source RtcSlowClockRcSlow = 0, /// Select XTAL32K_CLK as RTC_SLOW_CLK source @@ -270,8 +271,10 @@ pub struct RtcClock; impl RtcClock { const CAL_FRACT: u32 = 19; - /// Calculate the necessary RTC_SLOW_CLK cycles to complete 1 millisecond. - fn get_xtal_freq() -> XtalClock { + /// Get main XTAL frequency. + /// This is the value stored in RTC register RTC_XTAL_FREQ_REG by the + /// bootloader, as passed to rtc_clk_init function. + pub fn get_xtal_freq() -> XtalClock { let xtal_freq_reg = unsafe { &*LP_AON::PTR }.store4().read().bits(); // Values of RTC_XTAL_FREQ_REG and RTC_APB_FREQ_REG are stored as two copies in @@ -324,7 +327,7 @@ impl RtcClock { } /// Get the RTC_SLOW_CLK source - pub(crate) fn get_slow_freq() -> RtcSlowClock { + pub fn get_slow_freq() -> RtcSlowClock { let lp_clrst = unsafe { &*LPWR::ptr() }; let slow_freq = lp_clrst.lp_clk_conf().read().slow_clk_sel().bits(); diff --git a/esp-ieee802154/Cargo.toml b/esp-ieee802154/Cargo.toml index 5774976076d..7354174b768 100644 --- a/esp-ieee802154/Cargo.toml +++ b/esp-ieee802154/Cargo.toml @@ -20,7 +20,7 @@ byte = "0.2.7" critical-section = "1.1.3" document-features = "0.2.10" esp-hal = { version = "0.20.0", path = "../esp-hal" } -esp-wifi-sys = { version = "0.5.0", git = "https://github.com/esp-rs/esp-wifi-sys", rev = "e64adcf" } +esp-wifi-sys = { version = "0.5.0", git = "https://github.com/esp-rs/esp-wifi-sys", rev = "661e948" } heapless = "0.8.0" ieee802154 = "0.6.1" log = "0.4.22" diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index ec501850d6e..2ebca45377f 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -35,7 +35,7 @@ heapless = { version = "0.8.0", default-features = false, features = [ num-derive = { version = "0.4.2" } num-traits = { version = "0.2.19", default-features = false } no-std-net = { version = "0.6.0", optional = true } -esp-wifi-sys = { version = "0.5.0", git = "https://github.com/esp-rs/esp-wifi-sys", rev = "e64adcf" } +esp-wifi-sys = { version = "0.5.0", git = "https://github.com/esp-rs/esp-wifi-sys", rev = "661e948" } embassy-sync = { version = "0.6.0", optional = true } embassy-futures = { version = "0.1.1", optional = true } embassy-net-driver = { version = "0.2.0", optional = true } @@ -127,7 +127,7 @@ embassy-net = ["dep:embassy-net-driver", "async"] coex = [] ## Logs the WiFi logs from the driver at log level info (needs a nightly-compiler) -binary-logs = [] +binary-logs = ["esp-wifi-sys/binary-logs"] ## Dumps packet info at log level info dump-packets = [] diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs index c79265f60f7..53906b02527 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs @@ -137,10 +137,3 @@ pub(crate) unsafe fn phy_disable_clock() { trace!("phy_disable_clock done!"); } - -#[no_mangle] -pub extern "C" fn rtc_clk_xtal_freq_get() -> i32 { - use crate::hal::clock::Clock; - let xtal = crate::hal::rtc_cntl::RtcClock::get_xtal_freq(); - xtal.mhz() as i32 -} diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs index 612bbb77d3f..66d2bbdde39 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs @@ -130,9 +130,3 @@ pub(crate) unsafe fn phy_disable_clock() { unwrap!(RADIO_CLOCKS.as_mut()).disable(RadioPeripherals::Phy); trace!("phy_disable_clock done!"); } - -#[no_mangle] -pub extern "C" fn rtc_clk_xtal_freq_get() -> i32 { - // JUST SUPPORT 40MHz XTAL for now - 40 -} diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs index 25669989aa6..8b2e4646d90 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs @@ -133,9 +133,3 @@ pub(crate) unsafe fn phy_disable_clock() { unwrap!(RADIO_CLOCKS.as_mut()).disable(RadioPeripherals::Phy); trace!("phy_disable_clock done!"); } - -#[no_mangle] -pub extern "C" fn rtc_clk_xtal_freq_get() -> i32 { - // JUST SUPPORT 32MHz XTAL for now - 32 -} diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index 4f71b72daea..a51178993db 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -1449,8 +1449,7 @@ pub unsafe extern "C" fn log_write( format: *const crate::binary::c_types::c_char, args: ... ) { - #[allow(clippy::missing_transmute_annotations)] - crate::binary::log::syslog(level, format as *const u8, core::mem::transmute(args)); + crate::binary::log::syslog(level, format as *const u8, args); } /// ************************************************************************** @@ -1475,12 +1474,13 @@ pub unsafe extern "C" fn log_writev( level: u32, _tag: *const crate::binary::c_types::c_char, format: *const crate::binary::c_types::c_char, - args: esp_wifi_sys::include::va_list, + args: crate::binary::include::va_list, ) { - // annotations on transmute here would require different types for RISC-V and - // Xtensa - so let's allow `missing_transmute_annotations` in this case - #[allow(clippy::missing_transmute_annotations)] - crate::binary::log::syslog(level, format as *const u8, core::mem::transmute(args)); + crate::binary::log::syslog( + level, + format as *const u8, + core::mem::transmute::>(args), + ); } /// ************************************************************************** diff --git a/examples/src/bin/ieee802154_receive_all_frames.rs b/examples/src/bin/ieee802154_receive_all_frames.rs index 02a46286552..f92ff43b2f0 100644 --- a/examples/src/bin/ieee802154_receive_all_frames.rs +++ b/examples/src/bin/ieee802154_receive_all_frames.rs @@ -10,8 +10,8 @@ use esp_println::println; #[entry] fn main() -> ! { - let mut peripherals = esp_hal::init(esp_hal::Config::default()); - let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); + let peripherals = esp_hal::init(esp_hal::Config::default()); + let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, peripherals.RADIO_CLK); ieee802154.set_config(Config { channel: 15, diff --git a/examples/src/bin/ieee802154_receive_frame.rs b/examples/src/bin/ieee802154_receive_frame.rs index 53b6f5c9a65..e1ee7e164df 100644 --- a/examples/src/bin/ieee802154_receive_frame.rs +++ b/examples/src/bin/ieee802154_receive_frame.rs @@ -10,8 +10,8 @@ use esp_println::println; #[entry] fn main() -> ! { - let mut peripherals = esp_hal::init(esp_hal::Config::default()); - let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); + let peripherals = esp_hal::init(esp_hal::Config::default()); + let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, peripherals.RADIO_CLK); ieee802154.set_config(Config { channel: 15, diff --git a/examples/src/bin/ieee802154_send_broadcast_frame.rs b/examples/src/bin/ieee802154_send_broadcast_frame.rs index 7c8de3c34e4..2a01520bc44 100644 --- a/examples/src/bin/ieee802154_send_broadcast_frame.rs +++ b/examples/src/bin/ieee802154_send_broadcast_frame.rs @@ -19,11 +19,11 @@ use ieee802154::mac::{ #[entry] fn main() -> ! { - let mut peripherals = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(); - let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); + let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, peripherals.RADIO_CLK); ieee802154.set_config(Config { channel: 15, diff --git a/examples/src/bin/ieee802154_send_frame.rs b/examples/src/bin/ieee802154_send_frame.rs index 851ce007997..d6aace16928 100644 --- a/examples/src/bin/ieee802154_send_frame.rs +++ b/examples/src/bin/ieee802154_send_frame.rs @@ -19,11 +19,11 @@ use ieee802154::mac::{ #[entry] fn main() -> ! { - let mut peripherals = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let delay = Delay::new(); - let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); + let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, peripherals.RADIO_CLK); ieee802154.set_config(Config { channel: 15, diff --git a/examples/src/bin/ieee802154_sniffer.rs b/examples/src/bin/ieee802154_sniffer.rs index 6f36699e0ac..f8789241c4a 100644 --- a/examples/src/bin/ieee802154_sniffer.rs +++ b/examples/src/bin/ieee802154_sniffer.rs @@ -14,7 +14,7 @@ use esp_println::println; #[entry] fn main() -> ! { - let mut peripherals = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -50,7 +50,7 @@ fn main() -> ! { .unwrap(); let radio = peripherals.IEEE802154; - let mut ieee802154 = Ieee802154::new(radio, &mut peripherals.RADIO_CLK); + let mut ieee802154 = Ieee802154::new(radio, peripherals.RADIO_CLK); ieee802154.set_config(Config { channel,