aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cyw43/Cargo.toml1
-rw-r--r--embassy-net/Cargo.toml1
-rw-r--r--embassy-net/src/tcp.rs15
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs4
4 files changed, 9 insertions, 12 deletions
diff --git a/cyw43/Cargo.toml b/cyw43/Cargo.toml
index dae7419c1..c201405e7 100644
--- a/cyw43/Cargo.toml
+++ b/cyw43/Cargo.toml
@@ -15,7 +15,6 @@ embassy-time = { version = "0.1.3", path = "../embassy-time"}
15embassy-sync = { version = "0.3.0", path = "../embassy-sync"} 15embassy-sync = { version = "0.3.0", path = "../embassy-sync"}
16embassy-futures = { version = "0.1.0", path = "../embassy-futures"} 16embassy-futures = { version = "0.1.0", path = "../embassy-futures"}
17embassy-net-driver-channel = { version = "0.1.0", path = "../embassy-net-driver-channel"} 17embassy-net-driver-channel = { version = "0.1.0", path = "../embassy-net-driver-channel"}
18atomic-polyfill = "0.1.5"
19 18
20defmt = { version = "0.3", optional = true } 19defmt = { version = "0.3", optional = true }
21log = { version = "0.4.17", optional = true } 20log = { version = "0.4.17", optional = true }
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml
index c2fffba84..a3c18046e 100644
--- a/embassy-net/Cargo.toml
+++ b/embassy-net/Cargo.toml
@@ -64,4 +64,3 @@ stable_deref_trait = { version = "1.2.0", default-features = false }
64futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } 64futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] }
65atomic-pool = "1.0" 65atomic-pool = "1.0"
66embedded-nal-async = { version = "0.6.0", optional = true } 66embedded-nal-async = { version = "0.6.0", optional = true }
67atomic-polyfill = { version = "1.0" }
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index a12fd382a..b5615cb66 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -579,11 +579,10 @@ mod embedded_io_impls {
579/// TCP client compatible with `embedded-nal-async` traits. 579/// TCP client compatible with `embedded-nal-async` traits.
580#[cfg(feature = "nightly")] 580#[cfg(feature = "nightly")]
581pub mod client { 581pub mod client {
582 use core::cell::UnsafeCell; 582 use core::cell::{Cell, UnsafeCell};
583 use core::mem::MaybeUninit; 583 use core::mem::MaybeUninit;
584 use core::ptr::NonNull; 584 use core::ptr::NonNull;
585 585
586 use atomic_polyfill::{AtomicBool, Ordering};
587 use embedded_nal_async::IpAddr; 586 use embedded_nal_async::IpAddr;
588 587
589 use super::*; 588 use super::*;
@@ -702,15 +701,13 @@ pub mod client {
702 } 701 }
703 } 702 }
704 703
705 unsafe impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize> Sync for TcpClientState<N, TX_SZ, RX_SZ> {}
706
707 struct Pool<T, const N: usize> { 704 struct Pool<T, const N: usize> {
708 used: [AtomicBool; N], 705 used: [Cell<bool>; N],
709 data: [UnsafeCell<MaybeUninit<T>>; N], 706 data: [UnsafeCell<MaybeUninit<T>>; N],
710 } 707 }
711 708
712 impl<T, const N: usize> Pool<T, N> { 709 impl<T, const N: usize> Pool<T, N> {
713 const VALUE: AtomicBool = AtomicBool::new(false); 710 const VALUE: Cell<bool> = Cell::new(false);
714 const UNINIT: UnsafeCell<MaybeUninit<T>> = UnsafeCell::new(MaybeUninit::uninit()); 711 const UNINIT: UnsafeCell<MaybeUninit<T>> = UnsafeCell::new(MaybeUninit::uninit());
715 712
716 const fn new() -> Self { 713 const fn new() -> Self {
@@ -724,7 +721,9 @@ pub mod client {
724 impl<T, const N: usize> Pool<T, N> { 721 impl<T, const N: usize> Pool<T, N> {
725 fn alloc(&self) -> Option<NonNull<T>> { 722 fn alloc(&self) -> Option<NonNull<T>> {
726 for n in 0..N { 723 for n in 0..N {
727 if self.used[n].swap(true, Ordering::SeqCst) == false { 724 // this can't race because Pool is not Sync.
725 if !self.used[n].get() {
726 self.used[n].set(true);
728 let p = self.data[n].get() as *mut T; 727 let p = self.data[n].get() as *mut T;
729 return Some(unsafe { NonNull::new_unchecked(p) }); 728 return Some(unsafe { NonNull::new_unchecked(p) });
730 } 729 }
@@ -738,7 +737,7 @@ pub mod client {
738 let n = p.as_ptr().offset_from(origin); 737 let n = p.as_ptr().offset_from(origin);
739 assert!(n >= 0); 738 assert!(n >= 0);
740 assert!((n as usize) < N); 739 assert!((n as usize) < N);
741 self.used[n as usize].store(false, Ordering::SeqCst); 740 self.used[n as usize].set(false);
742 } 741 }
743 } 742 }
744} 743}
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
index 4db7aa252..09d27cdbd 100644
--- a/examples/stm32h7/src/bin/eth_client.rs
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -105,8 +105,8 @@ async fn main(spawner: Spawner) -> ! {
105 105
106 info!("Network task initialized"); 106 info!("Network task initialized");
107 107
108 static STATE: TcpClientState<1, 1024, 1024> = TcpClientState::new(); 108 let state: TcpClientState<1, 1024, 1024> = TcpClientState::new();
109 let client = TcpClient::new(&stack, &STATE); 109 let client = TcpClient::new(&stack, &state);
110 110
111 loop { 111 loop {
112 let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(10, 42, 0, 1), 8000)); 112 let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(10, 42, 0, 1), 8000));