From 9bdef35d5746b2ce5c4039816fb316c97fe9c515 Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Mon, 15 Apr 2024 13:58:20 +0200 Subject: [PATCH] Use esp-hal 0.17.0 --- Cargo.toml | 4 +- .../automated-tests/esp_now_broadcaster.rs | 4 +- esp-wifi/automated-tests/open_access_point.rs | 4 +- esp-wifi/automated-tests/test_ble.rs | 4 +- esp-wifi/automated-tests/test_connect.rs | 4 +- esp-wifi/automated-tests/test_esp_now.rs | 4 +- esp-wifi/examples/access_point.rs | 4 +- esp-wifi/examples/access_point_with_sta.rs | 4 +- esp-wifi/examples/bench.rs | 13 ++-- esp-wifi/examples/ble.rs | 8 +-- esp-wifi/examples/coex.rs | 4 +- esp-wifi/examples/dhcp.rs | 4 +- esp-wifi/examples/embassy_access_point.rs | 6 +- .../examples/embassy_access_point_with_sta.rs | 6 +- esp-wifi/examples/embassy_bench.rs | 18 ++++-- esp-wifi/examples/embassy_ble.rs | 11 ++-- esp-wifi/examples/embassy_dhcp.rs | 6 +- esp-wifi/examples/embassy_esp_now.rs | 6 +- esp-wifi/examples/embassy_esp_now_duplex.rs | 6 +- esp-wifi/examples/esp_now.rs | 4 +- esp-wifi/examples/static_ip.rs | 4 +- .../common_adapter/common_adapter_esp32h2.rs | 16 ++--- .../common_adapter/common_adapter_esp32s2.rs | 2 +- esp-wifi/src/lib.rs | 5 +- esp-wifi/src/timer/riscv.rs | 22 ++++--- esp-wifi/src/timer/timer_esp32.rs | 18 +++--- esp-wifi/src/timer/timer_esp32c2.rs | 18 +++--- esp-wifi/src/timer/timer_esp32c3.rs | 22 +++---- esp-wifi/src/timer/timer_esp32c6.rs | 22 +++---- esp-wifi/src/timer/timer_esp32h2.rs | 10 +-- esp-wifi/src/timer/timer_esp32s2.rs | 10 +-- esp-wifi/src/timer/timer_esp32s3.rs | 18 +++--- esp-wifi/src/timer/xtensa.rs | 18 +++--- smoketest.bat | 61 ++++++++++++++++++- 34 files changed, 225 insertions(+), 145 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e96d15c6..2359f237 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ debug = true [workspace.dependencies] defmt = "0.3.6" -esp-hal = { version = "0.16.1", default-features = false } +esp-hal = { version = "0.17.0", default-features = false } smoltcp = { version = "0.11.0", default-features = false, features = [ "medium-ethernet", "socket-raw", @@ -51,7 +51,7 @@ bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "93 "macros", ] } embassy-executor = { version = "0.5.0", package = "embassy-executor", features = [ - "nightly", + "task-arena-size-12288", "integrated-timers", ] } embassy-time = { version = "0.3.0" } diff --git a/esp-wifi/automated-tests/esp_now_broadcaster.rs b/esp-wifi/automated-tests/esp_now_broadcaster.rs index ddbd2627..f0a393e0 100644 --- a/esp-wifi/automated-tests/esp_now_broadcaster.rs +++ b/esp-wifi/automated-tests/esp_now_broadcaster.rs @@ -9,7 +9,7 @@ use esp_wifi::{current_millis, initialize, EspWifiInitFor}; mod examples_util; use examples_util::hal; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; #[entry] @@ -23,7 +23,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/automated-tests/open_access_point.rs b/esp-wifi/automated-tests/open_access_point.rs index af8a5478..2502021e 100644 --- a/esp-wifi/automated-tests/open_access_point.rs +++ b/esp-wifi/automated-tests/open_access_point.rs @@ -16,7 +16,7 @@ use esp_wifi::wifi::WifiApDevice; use esp_wifi::wifi_interface::WifiStack; use esp_wifi::{current_millis, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; use smoltcp::iface::SocketStorage; @@ -32,7 +32,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/automated-tests/test_ble.rs b/esp-wifi/automated-tests/test_ble.rs index 4c245d3f..f2bf94e2 100644 --- a/esp-wifi/automated-tests/test_ble.rs +++ b/esp-wifi/automated-tests/test_ble.rs @@ -14,7 +14,7 @@ use esp_backtrace as _; use esp_println::println; use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor}; use examples_util::hal; -use hal::{clock::ClockControl, peripherals::*, prelude::*, Rng}; +use hal::{clock::ClockControl, peripherals::*, prelude::*, rng::Rng}; #[path = "../../examples-util/util.rs"] mod examples_util; @@ -29,7 +29,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/automated-tests/test_connect.rs b/esp-wifi/automated-tests/test_connect.rs index 776e62ef..f795aa47 100644 --- a/esp-wifi/automated-tests/test_connect.rs +++ b/esp-wifi/automated-tests/test_connect.rs @@ -16,7 +16,7 @@ use esp_wifi::wifi::{utils::create_network_interface, WifiError}; use esp_wifi::wifi_interface::WifiStack; use esp_wifi::{current_millis, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; use smoltcp::iface::SocketStorage; @@ -45,7 +45,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/automated-tests/test_esp_now.rs b/esp-wifi/automated-tests/test_esp_now.rs index dedd4fc0..339f77fc 100644 --- a/esp-wifi/automated-tests/test_esp_now.rs +++ b/esp-wifi/automated-tests/test_esp_now.rs @@ -9,7 +9,7 @@ use esp_wifi::{initialize, EspWifiInitFor}; mod examples_util; use examples_util::hal; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; #[entry] @@ -23,7 +23,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/examples/access_point.rs b/esp-wifi/examples/access_point.rs index 537b0fd0..ada530af 100644 --- a/esp-wifi/examples/access_point.rs +++ b/esp-wifi/examples/access_point.rs @@ -16,7 +16,7 @@ use esp_wifi::wifi::WifiApDevice; use esp_wifi::wifi_interface::WifiStack; use esp_wifi::{current_millis, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; use smoltcp::iface::SocketStorage; @@ -32,7 +32,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/examples/access_point_with_sta.rs b/esp-wifi/examples/access_point_with_sta.rs index 92637646..f1b40d51 100644 --- a/esp-wifi/examples/access_point_with_sta.rs +++ b/esp-wifi/examples/access_point_with_sta.rs @@ -15,7 +15,7 @@ use esp_wifi::wifi::utils::{create_ap_sta_network_interface, ApStaInterface}; use esp_wifi::wifi_interface::WifiStack; use esp_wifi::{current_millis, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; use smoltcp::iface::SocketStorage; @@ -36,7 +36,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/examples/bench.rs b/esp-wifi/examples/bench.rs index bc6eecd7..1f86ef8f 100644 --- a/esp-wifi/examples/bench.rs +++ b/esp-wifi/examples/bench.rs @@ -15,7 +15,8 @@ use esp_wifi::wifi::{WifiError, WifiStaDevice}; use esp_wifi::wifi_interface::WifiStack; use esp_wifi::{current_millis, initialize, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::delay::Delay; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; use smoltcp::iface::SocketStorage; use smoltcp::wire::IpAddress; @@ -46,7 +47,7 @@ fn main() -> ! { let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address"); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -119,18 +120,18 @@ fn main() -> ! { let mut tx_buffer = [0u8; TX_BUFFER_SIZE]; let mut socket = wifi_stack.get_socket(&mut rx_buffer, &mut tx_buffer); - let mut delay = hal::Delay::new(&clocks); + let delay = Delay::new(&clocks); loop { test_download(server_address, &mut socket); - delay.delay_ms(3_000u32); + delay.delay_millis(3_000u32); socket.work(); test_upload(server_address, &mut socket); socket.work(); - delay.delay_ms(3_000u32); + delay.delay_millis(3_000u32); test_upload_download(server_address, &mut socket); socket.work(); - delay.delay_ms(3_000u32); + delay.delay_millis(3_000u32); } } diff --git a/esp-wifi/examples/ble.rs b/esp-wifi/examples/ble.rs index 78563fab..422976f2 100644 --- a/esp-wifi/examples/ble.rs +++ b/esp-wifi/examples/ble.rs @@ -14,7 +14,7 @@ use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor}; #[path = "../../examples-util/util.rs"] mod examples_util; use examples_util::hal; -use hal::{clock::ClockControl, peripherals::*, prelude::*, Rng, IO}; +use hal::{clock::ClockControl, gpio::IO, peripherals::*, prelude::*, rng::Rng}; #[entry] fn main() -> ! { @@ -27,7 +27,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -124,7 +124,7 @@ fn main() -> ! { loop { let mut notification = None; - if button.is_low().unwrap() && debounce_cnt > 0 { + if button.is_low() && debounce_cnt > 0 { debounce_cnt -= 1; if debounce_cnt == 0 { let mut cccd = [0u8; 1]; @@ -144,7 +144,7 @@ fn main() -> ! { } }; - if button.is_high().unwrap() { + if button.is_high() { debounce_cnt = 500; } diff --git a/esp-wifi/examples/coex.rs b/esp-wifi/examples/coex.rs index 46cbde1e..73edcdfc 100644 --- a/esp-wifi/examples/coex.rs +++ b/esp-wifi/examples/coex.rs @@ -25,7 +25,7 @@ use esp_backtrace as _; use esp_println::{print, println}; use esp_wifi::initialize; use esp_wifi::wifi::utils::create_network_interface; -use hal::{clock::ClockControl, Rng}; +use hal::{clock::ClockControl, rng::Rng}; use hal::{peripherals::Peripherals, prelude::*}; use smoltcp::{iface::SocketStorage, wire::IpAddress, wire::Ipv4Address}; @@ -43,7 +43,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/examples/dhcp.rs b/esp-wifi/examples/dhcp.rs index 6da1f4ad..0b964357 100644 --- a/esp-wifi/examples/dhcp.rs +++ b/esp-wifi/examples/dhcp.rs @@ -15,7 +15,7 @@ use esp_wifi::wifi::{WifiError, WifiStaDevice}; use esp_wifi::wifi_interface::WifiStack; use esp_wifi::{current_millis, initialize, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; use smoltcp::iface::SocketStorage; use smoltcp::wire::IpAddress; @@ -35,7 +35,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/examples/embassy_access_point.rs b/esp-wifi/examples/embassy_access_point.rs index c74a95ff..29d32a75 100644 --- a/esp-wifi/examples/embassy_access_point.rs +++ b/esp-wifi/examples/embassy_access_point.rs @@ -18,7 +18,7 @@ use esp_wifi::wifi::{AccessPointConfiguration, Configuration}; use esp_wifi::wifi::{WifiApDevice, WifiController, WifiDevice, WifiEvent, WifiState}; use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; use static_cell::make_static; @@ -33,7 +33,7 @@ async fn main(spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -49,7 +49,7 @@ async fn main(spawner: Spawner) -> ! { let (wifi_interface, controller) = esp_wifi::wifi::new_with_mode(&init, wifi, WifiApDevice).unwrap(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); embassy::init(&clocks, timer_group0); let config = Config::ipv4_static(StaticConfigV4 { diff --git a/esp-wifi/examples/embassy_access_point_with_sta.rs b/esp-wifi/examples/embassy_access_point_with_sta.rs index ecfaf8b5..922f2c04 100644 --- a/esp-wifi/examples/embassy_access_point_with_sta.rs +++ b/esp-wifi/examples/embassy_access_point_with_sta.rs @@ -20,7 +20,7 @@ use esp_wifi::wifi::{ }; use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; use static_cell::make_static; @@ -38,7 +38,7 @@ async fn main(spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -54,7 +54,7 @@ async fn main(spawner: Spawner) -> ! { let (wifi_ap_interface, wifi_sta_interface, mut controller) = esp_wifi::wifi::new_ap_sta(&init, wifi).unwrap(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); embassy::init(&clocks, timer_group0); let ap_config = Config::ipv4_static(StaticConfigV4 { diff --git a/esp-wifi/examples/embassy_bench.rs b/esp-wifi/examples/embassy_bench.rs index befc6a5c..a817ee79 100644 --- a/esp-wifi/examples/embassy_bench.rs +++ b/esp-wifi/examples/embassy_bench.rs @@ -17,7 +17,7 @@ use esp_wifi::wifi::{ClientConfiguration, Configuration, WifiStaDevice}; use esp_wifi::wifi::{WifiController, WifiDevice, WifiEvent, WifiState}; use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; use static_cell::make_static; @@ -33,6 +33,10 @@ const DOWNLOAD_PORT: u16 = 4321; const UPLOAD_PORT: u16 = 4322; const UPLOAD_DOWNLOAD_PORT: u16 = 4323; +// static buffers to not need a huge task-arena +static mut RX_BUFFER: [u8; RX_BUFFER_SIZE] = [0; RX_BUFFER_SIZE]; +static mut TX_BUFFER: [u8; TX_BUFFER_SIZE] = [0; TX_BUFFER_SIZE]; + #[main] async fn main(spawner: Spawner) -> ! { #[cfg(feature = "log")] @@ -46,7 +50,7 @@ async fn main(spawner: Spawner) -> ! { let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address"); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -62,7 +66,7 @@ async fn main(spawner: Spawner) -> ! { let (wifi_interface, controller) = esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); embassy::init(&clocks, timer_group0); let config = Config::dhcpv4(Default::default()); @@ -96,9 +100,11 @@ async fn main(spawner: Spawner) -> ! { Timer::after(Duration::from_millis(500)).await; } - let mut rx_buffer = [0; RX_BUFFER_SIZE]; - let mut tx_buffer = [0; TX_BUFFER_SIZE]; - let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer); + let mut socket = TcpSocket::new( + stack, + unsafe { &mut *core::ptr::addr_of_mut!(RX_BUFFER) }, + unsafe { &mut *core::ptr::addr_of_mut!(TX_BUFFER) }, + ); loop { let _down = test_download(server_address, &mut socket).await; diff --git a/esp-wifi/examples/embassy_ble.rs b/esp-wifi/examples/embassy_ble.rs index 460f8b38..b1298616 100644 --- a/esp-wifi/examples/embassy_ble.rs +++ b/esp-wifi/examples/embassy_ble.rs @@ -15,14 +15,15 @@ use bleps::{ gatt, }; use embassy_executor::Spawner; -use embedded_hal_async::digital::Wait; use esp_backtrace as _; use esp_println::println; use esp_wifi::{ble::controller::asynch::BleConnector, initialize, EspWifiInitFor}; #[path = "../../examples-util/util.rs"] mod examples_util; use examples_util::hal; -use hal::{clock::ClockControl, embassy, peripherals::*, prelude::*, timer::TimerGroup, Rng, IO}; +use hal::{ + clock::ClockControl, embassy, gpio::IO, peripherals::*, prelude::*, rng::Rng, timer::TimerGroup, +}; #[main] async fn main(_spawner: Spawner) -> ! { @@ -35,7 +36,7 @@ async fn main(_spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -65,7 +66,7 @@ async fn main(_spawner: Spawner) -> ! { ) .unwrap(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); embassy::init(&clocks, timer_group0); let mut bluetooth = peripherals.BT; @@ -150,7 +151,7 @@ async fn main(_spawner: Spawner) -> ! { // probably passing in the attribute server won't work? async { - pin_ref.borrow_mut().wait_for_rising_edge().await.unwrap(); + pin_ref.borrow_mut().wait_for_rising_edge().await; let mut data = [0u8; 13]; data.copy_from_slice(b"Notification0"); { diff --git a/esp-wifi/examples/embassy_dhcp.rs b/esp-wifi/examples/embassy_dhcp.rs index c069c9ce..8973b401 100644 --- a/esp-wifi/examples/embassy_dhcp.rs +++ b/esp-wifi/examples/embassy_dhcp.rs @@ -16,7 +16,7 @@ use esp_wifi::wifi::{ClientConfiguration, Configuration}; use esp_wifi::wifi::{WifiController, WifiDevice, WifiEvent, WifiStaDevice, WifiState}; use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; use static_cell::make_static; @@ -34,7 +34,7 @@ async fn main(spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -50,7 +50,7 @@ async fn main(spawner: Spawner) -> ! { let (wifi_interface, controller) = esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); embassy::init(&clocks, timer_group0); let config = Config::dhcpv4(Default::default()); diff --git a/esp-wifi/examples/embassy_esp_now.rs b/esp-wifi/examples/embassy_esp_now.rs index b1a12342..4c5e76ff 100644 --- a/esp-wifi/examples/embassy_esp_now.rs +++ b/esp-wifi/examples/embassy_esp_now.rs @@ -14,7 +14,7 @@ use esp_println::println; use esp_wifi::esp_now::{PeerInfo, BROADCAST_ADDRESS}; use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; #[main] @@ -28,7 +28,7 @@ async fn main(_spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -44,7 +44,7 @@ async fn main(_spawner: Spawner) -> ! { let mut esp_now = esp_wifi::esp_now::EspNow::new(&init, wifi).unwrap(); println!("esp-now version {}", esp_now.get_version().unwrap()); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); embassy::init(&clocks, timer_group0); let mut ticker = Ticker::every(Duration::from_secs(5)); diff --git a/esp-wifi/examples/embassy_esp_now_duplex.rs b/esp-wifi/examples/embassy_esp_now_duplex.rs index 43cdfdcb..ae7961d7 100644 --- a/esp-wifi/examples/embassy_esp_now_duplex.rs +++ b/esp-wifi/examples/embassy_esp_now_duplex.rs @@ -16,7 +16,7 @@ use esp_println::println; use esp_wifi::esp_now::{EspNowManager, EspNowReceiver, EspNowSender, PeerInfo, BROADCAST_ADDRESS}; use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; use static_cell::make_static; @@ -31,7 +31,7 @@ async fn main(spawner: Spawner) -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( @@ -47,7 +47,7 @@ async fn main(spawner: Spawner) -> ! { let esp_now = esp_wifi::esp_now::EspNow::new(&init, wifi).unwrap(); println!("esp-now version {}", esp_now.get_version().unwrap()); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); embassy::init(&clocks, timer_group0); let (manager, sender, receiver) = esp_now.split(); diff --git a/esp-wifi/examples/esp_now.rs b/esp-wifi/examples/esp_now.rs index c106d7e1..8bd58068 100644 --- a/esp-wifi/examples/esp_now.rs +++ b/esp-wifi/examples/esp_now.rs @@ -9,7 +9,7 @@ use esp_wifi::{current_millis, initialize, EspWifiInitFor}; mod examples_util; use examples_util::hal; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; #[entry] @@ -23,7 +23,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/examples/static_ip.rs b/esp-wifi/examples/static_ip.rs index 284f0388..eeb7df0f 100644 --- a/esp-wifi/examples/static_ip.rs +++ b/esp-wifi/examples/static_ip.rs @@ -16,7 +16,7 @@ use esp_wifi::wifi::{utils::create_network_interface, WifiError}; use esp_wifi::wifi_interface::WifiStack; use esp_wifi::{current_millis, EspWifiInitFor}; use hal::clock::ClockControl; -use hal::Rng; +use hal::rng::Rng; use hal::{peripherals::Peripherals, prelude::*}; use smoltcp::iface::SocketStorage; @@ -37,7 +37,7 @@ fn main() -> ! { let clocks = ClockControl::max(system.clock_control).freeze(); #[cfg(target_arch = "xtensa")] - let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; #[cfg(target_arch = "riscv32")] let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; let init = initialize( diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs index e23d0338..e64be726 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs @@ -42,14 +42,16 @@ pub(crate) unsafe fn phy_enable() { let init_data = &PHY_INIT_DATA_DEFAULT; - #[cfg(feature = "phy-enable-usb")] - { - extern "C" { - pub fn phy_bbpll_en_usb(param: bool); - } + // this would cause linker errors when the feature is activated - see https://github.com/esp-rs/esp-wifi/issues/457 - phy_bbpll_en_usb(true); - } + // #[cfg(feature = "phy-enable-usb")] + // { + // extern "C" { + // pub fn phy_bbpll_en_usb(param: bool); + // } + + // phy_bbpll_en_usb(true); + // } register_chipv7_phy( init_data, &mut cal_data as *mut _ diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs index c36e4703..01e3fb2d 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs @@ -223,6 +223,6 @@ static mut g_log_mod: i32 = 0; static mut g_log_level: i32 = 0; #[no_mangle] -pub static mut g_misc_nvs: &u32 = unsafe { &NVS }; +pub static mut g_misc_nvs: &u32 = unsafe { &*core::ptr::addr_of!(NVS) }; pub static mut NVS: u32 = 0; diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index a674fe21..e09a91aa 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -156,10 +156,11 @@ fn init_heap() { } #[cfg(any(esp32c3, esp32c2, esp32c6, esp32h2))] -pub(crate) type EspWifiTimer = Alarm; +pub(crate) type EspWifiTimer = Alarm; #[cfg(any(esp32, esp32s3, esp32s2))] -pub(crate) type EspWifiTimer = hal::timer::Timer>; +pub(crate) type EspWifiTimer = + hal::timer::Timer, esp_hal::Blocking>; #[derive(Debug, PartialEq, PartialOrd)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] diff --git a/esp-wifi/src/timer/riscv.rs b/esp-wifi/src/timer/riscv.rs index 32514171..510d1797 100644 --- a/esp-wifi/src/timer/riscv.rs +++ b/esp-wifi/src/timer/riscv.rs @@ -6,7 +6,6 @@ use crate::{ hal::{ interrupt::{self, TrapFrame}, peripherals::{self, Interrupt}, - prelude::*, riscv, systimer::{Alarm, Periodic, SystemTimer, Target}, }, @@ -19,8 +18,9 @@ use peripherals::INTPRI as SystemPeripheral; use peripherals::SYSTEM as SystemPeripheral; /// The timer responsible for time slicing. -pub type TimeBase = Alarm; -static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); +pub type TimeBase = Alarm; +static ALARM0: Mutex>>> = + Mutex::new(RefCell::new(None)); const TIMESLICE_FREQUENCY: fugit::HertzU32 = fugit::HertzU32::from_raw(crate::CONFIG.tick_rate_hz); // Time keeping @@ -31,13 +31,20 @@ pub fn setup_timer(systimer: TimeBase) { // make sure the scheduling won't start before everything is setup riscv::interrupt::disable(); - let alarm0 = systimer.into_periodic(); + let mut alarm0 = systimer.into_periodic(); alarm0.set_period(TIMESLICE_FREQUENCY.into_duration()); alarm0.clear_interrupt(); alarm0.enable_interrupt(true); critical_section::with(|cs| ALARM0.borrow_ref_mut(cs).replace(alarm0)); + unsafe { + interrupt::bind_interrupt( + Interrupt::SYSTIMER_TARGET0, + core::mem::transmute(systimer_target0 as *const ()), + ); + } + unwrap!(interrupt::enable( Interrupt::SYSTIMER_TARGET0, interrupt::Priority::Priority1, @@ -55,8 +62,7 @@ pub fn setup_multitasking() { } } -#[interrupt] -fn SYSTIMER_TARGET0(trap_frame: &mut TrapFrame) { +extern "C" fn systimer_target0(trap_frame: &mut TrapFrame) { // clear the systimer intr critical_section::with(|cs| { unwrap!(ALARM0.borrow_ref_mut(cs).as_mut()).clear_interrupt(); @@ -65,8 +71,8 @@ fn SYSTIMER_TARGET0(trap_frame: &mut TrapFrame) { task_switch(trap_frame); } -#[interrupt] -fn FROM_CPU_INTR3(trap_frame: &mut TrapFrame) { +#[no_mangle] +extern "C" fn FROM_CPU_INTR3(trap_frame: &mut TrapFrame) { unsafe { // clear FROM_CPU_INTR3 (&*SystemPeripheral::PTR) diff --git a/esp-wifi/src/timer/timer_esp32.rs b/esp-wifi/src/timer/timer_esp32.rs index 5846fb42..3a59a985 100644 --- a/esp-wifi/src/timer/timer_esp32.rs +++ b/esp-wifi/src/timer/timer_esp32.rs @@ -1,6 +1,6 @@ #[cfg(any(feature = "wifi", feature = "ble"))] #[allow(unused_imports)] -use crate::hal::{interrupt, macros::interrupt, peripherals}; +use crate::hal::{interrupt, peripherals}; pub fn setup_radio_isr() { // wifi enabled in set_isr @@ -38,8 +38,8 @@ fn Software0(_level: u32) { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_MAC() { +#[no_mangle] +extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; trace!("interrupt WIFI_MAC {:?} {:?}", fnc, arg); @@ -52,8 +52,8 @@ fn WIFI_MAC() { } #[cfg(feature = "ble")] -#[interrupt] -fn RWBT() { +#[no_mangle] +extern "C" fn RWBT() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_5; trace!("interrupt RWBT {:?} {:?}", fnc, arg); @@ -66,8 +66,8 @@ fn RWBT() { } #[cfg(feature = "ble")] -#[interrupt] -fn RWBLE() { +#[no_mangle] +extern "C" fn RWBLE() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_5; trace!("interrupt RWBLE {:?} {:?}", fnc, arg); @@ -80,8 +80,8 @@ fn RWBLE() { } #[cfg(feature = "ble")] -#[interrupt] -fn BT_BB() { +#[no_mangle] +extern "C" fn BT_BB() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_8; trace!("interrupt BT_BB {:?} {:?}", fnc, arg); diff --git a/esp-wifi/src/timer/timer_esp32c2.rs b/esp-wifi/src/timer/timer_esp32c2.rs index 5ab95ee8..452790dc 100644 --- a/esp-wifi/src/timer/timer_esp32c2.rs +++ b/esp-wifi/src/timer/timer_esp32c2.rs @@ -2,7 +2,7 @@ #[allow(unused_imports)] use crate::{ binary, - hal::{interrupt, macros::interrupt, peripherals::Interrupt}, + hal::{interrupt, peripherals::Interrupt}, }; pub fn setup_radio_isr() { @@ -21,8 +21,8 @@ pub fn setup_radio_isr() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_MAC() { +#[no_mangle] +extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -38,8 +38,8 @@ fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_PWR() { +#[no_mangle] +extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -55,8 +55,8 @@ fn WIFI_PWR() { } #[cfg(feature = "ble")] -#[interrupt] -fn LP_TIMER() { +#[no_mangle] +extern "C" fn LP_TIMER() { unsafe { trace!("LP_TIMER interrupt"); @@ -77,8 +77,8 @@ fn LP_TIMER() { } #[cfg(feature = "ble")] -#[interrupt] -fn BT_MAC() { +#[no_mangle] +extern "C" fn BT_MAC() { unsafe { trace!("BT_MAC interrupt"); diff --git a/esp-wifi/src/timer/timer_esp32c3.rs b/esp-wifi/src/timer/timer_esp32c3.rs index ce204351..d71682d3 100644 --- a/esp-wifi/src/timer/timer_esp32c3.rs +++ b/esp-wifi/src/timer/timer_esp32c3.rs @@ -2,7 +2,7 @@ #[allow(unused_imports)] use crate::{ binary, - hal::{interrupt, macros::interrupt, peripherals::Interrupt}, + hal::{interrupt, peripherals::Interrupt}, }; pub fn setup_radio_isr() { @@ -25,8 +25,8 @@ pub fn setup_radio_isr() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_MAC() { +#[no_mangle] +extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -42,8 +42,8 @@ fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_PWR() { +#[no_mangle] +extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -59,8 +59,8 @@ fn WIFI_PWR() { } #[cfg(feature = "ble")] -#[interrupt] -fn RWBT() { +#[no_mangle] +extern "C" fn RWBT() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION5; @@ -76,8 +76,8 @@ fn RWBT() { } #[cfg(feature = "ble")] -#[interrupt] -fn RWBLE() { +#[no_mangle] +extern "C" fn RWBLE() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION5; @@ -93,8 +93,8 @@ fn RWBLE() { } #[cfg(feature = "ble")] -#[interrupt] -fn BT_BB(_trap_frame: &mut crate::hal::interrupt::TrapFrame) { +#[no_mangle] +extern "C" fn BT_BB(_trap_frame: &mut crate::hal::interrupt::TrapFrame) { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION8; diff --git a/esp-wifi/src/timer/timer_esp32c6.rs b/esp-wifi/src/timer/timer_esp32c6.rs index 06232e8f..992c0b5a 100644 --- a/esp-wifi/src/timer/timer_esp32c6.rs +++ b/esp-wifi/src/timer/timer_esp32c6.rs @@ -2,7 +2,7 @@ #[allow(unused_imports)] use crate::{ binary, - hal::{interrupt, macros::interrupt, peripherals::Interrupt}, + hal::{interrupt, peripherals::Interrupt}, }; use crate::hal::peripherals; @@ -15,10 +15,10 @@ pub fn setup_radio_isr() { let interrupt_core0 = unsafe { &*peripherals::INTERRUPT_CORE0::PTR }; interrupt_core0 .wifi_bb_intr_map() - .write(|w| w.wifi_bb_intr_map().variant(31)); + .write(|w| unsafe { w.wifi_bb_intr_map().bits(31) }); interrupt_core0 .modem_peri_timeout_intr_map() - .write(|w| w.modem_peri_timeout_intr_map().variant(31)); + .write(|w| unsafe { w.modem_peri_timeout_intr_map().bits(31) }); #[cfg(feature = "ble")] { @@ -34,8 +34,8 @@ pub fn setup_radio_isr() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_MAC() { +#[no_mangle] +extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -51,8 +51,8 @@ fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_PWR() { +#[no_mangle] +extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -68,8 +68,8 @@ fn WIFI_PWR() { } #[cfg(feature = "ble")] -#[interrupt] -fn LP_TIMER() { +#[no_mangle] +extern "C" fn LP_TIMER() { unsafe { trace!("LP_TIMER interrupt"); @@ -90,8 +90,8 @@ fn LP_TIMER() { } #[cfg(feature = "ble")] -#[interrupt] -fn BT_MAC() { +#[no_mangle] +extern "C" fn BT_MAC() { unsafe { trace!("BT_MAC interrupt"); diff --git a/esp-wifi/src/timer/timer_esp32h2.rs b/esp-wifi/src/timer/timer_esp32h2.rs index 6e20bc6c..efcdbd84 100644 --- a/esp-wifi/src/timer/timer_esp32h2.rs +++ b/esp-wifi/src/timer/timer_esp32h2.rs @@ -1,7 +1,7 @@ #[cfg(any(feature = "ble"))] use crate::{ binary, - hal::{interrupt, macros::interrupt, peripherals::Interrupt}, + hal::{interrupt, peripherals::Interrupt}, }; pub fn setup_radio_isr() { @@ -19,8 +19,8 @@ pub fn setup_radio_isr() { } #[cfg(feature = "ble")] -#[interrupt] -fn LP_BLE_TIMER() { +#[no_mangle] +extern "C" fn LP_BLE_TIMER() { unsafe { trace!("LP_TIMER interrupt"); @@ -41,8 +41,8 @@ fn LP_BLE_TIMER() { } #[cfg(feature = "ble")] -#[interrupt] -fn BT_MAC() { +#[no_mangle] +extern "C" fn BT_MAC() { unsafe { trace!("BT_MAC interrupt"); diff --git a/esp-wifi/src/timer/timer_esp32s2.rs b/esp-wifi/src/timer/timer_esp32s2.rs index c789085f..c5023d23 100644 --- a/esp-wifi/src/timer/timer_esp32s2.rs +++ b/esp-wifi/src/timer/timer_esp32s2.rs @@ -1,6 +1,6 @@ #[cfg(feature = "wifi")] #[allow(unused_imports)] -use crate::hal::{interrupt, macros::interrupt, peripherals}; +use crate::hal::{interrupt, peripherals}; pub fn setup_radio_isr() { // wifi enabled in set_isr @@ -8,8 +8,8 @@ pub fn setup_radio_isr() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_MAC() { +#[no_mangle] +extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; trace!("interrupt WIFI_MAC {:?} {:?}", fnc, arg); @@ -22,8 +22,8 @@ fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_PWR() { +#[no_mangle] +extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; diff --git a/esp-wifi/src/timer/timer_esp32s3.rs b/esp-wifi/src/timer/timer_esp32s3.rs index d9a3908f..1d7c33df 100644 --- a/esp-wifi/src/timer/timer_esp32s3.rs +++ b/esp-wifi/src/timer/timer_esp32s3.rs @@ -1,6 +1,6 @@ #[cfg(any(feature = "wifi", feature = "ble"))] #[allow(unused_imports)] -use crate::hal::{interrupt, macros::interrupt, peripherals}; +use crate::hal::{interrupt, peripherals}; pub fn setup_radio_isr() { // wifi enabled in set_isr @@ -18,8 +18,8 @@ pub fn setup_radio_isr() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_MAC() { +#[no_mangle] +extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; trace!("interrupt WIFI_MAC {:?} {:?}", fnc, arg); @@ -32,8 +32,8 @@ fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_PWR() { +#[no_mangle] +extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; trace!("interrupt WIFI_PWR {:?} {:?}", fnc, arg); @@ -48,8 +48,8 @@ fn WIFI_PWR() { } #[cfg(feature = "ble")] -#[interrupt] -fn RWBLE() { +#[no_mangle] +extern "C" fn RWBLE() { critical_section::with(|_| unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_5; trace!("interrupt RWBLE {:?} {:?}", fnc, arg); @@ -61,8 +61,8 @@ fn RWBLE() { } #[cfg(feature = "ble")] -#[interrupt] -fn BT_BB() { +#[no_mangle] +extern "C" fn BT_BB() { critical_section::with(|_| unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_8; trace!("interrupt RWBT {:?} {:?}", fnc, arg); diff --git a/esp-wifi/src/timer/xtensa.rs b/esp-wifi/src/timer/xtensa.rs index 4999ad7f..7588cd0e 100644 --- a/esp-wifi/src/timer/xtensa.rs +++ b/esp-wifi/src/timer/xtensa.rs @@ -1,7 +1,5 @@ use core::cell::RefCell; -use embedded_hal::timer::CountDown; - use portable_atomic::{AtomicU32, Ordering}; use critical_section::Mutex; @@ -9,7 +7,6 @@ use critical_section::Mutex; use crate::{ hal::{ interrupt, - macros::interrupt, peripherals::{self, TIMG1}, prelude::*, timer::{Timer, Timer0}, @@ -20,9 +17,10 @@ use crate::{ }; /// The timer responsible for time slicing. -pub type TimeBase = Timer>; +pub type TimeBase = Timer, esp_hal::Blocking>; static TIMER1: Mutex>> = Mutex::new(RefCell::new(None)); -const TIMESLICE_FREQUENCY: fugit::HertzU32 = fugit::HertzU32::from_raw(crate::CONFIG.tick_rate_hz); +const TIMESLICE_FREQUENCY: fugit::HertzU64 = + fugit::HertzU64::from_raw(crate::CONFIG.tick_rate_hz as u64); // Time keeping @@ -50,6 +48,13 @@ pub fn get_systimer_count() -> u64 { } pub fn setup_timer(mut timer1: TimeBase) { + unsafe { + interrupt::bind_interrupt( + peripherals::Interrupt::TG1_T0_LEVEL, + core::mem::transmute(tg1_t0_level as *const ()), + ); + } + unwrap!(interrupt::enable( peripherals::Interrupt::TG1_T0_LEVEL, interrupt::Priority::Priority2, @@ -96,8 +101,7 @@ fn do_task_switch(context: &mut TrapFrame) { task_switch(context); } -#[interrupt] -fn TG1_T0_LEVEL(context: &mut TrapFrame) { +extern "C" fn tg1_t0_level(context: &mut TrapFrame) { do_task_switch(context); } diff --git a/smoketest.bat b/smoketest.bat index a521d848..2764c2a1 100644 --- a/smoketest.bat +++ b/smoketest.bat @@ -13,18 +13,28 @@ echo. echo Connect ESP32-C3 pause cargo +nightly esp32c3 --example ble --release --features "ble" +pause cargo +nightly esp32c3 --example embassy_ble --release --features "async,ble" +pause cargo +nightly esp32c3 --example dhcp --release --features "wifi" +pause cargo +nightly esp32c3 --example static_ip --release --features "wifi" +pause cargo +nightly esp32c3 --example embassy_dhcp --release --features "async,wifi,embassy-net" +pause echo [esp-wifi] >..\cfg.toml echo heap_size = 70000 >>..\cfg.toml cargo +nightly esp32c3 --example coex --release --features "wifi,ble,coex" +pause del /q ..\cfg.toml cargo +nightly esp32c3 --example esp_now --release --features "esp-now" +pause cargo +nightly esp32c3 --example embassy_esp_now --release --features "async,esp-now" +pause cargo +nightly esp32c3 --example access_point --release --features "wifi" +pause cargo +nightly esp32c3 --example embassy_access_point --release --features "async,wifi,embassy-net" +pause set CARGO_PROFILE_RELEASE_OPT_LEVEL=3 set CARGO_PROFILE_RELEASE_LTO=off @@ -32,15 +42,25 @@ echo. echo Connect ESP32 pause cargo +esp esp32 --example ble --release --features "ble" +pause cargo +esp esp32 --example embassy_ble --release --features "async,ble" +pause cargo +esp esp32 --example dhcp --release --features "wifi" +pause cargo +esp esp32 --example static_ip --release --features "wifi" +pause cargo +esp esp32 --example embassy_dhcp --release --features "async,wifi,embassy-net" +pause cargo +esp esp32 --example coex --release --features "wifi,ble,coex" +pause cargo +esp esp32 --example esp_now --release --features "esp-now" +pause cargo +esp esp32 --example embassy_esp_now --release --features "async,esp-now" +pause cargo +esp esp32 --example access_point --release --features "wifi" +pause cargo +esp esp32 --example embassy_access_point --release --features "async,wifi,embassy-net" +pause set CARGO_PROFILE_RELEASE_OPT_LEVEL=3 set CARGO_PROFILE_RELEASE_LTO=off @@ -48,15 +68,25 @@ echo. echo Connect ESP32-S3 pause cargo +esp esp32s3 --example ble --release --features "ble" +pause cargo +esp esp32s3 --example embassy_ble --release --features "async,ble" +pause cargo +esp esp32s3 --example dhcp --release --features "wifi" +pause cargo +esp esp32s3 --example static_ip --release --features "wifi" +pause cargo +esp esp32s3 --example embassy_dhcp --release --features "async,wifi,embassy-net" +pause cargo +esp esp32s3 --example coex --release --features "wifi,ble,coex" +pause cargo +esp esp32s3 --example esp_now --release --features "esp-now" +pause cargo +esp esp32s3 --example embassy_esp_now --release --features "async,esp-now" +pause cargo +esp esp32s3 --example access_point --release --features "wifi" +pause cargo +esp esp32s3 --example embassy_access_point --release --features "async,wifi,embassy-net" +pause set CARGO_PROFILE_RELEASE_OPT_LEVEL=2 set CARGO_PROFILE_RELEASE_LTO=off @@ -64,12 +94,19 @@ echo. echo Connect ESP32-S2 pause cargo +esp esp32s2 --example dhcp --release --features "wifi" +pause cargo +esp esp32s2 --example static_ip --release --features "wifi" +pause cargo +esp esp32s2 --example embassy_dhcp --release --features "async,wifi,embassy-net" +pause cargo +esp esp32s2 --example esp_now --release --features "esp-now" +pause cargo +esp esp32s2 --example embassy_esp_now --release --features "async,esp-now" +pause cargo +esp esp32s2 --example access_point --release --features "wifi" +pause cargo +esp esp32s2 --example embassy_access_point --release --features "async,wifi,embassy-net" +pause set CARGO_PROFILE_RELEASE_OPT_LEVEL=3 set CARGO_PROFILE_RELEASE_LTO=false @@ -77,18 +114,28 @@ echo. echo Connect ESP32-C2 pause cargo +nightly esp32c2 --example ble --release --features "ble" +pause cargo +nightly esp32c2 --example embassy_ble --release --features "async,ble" +pause cargo +nightly esp32c2 --example dhcp --release --features "wifi" +pause cargo +nightly esp32c2 --example static_ip --release --features "wifi" +pause cargo +nightly esp32c2 --example embassy_dhcp --release --features "async,wifi,embassy-net" +pause echo [esp-wifi] >..\cfg.toml echo heap_size = 70000 >>..\cfg.toml cargo +nightly esp32c2 --example coex --release --features "wifi,ble,coex" +pause del /q ..\cfg.toml cargo +nightly esp32c2 --example esp_now --release --features "esp-now" +pause cargo +nightly esp32c2 --example embassy_esp_now --release --features "async,esp-now" +pause cargo +nightly esp32c2 --example access_point --release --features "wifi" +pause cargo +nightly esp32c2 --example embassy_access_point --release --features "async,wifi,embassy-net" +pause set CARGO_PROFILE_RELEASE_OPT_LEVEL=3 set CARGO_PROFILE_RELEASE_LTO=off @@ -96,23 +143,35 @@ echo. echo Connect ESP32-C6 pause cargo +nightly esp32c6 --example ble --release --features "ble" +pause cargo +nightly esp32c6 --example embassy_ble --release --features "async,ble" +pause cargo +nightly esp32c6 --example dhcp --release --features "wifi" +pause cargo +nightly esp32c6 --example static_ip --release --features "wifi" +pause cargo +nightly esp32c6 --example embassy_dhcp --release --features "async,wifi,embassy-net" +pause echo [esp-wifi] >..\cfg.toml echo heap_size = 80000 >>..\cfg.toml echo tx_queue_size = 10 >>..\cfg.toml cargo +nightly esp32c6 --example coex --release --features "wifi,ble,coex" +pause del /q ..\cfg.toml cargo +nightly esp32c6 --example esp_now --release --features "esp-now" +pause cargo +nightly esp32c6 --example embassy_esp_now --release --features "async,esp-now" +pause cargo +nightly esp32c6 --example access_point --release --features "wifi" +pause cargo +nightly esp32c6 --example embassy_access_point --release --features "async,wifi,embassy-net" +pause set CARGO_PROFILE_RELEASE_OPT_LEVEL=3 echo. echo Connect ESP32-H2 pause cargo +nightly esp32h2 --example ble --release --no-default-features --features "ble" -cargo +nightly esp32h2 --example embassy_ble --release --no-default-features --features "async,ble" \ No newline at end of file +pause +cargo +nightly esp32h2 --example embassy_ble --release --no-default-features --features "async,ble" +pause