net: Make the user pass in the StackResources in init

By having the user pass in the resources, we can make them generic, this way
the user can choose the size of the individual resources
This commit is contained in:
Thales Fragoso
2021-06-20 16:46:26 -03:00
parent 06d69a8028
commit aca0fb1065
4 changed files with 41 additions and 29 deletions

View File

@ -19,6 +19,7 @@ use crate::tuntap::TunTapDevice;
static DEVICE: Forever<TunTapDevice> = Forever::new();
static CONFIG: Forever<DhcpConfigurator> = Forever::new();
static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new();
#[derive(Clap)]
#[clap(version = "1.0")]
@ -51,8 +52,10 @@ async fn main_task(spawner: Spawner) {
// DHCP configruation
let config = DhcpConfigurator::new();
let net_resources = StackResources::new();
// Init network stack
embassy_net::init(DEVICE.put(device), CONFIG.put(config));
embassy_net::init(DEVICE.put(device), CONFIG.put(config), NET_RESOURCES.put(net_resources));
// Launch network task
spawner.spawn(net_task()).unwrap();

View File

@ -16,7 +16,9 @@ use embassy::io::AsyncWriteExt;
use embassy::time::{Duration, Timer};
use embassy::util::Forever;
use embassy_macros::interrupt_take;
use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StaticConfigurator, TcpSocket};
use embassy_net::{
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
};
use embassy_stm32::clock::{Alarm, Clock};
use embassy_stm32::eth::lan8742a::LAN8742A;
use embassy_stm32::eth::Ethernet;
@ -43,8 +45,10 @@ async fn main_task(
config: &'static mut StaticConfigurator,
spawner: Spawner,
) {
let net_resources = NET_RESOURCES.put(StackResources::new());
// Init network stack
embassy_net::init(device, config);
embassy_net::init(device, config, net_resources);
// Launch network task
unwrap!(spawner.spawn(net_task()));
@ -97,6 +101,7 @@ static ALARM: Forever<Alarm<TIM2>> = Forever::new();
static ETH: Forever<Ethernet<'static, LAN8742A, 4, 4>> = Forever::new();
static DEVICE: Forever<Pin<&'static mut Ethernet<'static, LAN8742A, 4, 4>>> = Forever::new();
static CONFIG: Forever<StaticConfigurator> = Forever::new();
static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new();
#[entry]
fn main() -> ! {