diff options
Diffstat (limited to 'embassy-net')
| -rw-r--r-- | embassy-net/Cargo.toml | 6 | ||||
| -rw-r--r-- | embassy-net/src/device.rs | 2 | ||||
| -rw-r--r-- | embassy-net/src/lib.rs | 2 | ||||
| -rw-r--r-- | embassy-net/src/packet_pool.rs | 14 |
4 files changed, 21 insertions, 3 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/lib.rs b/embassy-net/src/lib.rs index 88dcf0aa5..51eb97a2e 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -13,7 +13,7 @@ pub use config::DhcpConfigurator; | |||
| 13 | pub use config::{Config, Configurator, Event as ConfigEvent, StaticConfigurator}; | 13 | pub use config::{Config, Configurator, Event as ConfigEvent, StaticConfigurator}; |
| 14 | 14 | ||
| 15 | pub use device::{Device, LinkState}; | 15 | pub use device::{Device, LinkState}; |
| 16 | pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf}; | 16 | pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf, MTU}; |
| 17 | pub use stack::{init, is_config_up, is_init, is_link_up, run}; | 17 | pub use stack::{init, is_config_up, is_init, is_link_up, run}; |
| 18 | 18 | ||
| 19 | #[cfg(feature = "tcp")] | 19 | #[cfg(feature = "tcp")] |
diff --git a/embassy-net/src/packet_pool.rs b/embassy-net/src/packet_pool.rs index 2c27d4013..b43ae2eb2 100644 --- a/embassy-net/src/packet_pool.rs +++ b/embassy-net/src/packet_pool.rs | |||
| @@ -3,12 +3,24 @@ use core::ops::{Deref, DerefMut, Range}; | |||
| 3 | 3 | ||
| 4 | use atomic_pool::{pool, Box}; | 4 | use atomic_pool::{pool, Box}; |
| 5 | 5 | ||
| 6 | pub const MTU: usize = 1514; | 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 | ||
| 23 | #[repr(align(4))] | ||
| 12 | pub struct Packet(pub [u8; MTU]); | 24 | pub struct Packet(pub [u8; MTU]); |
| 13 | 25 | ||
| 14 | impl Packet { | 26 | impl Packet { |
