examples: ensure at least 3 sockets to avoid running out (DHCP, DNS, the user's)

This commit is contained in:
Dario Nieuwenhuis 2024-08-05 21:38:30 +02:00
parent 21edbd3c17
commit 59cb1531c9
27 changed files with 46 additions and 128 deletions

View File

@ -416,7 +416,10 @@ impl<D: Driver> Stack<D> {
/// ```ignore
/// let config = embassy_net::Config::dhcpv4(Default::default());
/// // Init network stack
/// static RESOURCES: StaticCell<embassy_net::StackResources<2>> = StaticCell::new();
/// // NOTE: DHCP and DNS need one socket slot if enabled. This is why we're
/// // provisioning space for 3 sockets here: one for DHCP, one for DNS, and one for your code (e.g. TCP).
/// // If you use more sockets you must increase this. If you don't enable DHCP or DNS you can decrease it.
/// static RESOURCES: StaticCell<embassy_net::StackResources<3>> = StaticCell::new();
/// static STACK: StaticCell<embassy_net::Stack> = StaticCell::new();
/// let stack = &*STACK.init(embassy_net::Stack::new(
/// device,

View File

@ -66,16 +66,11 @@ async fn main(spawner: Spawner) {
let seed = u64::from_le_bytes(seed);
// Init network stack
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
static STACK: StaticCell<
Stack<Enc28j60<ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, Output<'static>>>,
> = StaticCell::new();
let stack = STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
let stack = STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -115,7 +115,7 @@ async fn main(spawner: Spawner) {
let seed = u64::from_le_bytes(seed);
// Init network stack
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));

View File

@ -89,14 +89,9 @@ async fn main(spawner: Spawner) {
let seed = u64::from_le_bytes(seed);
// Init network stack
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
static STACK: StaticCell<Stack<hosted::NetDriver<'static>>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -76,7 +76,7 @@ async fn main(spawner: Spawner) {
let stack = &*STACK.init(Stack::new(
device,
embassy_net::Config::dhcpv4(Default::default()),
RESOURCES.init(StackResources::<3>::new()),
RESOURCES.init(StackResources::new()),
seed,
));

View File

@ -75,11 +75,11 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
embassy_net::Config::dhcpv4(Default::default()),
RESOURCES.init(StackResources::<2>::new()),
RESOURCES.init(StackResources::new()),
seed,
));

View File

@ -74,11 +74,11 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
embassy_net::Config::dhcpv4(Default::default()),
RESOURCES.init(StackResources::<2>::new()),
RESOURCES.init(StackResources::new()),
seed,
));

View File

@ -72,11 +72,11 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
embassy_net::Config::dhcpv4(Default::default()),
RESOURCES.init(StackResources::<2>::new()),
RESOURCES.init(StackResources::new()),
seed,
));

View File

@ -109,13 +109,8 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -81,11 +81,11 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<cyw43::NetDriver<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
net_device,
config,
RESOURCES.init(StackResources::<2>::new()),
RESOURCES.init(StackResources::new()),
seed,
));

View File

@ -84,11 +84,11 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<cyw43::NetDriver<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
net_device,
config,
RESOURCES.init(StackResources::<2>::new()),
RESOURCES.init(StackResources::new()),
seed,
));

View File

@ -91,7 +91,7 @@ async fn main(spawner: Spawner) {
let stack = &*STACK.init(Stack::new(
net_device,
config,
RESOURCES.init(StackResources::<5>::new()),
RESOURCES.init(StackResources::new()),
seed,
));

View File

@ -52,12 +52,7 @@ async fn main_task(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<3>::new()),
seed,
));
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

View File

@ -51,12 +51,7 @@ async fn main_task(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack: &Stack<_> = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<3>::new()),
seed,
));
let stack: &Stack<_> = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

View File

@ -102,7 +102,7 @@ async fn main_task(spawner: Spawner) {
let stack = &*STACK.init(Stack::new(
device,
Config::default(), // don't configure IP yet
RESOURCES.init(StackResources::<3>::new()),
RESOURCES.init(StackResources::new()),
seed,
));

View File

@ -50,12 +50,7 @@ async fn main_task(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<3>::new()),
seed,
));
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

View File

@ -64,12 +64,7 @@ async fn main_task(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<3>::new()),
seed,
));
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

View File

@ -89,13 +89,8 @@ async fn main(spawner: Spawner) -> ! {
// Init network stack
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -93,13 +93,8 @@ async fn main(spawner: Spawner) -> ! {
//});
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -145,13 +145,8 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -90,13 +90,8 @@ async fn main(spawner: Spawner) -> ! {
// Init network stack
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -93,13 +93,8 @@ async fn main(spawner: Spawner) -> ! {
// Init network stack
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
unwrap!(spawner.spawn(net_task(&stack)));

View File

@ -93,12 +93,7 @@ async fn main(spawner: Spawner) -> ! {
// Init network stack
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<3>::new()),
seed,
));
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
unwrap!(spawner.spawn(net_task(&stack)));

View File

@ -93,12 +93,7 @@ async fn main(spawner: Spawner) -> ! {
// Init network stack
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<3>::new()),
seed,
));
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -99,12 +99,7 @@ async fn main(spawner: Spawner) -> ! {
// Init network stack
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<3>::new()),
seed,
));
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
// Launch network task
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -207,13 +207,8 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
ip_cfg,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, ip_cfg, RESOURCES.init(StackResources::new()), seed));
// Launch network task
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -122,13 +122,8 @@ async fn main(spawner: Spawner) {
// Init network stack
static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
RESOURCES.init(StackResources::<2>::new()),
seed,
));
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
unwrap!(spawner.spawn(net_task(stack)));