aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src/bin/net.rs
diff options
context:
space:
mode:
authorPeter Krull <[email protected]>2024-09-23 19:02:59 +0200
committerGitHub <[email protected]>2024-09-23 19:02:59 +0200
commita2c473306f4a7c8e99add2546450ab3a7a97436e (patch)
tree5522a708e492db7d4632dc0a56fe5057244f03f0 /examples/std/src/bin/net.rs
parente02a987bafd4f0fcf9d80e7c4f6e1504b8b02cec (diff)
parent2935290a6222536d6341103f91bfd732165d3862 (diff)
Merge branch 'embassy-rs:main' into multi-signal
Diffstat (limited to 'examples/std/src/bin/net.rs')
-rw-r--r--examples/std/src/bin/net.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs
index dad93d0a1..cefa5448c 100644
--- a/examples/std/src/bin/net.rs
+++ b/examples/std/src/bin/net.rs
@@ -1,9 +1,7 @@
1use std::default::Default;
2
3use clap::Parser; 1use clap::Parser;
4use embassy_executor::{Executor, Spawner}; 2use embassy_executor::{Executor, Spawner};
5use embassy_net::tcp::TcpSocket; 3use embassy_net::tcp::TcpSocket;
6use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; 4use embassy_net::{Config, Ipv4Address, Ipv4Cidr, StackResources};
7use embassy_net_tuntap::TunTapDevice; 5use embassy_net_tuntap::TunTapDevice;
8use embassy_time::Duration; 6use embassy_time::Duration;
9use embedded_io_async::Write; 7use embedded_io_async::Write;
@@ -24,8 +22,8 @@ struct Opts {
24} 22}
25 23
26#[embassy_executor::task] 24#[embassy_executor::task]
27async fn net_task(stack: &'static Stack<TunTapDevice>) -> ! { 25async fn net_task(mut runner: embassy_net::Runner<'static, TunTapDevice>) -> ! {
28 stack.run().await 26 runner.run().await
29} 27}
30 28
31#[embassy_executor::task] 29#[embassy_executor::task]
@@ -52,17 +50,11 @@ async fn main_task(spawner: Spawner) {
52 let seed = u64::from_le_bytes(seed); 50 let seed = u64::from_le_bytes(seed);
53 51
54 // Init network stack 52 // Init network stack
55 static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new();
56 static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); 53 static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
57 let stack = &*STACK.init(Stack::new( 54 let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed);
58 device,
59 config,
60 RESOURCES.init(StackResources::<3>::new()),
61 seed,
62 ));
63 55
64 // Launch network task 56 // Launch network task
65 spawner.spawn(net_task(stack)).unwrap(); 57 spawner.spawn(net_task(runner)).unwrap();
66 58
67 // Then we can use it! 59 // Then we can use it!
68 let mut rx_buffer = [0; 4096]; 60 let mut rx_buffer = [0; 4096];