diff --git a/esp-wifi/automated-tests/esp_now_broadcaster.rs b/esp-wifi/automated-tests/esp_now_broadcaster.rs index ddbd2627a75..f0a393e08f2 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 af8a547879b..2502021e0ee 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 4c245d3f07c..f2bf94e2991 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 776e62ef550..f795aa47b70 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 dedd4fc03e8..339f77fc92a 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 537b0fd0d2b..ada530af967 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 926376462f1..f1b40d51681 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 bc6eecd7e36..1f86ef8fbff 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 78563fab8f9..422976f2dbd 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 46cbde1eb52..73edcdfcd7d 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 6da1f4ad6c3..0b96435708c 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 c74a95fff2d..29d32a75f1c 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 ecfaf8b5a6c..922f2c04c38 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 befc6a5cd85..a817ee7938e 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 460f8b38f0f..b1298616223 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 c069c9ce45b..8973b401fc8 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 b1a12342926..4c5e76ff1b3 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 43cdfdcbb8f..ae7961d7491 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 c106d7e19e2..8bd58068319 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 284f03887a3..eeb7df0f118 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 e23d033819c..e64be726ecc 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 c36e4703d26..01e3fb2dab3 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 a674fe211fe..e09a91aa664 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 32514171a4b..510d179754f 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 5846fb42cea..3a59a9859e4 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 5ab95ee82fe..452790dcfb2 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 ce20435116a..d71682d3452 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 06232e8f2f5..992c0b5a7ee 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 6e20bc6c599..efcdbd84a2e 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 c789085f3fd..c5023d230ab 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 d9a3908fe9d..1d7c33dfb46 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 4999ad7f7d4..7588cd0e510 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); }