diff options
| author | Thales Fragoso <[email protected]> | 2021-06-14 18:06:12 -0300 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-06-16 16:48:35 +0200 |
| commit | 3396a519389837727c17eae2ebf65d5c93f70551 (patch) | |
| tree | 209e8b6628d765079ef539abdd070d23f61171ec | |
| parent | 6cecc6d4b54acf84cc9b22996b178cba97970374 (diff) | |
net: Add features for pool size and remove unwrap on smoltcp device
| -rw-r--r-- | embassy-net/Cargo.toml | 6 | ||||
| -rw-r--r-- | embassy-net/src/device.rs | 2 | ||||
| -rw-r--r-- | embassy-net/src/packet_pool.rs | 11 |
3 files changed, 18 insertions, 1 deletions
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 <[email protected]>"] | |||
| 5 | edition = "2018" | 5 | edition = "2018" |
| 6 | 6 | ||
| 7 | [features] | 7 | [features] |
| 8 | default = ["pool-4"] | ||
| 8 | std = [] | 9 | std = [] |
| 9 | defmt-trace = [] | 10 | defmt-trace = [] |
| 10 | defmt-debug = [] | 11 | defmt-debug = [] |
| @@ -17,6 +18,11 @@ dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"] | |||
| 17 | medium-ethernet = ["smoltcp/medium-ethernet"] | 18 | medium-ethernet = ["smoltcp/medium-ethernet"] |
| 18 | medium-ip = ["smoltcp/medium-ip"] | 19 | medium-ip = ["smoltcp/medium-ip"] |
| 19 | 20 | ||
| 21 | pool-4 = [] | ||
| 22 | pool-8 = [] | ||
| 23 | pool-16 = [] | ||
| 24 | pool-32 = [] | ||
| 25 | |||
| 20 | [dependencies] | 26 | [dependencies] |
| 21 | 27 | ||
| 22 | defmt = { version = "0.2.0", optional = true } | 28 | 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 { | |||
| 43 | type TxToken = TxToken<'a>; | 43 | type TxToken = TxToken<'a>; |
| 44 | 44 | ||
| 45 | fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { | 45 | fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { |
| 46 | let tx_pkt = PacketBox::new(Packet::new())?; | ||
| 46 | let rx_pkt = self.device.receive()?; | 47 | let rx_pkt = self.device.receive()?; |
| 47 | let tx_pkt = PacketBox::new(Packet::new()).unwrap(); // TODO: not sure about unwrap | ||
| 48 | let rx_token = RxToken { pkt: rx_pkt }; | 48 | let rx_token = RxToken { pkt: rx_pkt }; |
| 49 | let tx_token = TxToken { | 49 | let tx_token = TxToken { |
| 50 | device: self.device, | 50 | 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}; | |||
| 4 | use atomic_pool::{pool, Box}; | 4 | use atomic_pool::{pool, Box}; |
| 5 | 5 | ||
| 6 | pub const MTU: usize = 1516; | 6 | pub const MTU: usize = 1516; |
| 7 | |||
| 8 | #[cfg(feature = "pool-4")] | ||
| 7 | pub const PACKET_POOL_SIZE: usize = 4; | 9 | pub const PACKET_POOL_SIZE: usize = 4; |
| 8 | 10 | ||
| 11 | #[cfg(feature = "pool-8")] | ||
| 12 | pub const PACKET_POOL_SIZE: usize = 8; | ||
| 13 | |||
| 14 | #[cfg(feature = "pool-16")] | ||
| 15 | pub const PACKET_POOL_SIZE: usize = 16; | ||
| 16 | |||
| 17 | #[cfg(feature = "pool-32")] | ||
| 18 | pub const PACKET_POOL_SIZE: usize = 32; | ||
| 19 | |||
| 9 | pool!(pub PacketPool: [Packet; PACKET_POOL_SIZE]); | 20 | pool!(pub PacketPool: [Packet; PACKET_POOL_SIZE]); |
| 10 | pub type PacketBox = Box<PacketPool>; | 21 | pub type PacketBox = Box<PacketPool>; |
| 11 | 22 | ||
