Skip to content

Commit

Permalink
Make portable-atomic optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 16, 2023
1 parent a486b18 commit 399dd7b
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ esp32s2-hal = { version = "0.13.0", default-features = false }
smoltcp = { version = "0.10.0", default-features=false, features = ["medium-ethernet", "socket-raw"] }
critical-section = "1.1.1"
portable-atomic = { version = "1.5", default-features = false }
portable_atomic_enum = "0.2.0"
portable_atomic_enum = "0.3.0"
log = "0.4.20"
embedded-svc = { version = "0.26.1", default-features = false, features = [] }
enumset = { version = "1", default-features = false }
Expand All @@ -58,7 +58,7 @@ esp-backtrace = { version = "0.9.0", features = ["panic-handler", "exception-han
embedded-hal-async = { version = "1.0.0-rc.1" }
embedded-io-async = { version = "0.6.0" }

futures-util = { version = "0.3.28", default-features = false, features = ["portable-atomic"] } # need this to activate portable-atomic on futures-util's AtomicWaker even though we don't use it
futures-util = { version = "0.3.28", default-features = false } # need this to activate portable-atomic on AtomicWaker even though we don't use it

[patch.crates-io]
esp32-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "957b232" }
Expand Down
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,30 @@ Don't use this feature if your are _not_ using USB-SERIAL-JTAG since it might re

## Features

| Feature | Meaning |
| -------------- | ---------------------------------------------------------------------------------------------------- |
| wifi-logs | logs the WiFi logs from the driver at log level info |
| dump-packets | dumps packet info at log level info |
| utils | Provide utilities for smoltcp initialization; adds `smoltcp` dependency |
| embedded-svc | Provides a (very limited) implementation of the `embedded-svc` WiFi trait |
| ble | Enable BLE support |
| wifi | Enable WiFi support |
| esp-now | Enable esp-now support |
| coex | Enable coex support |
| big-heap | Reserve more heap memory for the drivers |
| ipv4 | IPv4 support: includes `utils` feature |
| ipv6 | IPv6 support: includes `utils` feature |
| tcp | TCP socket support: includes `ipv4` feature |
| udp | UDP socket support: includes `ipv4` feature |
| igmp | IGMP (multicast) support: includes `ipv4` feature |
| dns | DNS support: includes `udp` feature |
| dhcpv4 | DHCPv4 support, both creating sockets and autoconfiguring network settings: includes `utils` feature |
| phy-enable-usb | See _USB-SERIAL-JTAG_ below |
| ps-min-modem | Enable minimum modem sleep. Only for STA mode |
| ps-max-modem | Enable maximum modem sleep. Only for STA mode |
| log | Route log output to the `log` crate |
| defmt | Add `defmt::Format` implementation |
| Feature | Meaning |
| --------------- | ---------------------------------------------------------------------------------------------------- |
| wifi-logs | logs the WiFi logs from the driver at log level info |
| dump-packets | dumps packet info at log level info |
| utils | Provide utilities for smoltcp initialization; adds `smoltcp` dependency |
| embedded-svc | Provides a (very limited) implementation of the `embedded-svc` WiFi trait |
| ble | Enable BLE support |
| wifi | Enable WiFi support |
| esp-now | Enable esp-now support |
| coex | Enable coex support |
| big-heap | Reserve more heap memory for the drivers |
| ipv4 | IPv4 support: includes `utils` feature |
| ipv6 | IPv6 support: includes `utils` feature |
| tcp | TCP socket support: includes `ipv4` feature |
| udp | UDP socket support: includes `ipv4` feature |
| igmp | IGMP (multicast) support: includes `ipv4` feature |
| dns | DNS support: includes `udp` feature |
| dhcpv4 | DHCPv4 support, both creating sockets and autoconfiguring network settings: includes `utils` feature |
| phy-enable-usb | See _USB-SERIAL-JTAG_ below |
| ps-min-modem | Enable minimum modem sleep. Only for STA mode |
| ps-max-modem | Enable maximum modem sleep. Only for STA mode |
| log | Route log output to the `log` crate |
| defmt | Add `defmt::Format` implementation |
| portable-atomic | Enables polyfilling using `portable-atomic`. Disable if you use atomic emulation trap |

When using the `dump-packets` feature you can use the extcap in `extras/esp-wifishark` to analyze the frames in Wireshark.
For more information see [extras/esp-wifishark/README.md](extras/esp-wifishark/README.md)
Expand Down
10 changes: 6 additions & 4 deletions esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ linked_list_allocator = { workspace = true }
embedded-io.workspace = true
embedded-io-async = { workspace = true, optional = true }
fugit.workspace = true
heapless = { workspace = true, default-features = false, features = ["portable-atomic"] }
heapless = { workspace = true, default-features = false }
num-derive = { workspace = true }
num-traits = { workspace = true, default-features = false }
esp-wifi-sys = { version = "0.1.0", path = "../esp-wifi-sys" }
Expand All @@ -31,7 +31,7 @@ embassy-net = { workspace = true, optional = true }
toml-cfg.workspace = true
libm.workspace = true
cfg-if.workspace = true
portable-atomic.workspace = true
portable-atomic = { workspace = true, optional = true }
portable_atomic_enum.workspace = true

# We don't use it directly but we need to enable portable-atomic on it
Expand All @@ -51,10 +51,10 @@ embedded-hal-async.workspace = true
log.workspace = true
smoltcp.workspace = true
static_cell.workspace = true
portable-atomic = { workspace = true, features = ["critical-section"] }
portable-atomic = { workspace = true, features = ["critical-section"] } # for tests/examples we use portable-atomic

[features]
default = [ "log", "ipv4", "tcp", "udp", "icmp", "igmp", "dns", "dhcpv4" ]
default = [ "log", "ipv4", "tcp", "udp", "icmp", "igmp", "dns", "dhcpv4", "portable-atomic" ]

# chip features
esp32c2 = [ "esp32c2-hal", "esp-wifi-sys/esp32c2", "esp-println/esp32c2", "esp-backtrace/esp32c2", "embassy-executor/arch-riscv32" ]
Expand Down Expand Up @@ -129,6 +129,8 @@ log = [
"esp32s3-hal?/log",
]

portable-atomic = ["dep:portable-atomic", "portable_atomic_enum/portable-atomic", "futures-util/portable-atomic", "heapless/portable-atomic"]

# These examples are used in test automation
[[example]]
name = "test_esp_now"
Expand Down
9 changes: 7 additions & 2 deletions esp-wifi/src/common_adapter/common_adapter_esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use crate::hal::prelude::ram;
use crate::hal::system::RadioClockController;
use crate::hal::system::RadioPeripherals;

use core::sync::atomic::Ordering;
use portable_atomic::AtomicU32;
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicU32, Ordering};

