aboutsummaryrefslogtreecommitdiff
path: root/embassy-net
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-06-16 16:55:39 +0200
committerGitHub <[email protected]>2021-06-16 16:55:39 +0200
commit0d1ae0a01e18e19cc8f33fd184785c19f18e1277 (patch)
tree79e3055dc8b04c2e9b4db45d0561e97a1eacc0e2 /embassy-net
parent6386c34079913732466046194f79a683a4aefce4 (diff)
parent098ce6e7404f10aa6c7dd91260ca6864a92c6a59 (diff)
Merge pull request #247 from thalesfragoso/eth-v2
Eth v2
Diffstat (limited to 'embassy-net')
-rw-r--r--embassy-net/Cargo.toml6
-rw-r--r--embassy-net/src/device.rs2
-rw-r--r--embassy-net/src/lib.rs2
-rw-r--r--embassy-net/src/packet_pool.rs14
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]>"]
5edition = "2018" 5edition = "2018"
6 6
7[features] 7[features]
8default = ["pool-4"]
8std = [] 9std = []
9defmt-trace = [] 10defmt-trace = []
10defmt-debug = [] 11defmt-debug = []
@@ -17,6 +18,11 @@ dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"]
17medium-ethernet = ["smoltcp/medium-ethernet"] 18medium-ethernet = ["smoltcp/medium-ethernet"]
18medium-ip = ["smoltcp/medium-ip"] 19medium-ip = ["smoltcp/medium-ip"]
19 20
21pool-4 = []
22pool-8 = []
23pool-16 = []
24pool-32 = []
25
20[dependencies] 26[dependencies]
21 27
22defmt = { version = "0.2.0", optional = true } 28defmt = { 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;
13pub use config::{Config, Configurator, Event as ConfigEvent, StaticConfigurator}; 13pub use config::{Config, Configurator, Event as ConfigEvent, StaticConfigurator};
14 14
15pub use device::{Device, LinkState}; 15pub use device::{Device, LinkState};
16pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf}; 16pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf, MTU};
17pub use stack::{init, is_config_up, is_init, is_link_up, run}; 17pub 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
4use atomic_pool::{pool, Box}; 4use atomic_pool::{pool, Box};
5 5
6pub const MTU: usize = 1514; 6pub const MTU: usize = 1516;
7
8#[cfg(feature = "pool-4")]
7pub const PACKET_POOL_SIZE: usize = 4; 9pub const PACKET_POOL_SIZE: usize = 4;
8 10
11#[cfg(feature = "pool-8")]
12pub const PACKET_POOL_SIZE: usize = 8;
13
14#[cfg(feature = "pool-16")]
15pub const PACKET_POOL_SIZE: usize = 16;
16
17#[cfg(feature = "pool-32")]
18pub const PACKET_POOL_SIZE: usize = 32;
19
9pool!(pub PacketPool: [Packet; PACKET_POOL_SIZE]); 20pool!(pub PacketPool: [Packet; PACKET_POOL_SIZE]);
10pub type PacketBox = Box<PacketPool>; 21pub type PacketBox = Box<PacketPool>;
11 22
23#[repr(align(4))]
12pub struct Packet(pub [u8; MTU]); 24pub struct Packet(pub [u8; MTU]);
13 25
14impl Packet { 26impl Packet {