Skip to content

Commit

Permalink
Add some config validations from esp-idf (esp-rs#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani authored and bjoernQ committed May 23, 2024
1 parent 5d91b1f commit 2588e76
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
3 changes: 3 additions & 0 deletions esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ cfg-if.workspace = true
atomic-polyfill = { workspace = true }
atomic_enum = { workspace = true }

[build-dependencies]
toml-cfg.workspace = true

[features]
default = [ "utils", "log" ]

Expand Down
73 changes: 68 additions & 5 deletions esp-wifi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ fn main() -> Result<(), String> {
Ok(level) => {
if level != "2" && level != "3" {
let message = format!(
"esp-wifi should be built with optimization level 2 or 3 - yours is {}.
"esp-wifi should be built with optimization level 2 or 3 - yours is {level}.
See https://github.com/esp-rs/esp-wifi",
level
)
.to_string();
println!("cargo:warning={}", message);
);
print_warning(message);
}
}
Err(_err) => (),
Expand All @@ -43,6 +41,8 @@ fn main() -> Result<(), String> {
#[cfg(feature = "coex")]
println!("cargo:rustc-cfg=coex");

validate_config();

let version_output = std::process::Command::new(
std::env::var_os("RUSTC").unwrap_or_else(|| std::ffi::OsString::from("rustc")),
)
Expand Down Expand Up @@ -115,3 +115,66 @@ impl PartialOrd for Version4 {
self.3.partial_cmp(&other.3)
}
}

fn print_warning(message: impl core::fmt::Display) {
println!("cargo:warning={}", message);
}

#[toml_cfg::toml_config]
/// Tunable parameters for the WiFi driver
struct Config {
#[default(5)]
rx_queue_size: usize,
#[default(3)]
tx_queue_size: usize,
#[default(10)]
static_rx_buf_num: usize,
#[default(32)]
dynamic_rx_buf_num: usize,
#[default(0)]
static_tx_buf_num: usize,
#[default(32)]
dynamic_tx_buf_num: usize,
#[default(0)]
ampdu_rx_enable: usize,
#[default(0)]
ampdu_tx_enable: usize,
#[default(0)]
amsdu_tx_enable: usize,
#[default(6)]
rx_ba_win: usize,
#[default(1)]
max_burst_size: usize,
#[default("CN")]
country_code: &'static str,
#[default(0)]
country_code_operating_class: u8,
#[default(1492)]
mtu: usize,
#[default(65536)]
heap_size: usize,
#[default(200)]
tick_rate_hz: u32,
#[default(3)]
listen_interval: u16,
#[default(6)]
beacon_timeout: u16,
#[default(300)]
ap_beacon_timeout: u16,
#[default(1)]
failure_retry_cnt: u8,
#[default(0)]
scan_method: u32,
}

fn validate_config() {
if CONFIG.rx_ba_win > CONFIG.dynamic_rx_buf_num {
print_warning(
"WiFi configuration check: rx_ba_win should not be larger than dynamic_rx_buf_num!",
);
}

if CONFIG.rx_ba_win > (CONFIG.static_rx_buf_num * 2) {
print_warning("WiFi configuration check: rx_ba_win should not be larger than double of the static_rx_buf_num!");
}
}

0 comments on commit 2588e76

Please sign in to comment.