diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index c64075b93..0f4571761 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Dario Nieuwenhuis "] edition = "2018" [features] +default = ["pool-4"] std = [] defmt-trace = [] defmt-debug = [] @@ -17,6 +18,11 @@ dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"] medium-ethernet = ["smoltcp/medium-ethernet"] medium-ip = ["smoltcp/medium-ip"] +pool-4 = [] +pool-8 = [] +pool-16 = [] +pool-32 = [] + [dependencies] defmt = { version = "0.2.0", optional = true } diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 5fcb94ac8..fc9d08947 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -43,8 +43,8 @@ impl<'a> SmolDevice<'a> for DeviceAdapter { type TxToken = TxToken<'a>; fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { + let tx_pkt = PacketBox::new(Packet::new())?; let rx_pkt = self.device.receive()?; - let tx_pkt = PacketBox::new(Packet::new()).unwrap(); // TODO: not sure about unwrap let rx_token = RxToken { pkt: rx_pkt }; let tx_token = TxToken { device: self.device, diff --git a/embassy-net/src/packet_pool.rs b/embassy-net/src/packet_pool.rs index 0ec88e649..b43ae2eb2 100644 --- a/embassy-net/src/packet_pool.rs +++ b/embassy-net/src/packet_pool.rs @@ -4,8 +4,19 @@ use core::ops::{Deref, DerefMut, Range}; use atomic_pool::{pool, Box}; pub const MTU: usize = 1516; + +#[cfg(feature = "pool-4")] pub const PACKET_POOL_SIZE: usize = 4; +#[cfg(feature = "pool-8")] +pub const PACKET_POOL_SIZE: usize = 8; + +#[cfg(feature = "pool-16")] +pub const PACKET_POOL_SIZE: usize = 16; + +#[cfg(feature = "pool-32")] +pub const PACKET_POOL_SIZE: usize = 32; + pool!(pub PacketPool: [Packet; PACKET_POOL_SIZE]); pub type PacketBox = Box;