diff --git a/CHANGELOG.md b/CHANGELOG.md index b95a85ef..52e58500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Users don't need embedded-svc to control wifi anymore. The wifi trait is optionally implemented now. (#429) +- Better network performance by forced yielding of the task when buffers are full / empty. (#430) ### Removed diff --git a/esp-wifi/examples/embassy_bench.rs b/esp-wifi/examples/embassy_bench.rs index 13d1a78f..befc6a5c 100644 --- a/esp-wifi/examples/embassy_bench.rs +++ b/esp-wifi/examples/embassy_bench.rs @@ -13,8 +13,8 @@ use examples_util::hal; use embassy_time::{with_timeout, Duration, Timer}; use esp_backtrace as _; use esp_println::println; -use esp_wifi::wifi::{ClientConfiguration, Configuration}; -use esp_wifi::wifi::{WifiApDevice, WifiController, WifiDevice, WifiEvent, WifiState}; +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; @@ -60,7 +60,7 @@ async fn main(spawner: Spawner) -> ! { let wifi = peripherals.WIFI; let (wifi_interface, controller) = - esp_wifi::wifi::new_with_mode(&init, wifi, WifiApDevice).unwrap(); + esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap(); let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); embassy::init(&clocks, timer_group0); @@ -146,7 +146,7 @@ async fn connection(mut controller: WifiController<'static>) { } #[embassy_executor::task] -async fn net_task(stack: &'static Stack>) { +async fn net_task(stack: &'static Stack>) { stack.run().await } diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index 71b9d759..fc17cd9a 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -1494,6 +1494,10 @@ mod sealed { } fn tx_token(self) -> Option> { + if !self.can_send() { + crate::timer::yield_task(); + } + if self.can_send() { Some(WifiTxToken { mode: self }) } else { @@ -1503,6 +1507,12 @@ mod sealed { fn rx_token(self) -> Option<(WifiRxToken, WifiTxToken)> { let is_empty = critical_section::with(|cs| self.data_queue_rx(cs).is_empty()); + if is_empty || !self.can_send() { + crate::timer::yield_task(); + } + + let is_empty = + is_empty && critical_section::with(|cs| self.data_queue_rx(cs).is_empty()); if !is_empty { self.tx_token().map(|tx| (WifiRxToken { mode: self }, tx))