From aca0fb10651359b5a3939f7424ac0a78ef20cc27 Mon Sep 17 00:00:00 2001 From: Thales Fragoso Date: Sun, 20 Jun 2021 16:46:26 -0300 Subject: 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 --- examples/std/src/bin/net.rs | 5 ++++- examples/stm32h7/src/bin/eth.rs | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 5a726e5d2..344a6e4d3 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs @@ -19,6 +19,7 @@ use crate::tuntap::TunTapDevice; static DEVICE: Forever = Forever::new(); static CONFIG: Forever = Forever::new(); +static NET_RESOURCES: Forever> = 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(); diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 57997da0a..7d7ff941e 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -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> = Forever::new(); static ETH: Forever> = Forever::new(); static DEVICE: Forever>> = Forever::new(); static CONFIG: Forever = Forever::new(); +static NET_RESOURCES: Forever> = Forever::new(); #[entry] fn main() -> ! { -- cgit