net: Add features for pool size and remove unwrap on smoltcp device

This commit is contained in:
Thales Fragoso 2021-06-14 18:06:12 -03:00 committed by Dario Nieuwenhuis
parent 6cecc6d4b5
commit 3396a51938
3 changed files with 18 additions and 1 deletions

View File

@ -5,6 +5,7 @@ authors = ["Dario Nieuwenhuis <dirbaio@dirbaio.net>"]
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 }

View File

@ -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,

View File

@ -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<PacketPool>;