const SOC_PHY_DIG_REGS_MEM_SIZE: usize = 21 * 4;

Expand Down
9 changes: 7 additions & 2 deletions esp-wifi/src/common_adapter/common_adapter_esp32c2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use crate::compat::common::str_from_c;
use crate::hal::system::RadioClockController;
use crate::hal::system::RadioPeripherals;

use core::sync::atomic::Ordering;
use portable_atomic::AtomicU32;
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicU32, Ordering};

const SOC_PHY_DIG_REGS_MEM_SIZE: usize = 21 * 4;

Expand Down
9 changes: 7 additions & 2 deletions esp-wifi/src/common_adapter/common_adapter_esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use crate::compat::common::str_from_c;
use crate::hal::system::RadioClockController;
use crate::hal::system::RadioPeripherals;

use core::sync::atomic::Ordering;
use portable_atomic::AtomicU32;
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicU32, Ordering};

const SOC_PHY_DIG_REGS_MEM_SIZE: usize = 21 * 4;

Expand Down
9 changes: 7 additions & 2 deletions esp-wifi/src/common_adapter/common_adapter_esp32c6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use crate::compat::common::str_from_c;
use crate::hal::system::RadioClockController;
use crate::hal::system::RadioPeripherals;

use core::sync::atomic::Ordering;
use portable_atomic::AtomicU32;
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicU32, Ordering};

const SOC_PHY_DIG_REGS_MEM_SIZE: usize = 21 * 4;

Expand Down
9 changes: 7 additions & 2 deletions esp-wifi/src/common_adapter/common_adapter_esp32s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use crate::hal::prelude::ram;
use crate::hal::system::RadioClockController;
use crate::hal::system::RadioPeripherals;

use core::sync::atomic::Ordering;
use portable_atomic::AtomicU32;
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicU32, Ordering};

const SOC_PHY_DIG_REGS_MEM_SIZE: usize = 21 * 4;

Expand Down
9 changes: 7 additions & 2 deletions esp-wifi/src/common_adapter/common_adapter_esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ use crate::common_adapter::RADIO_CLOCKS;
use crate::hal::system::RadioClockController;
use crate::hal::system::RadioPeripherals;

use core::sync::atomic::Ordering;
use portable_atomic::AtomicU32;
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicU32, Ordering};

const SOC_PHY_DIG_REGS_MEM_SIZE: usize = 21 * 4;

Expand Down
9 changes: 7 additions & 2 deletions esp-wifi/src/esp_now/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
//! For more information see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html
use core::marker::PhantomData;
use core::sync::atomic::Ordering;
use core::{cell::RefCell, fmt::Debug};

use portable_atomic::{AtomicBool, AtomicU8};
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicBool, AtomicU8, Ordering};

use critical_section::Mutex;

Expand Down
10 changes: 8 additions & 2 deletions esp-wifi/src/timer/xtensa.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use core::cell::RefCell;
use core::sync::atomic::Ordering;
use portable_atomic::AtomicU32;

#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicU32, Ordering};

use critical_section::Mutex;

Expand Down
10 changes: 8 additions & 2 deletions esp-wifi/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ pub(crate) mod os_adapter;
pub(crate) mod state;

use core::ptr::addr_of;
use core::sync::atomic::Ordering;
use core::time::Duration;
use core::{
cell::{RefCell, RefMut},
mem::MaybeUninit,
};
use portable_atomic::AtomicUsize;

#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;

#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

use atomic::{AtomicUsize, Ordering};

use crate::common_adapter::*;
use crate::esp_wifi_result;
Expand Down

0 comments on commit 399dd7b

Please sign in to comment.