diff options
Diffstat (limited to 'examples/std/src')
| -rw-r--r-- | examples/std/src/bin/net.rs | 23 | ||||
| -rw-r--r-- | examples/std/src/bin/net_dns.rs | 15 | ||||
| -rw-r--r-- | examples/std/src/bin/net_ppp.rs | 79 | ||||
| -rw-r--r-- | examples/std/src/bin/net_udp.rs | 15 | ||||
| -rw-r--r-- | examples/std/src/bin/tcp_accept.rs | 32 |
5 files changed, 48 insertions, 116 deletions
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 310e7264d..232cf494b 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -1,13 +1,15 @@ | |||
| 1 | use core::fmt::Write as _; | ||
| 2 | |||
| 1 | use clap::Parser; | 3 | use clap::Parser; |
| 2 | use embassy_executor::{Executor, Spawner}; | 4 | use embassy_executor::{Executor, Spawner}; |
| 3 | use embassy_net::tcp::TcpSocket; | 5 | use embassy_net::tcp::TcpSocket; |
| 4 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 6 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, StackResources}; |
| 5 | use embassy_net_tuntap::TunTapDevice; | 7 | use embassy_net_tuntap::TunTapDevice; |
| 6 | use embassy_time::Duration; | 8 | use embassy_time::Duration; |
| 7 | use embedded_io_async::Write; | 9 | use embedded_io_async::Write; |
| 8 | use heapless::Vec; | 10 | use heapless::Vec; |
| 9 | use log::*; | 11 | use log::*; |
| 10 | use rand_core::{OsRng, RngCore}; | 12 | use rand_core::{OsRng, TryRngCore}; |
| 11 | use static_cell::StaticCell; | 13 | use static_cell::StaticCell; |
| 12 | 14 | ||
| 13 | #[derive(Parser)] | 15 | #[derive(Parser)] |
| @@ -22,8 +24,8 @@ struct Opts { | |||
| 22 | } | 24 | } |
| 23 | 25 | ||
| 24 | #[embassy_executor::task] | 26 | #[embassy_executor::task] |
| 25 | async fn net_task(stack: &'static Stack<TunTapDevice>) -> ! { | 27 | async fn net_task(mut runner: embassy_net::Runner<'static, TunTapDevice>) -> ! { |
| 26 | stack.run().await | 28 | runner.run().await |
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | #[embassy_executor::task] | 31 | #[embassy_executor::task] |
| @@ -46,16 +48,15 @@ async fn main_task(spawner: Spawner) { | |||
| 46 | 48 | ||
| 47 | // Generate random seed | 49 | // Generate random seed |
| 48 | let mut seed = [0; 8]; | 50 | let mut seed = [0; 8]; |
| 49 | OsRng.fill_bytes(&mut seed); | 51 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 50 | let seed = u64::from_le_bytes(seed); | 52 | let seed = u64::from_le_bytes(seed); |
| 51 | 53 | ||
| 52 | // Init network stack | 54 | // Init network stack |
| 53 | static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new(); | ||
| 54 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 55 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 55 | let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); | 56 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 56 | 57 | ||
| 57 | // Launch network task | 58 | // Launch network task |
| 58 | spawner.spawn(net_task(stack)).unwrap(); | 59 | spawner.spawn(net_task(runner)).unwrap(); |
| 59 | 60 | ||
| 60 | // Then we can use it! | 61 | // Then we can use it! |
| 61 | let mut rx_buffer = [0; 4096]; | 62 | let mut rx_buffer = [0; 4096]; |
| @@ -72,8 +73,10 @@ async fn main_task(spawner: Spawner) { | |||
| 72 | return; | 73 | return; |
| 73 | } | 74 | } |
| 74 | info!("connected!"); | 75 | info!("connected!"); |
| 75 | loop { | 76 | for i in 0.. { |
| 76 | let r = socket.write_all(b"Hello!\n").await; | 77 | let mut buf = heapless::String::<100>::new(); |
| 78 | write!(buf, "Hello! ({})\r\n", i).unwrap(); | ||
| 79 | let r = socket.write_all(buf.as_bytes()).await; | ||
| 77 | if let Err(e) = r { | 80 | if let Err(e) = r { |
| 78 | warn!("write error: {:?}", e); | 81 | warn!("write error: {:?}", e); |
| 79 | return; | 82 | return; |
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index c9615ef35..cf90731dd 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | use clap::Parser; | 1 | use clap::Parser; |
| 2 | use embassy_executor::{Executor, Spawner}; | 2 | use embassy_executor::{Executor, Spawner}; |
| 3 | use embassy_net::dns::DnsQueryType; | 3 | use embassy_net::dns::DnsQueryType; |
| 4 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 4 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, StackResources}; |
| 5 | use embassy_net_tuntap::TunTapDevice; | 5 | use embassy_net_tuntap::TunTapDevice; |
| 6 | use heapless::Vec; | 6 | use heapless::Vec; |
| 7 | use log::*; | 7 | use log::*; |
| 8 | use rand_core::{OsRng, RngCore}; | 8 | use rand_core::{OsRng, TryRngCore}; |
| 9 | use static_cell::StaticCell; | 9 | use static_cell::StaticCell; |
| 10 | 10 | ||
| 11 | #[derive(Parser)] | 11 | #[derive(Parser)] |
| @@ -20,8 +20,8 @@ struct Opts { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | #[embassy_executor::task] | 22 | #[embassy_executor::task] |
| 23 | async fn net_task(stack: &'static Stack<TunTapDevice>) -> ! { | 23 | async fn net_task(mut runner: embassy_net::Runner<'static, TunTapDevice>) -> ! { |
| 24 | stack.run().await | 24 | runner.run().await |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | #[embassy_executor::task] | 27 | #[embassy_executor::task] |
| @@ -45,16 +45,15 @@ async fn main_task(spawner: Spawner) { | |||
| 45 | 45 | ||
| 46 | // Generate random seed | 46 | // Generate random seed |
| 47 | let mut seed = [0; 8]; | 47 | let mut seed = [0; 8]; |
| 48 | OsRng.fill_bytes(&mut seed); | 48 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 49 | let seed = u64::from_le_bytes(seed); | 49 | let seed = u64::from_le_bytes(seed); |
| 50 | 50 | ||
| 51 | // Init network stack | 51 | // Init network stack |
| 52 | static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new(); | ||
| 53 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 52 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 54 | let stack: &Stack<_> = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); | 53 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 55 | 54 | ||
| 56 | // Launch network task | 55 | // Launch network task |
| 57 | spawner.spawn(net_task(stack)).unwrap(); | 56 | spawner.spawn(net_task(runner)).unwrap(); |
| 58 | 57 | ||
| 59 | let host = "example.com"; | 58 | let host = "example.com"; |
| 60 | info!("querying host {:?}...", host); | 59 | info!("querying host {:?}...", host); |
diff --git a/examples/std/src/bin/net_ppp.rs b/examples/std/src/bin/net_ppp.rs index c5c27c4a3..ac3aea6ff 100644 --- a/examples/std/src/bin/net_ppp.rs +++ b/examples/std/src/bin/net_ppp.rs | |||
| @@ -16,14 +16,14 @@ use async_io::Async; | |||
| 16 | use clap::Parser; | 16 | use clap::Parser; |
| 17 | use embassy_executor::{Executor, Spawner}; | 17 | use embassy_executor::{Executor, Spawner}; |
| 18 | use embassy_net::tcp::TcpSocket; | 18 | use embassy_net::tcp::TcpSocket; |
| 19 | use embassy_net::{Config, ConfigV4, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 19 | use embassy_net::{Config, ConfigV4, Ipv4Cidr, Stack, StackResources}; |
| 20 | use embassy_net_ppp::Runner; | 20 | use embassy_net_ppp::Runner; |
| 21 | use embedded_io_async::Write; | 21 | use embedded_io_async::Write; |
| 22 | use futures::io::BufReader; | 22 | use futures::io::BufReader; |
| 23 | use heapless::Vec; | 23 | use heapless::Vec; |
| 24 | use log::*; | 24 | use log::*; |
| 25 | use nix::sys::termios; | 25 | use nix::sys::termios; |
| 26 | use rand_core::{OsRng, RngCore}; | 26 | use rand_core::{OsRng, TryRngCore}; |
| 27 | use static_cell::StaticCell; | 27 | use static_cell::StaticCell; |
| 28 | 28 | ||
| 29 | use crate::serial_port::SerialPort; | 29 | use crate::serial_port::SerialPort; |
| @@ -37,19 +37,15 @@ struct Opts { | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | #[embassy_executor::task] | 39 | #[embassy_executor::task] |
| 40 | async fn net_task(stack: &'static Stack<embassy_net_ppp::Device<'static>>) -> ! { | 40 | async fn net_task(mut runner: embassy_net::Runner<'static, embassy_net_ppp::Device<'static>>) -> ! { |
| 41 | stack.run().await | 41 | runner.run().await |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | #[embassy_executor::task] | 44 | #[embassy_executor::task] |
| 45 | async fn ppp_task( | 45 | async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: SerialPort) -> ! { |
| 46 | stack: &'static Stack<embassy_net_ppp::Device<'static>>, | ||
| 47 | mut runner: Runner<'static>, | ||
| 48 | port: SerialPort, | ||
| 49 | ) -> ! { | ||
| 50 | let port = Async::new(port).unwrap(); | 46 | let port = Async::new(port).unwrap(); |
| 51 | let port = BufReader::new(port); | 47 | let port = BufReader::new(port); |
| 52 | let port = adapter::FromFutures::new(port); | 48 | let port = embedded_io_adapters::futures_03::FromFutures::new(port); |
| 53 | 49 | ||
| 54 | let config = embassy_net_ppp::Config { | 50 | let config = embassy_net_ppp::Config { |
| 55 | username: b"myuser", | 51 | username: b"myuser", |
| @@ -64,10 +60,10 @@ async fn ppp_task( | |||
| 64 | }; | 60 | }; |
| 65 | let mut dns_servers = Vec::new(); | 61 | let mut dns_servers = Vec::new(); |
| 66 | for s in ipv4.dns_servers.iter().flatten() { | 62 | for s in ipv4.dns_servers.iter().flatten() { |
| 67 | let _ = dns_servers.push(Ipv4Address::from_bytes(&s.0)); | 63 | let _ = dns_servers.push(*s); |
| 68 | } | 64 | } |
| 69 | let config = ConfigV4::Static(embassy_net::StaticConfigV4 { | 65 | let config = ConfigV4::Static(embassy_net::StaticConfigV4 { |
| 70 | address: Ipv4Cidr::new(Ipv4Address::from_bytes(&addr.0), 0), | 66 | address: Ipv4Cidr::new(addr, 0), |
| 71 | gateway: None, | 67 | gateway: None, |
| 72 | dns_servers, | 68 | dns_servers, |
| 73 | }); | 69 | }); |
| @@ -93,21 +89,20 @@ async fn main_task(spawner: Spawner) { | |||
| 93 | 89 | ||
| 94 | // Generate random seed | 90 | // Generate random seed |
| 95 | let mut seed = [0; 8]; | 91 | let mut seed = [0; 8]; |
| 96 | OsRng.fill_bytes(&mut seed); | 92 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 97 | let seed = u64::from_le_bytes(seed); | 93 | let seed = u64::from_le_bytes(seed); |
| 98 | 94 | ||
| 99 | // Init network stack | 95 | // Init network stack |
| 100 | static STACK: StaticCell<Stack<embassy_net_ppp::Device<'static>>> = StaticCell::new(); | ||
| 101 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 96 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 102 | let stack = &*STACK.init(Stack::new( | 97 | let (stack, net_runner) = embassy_net::new( |
| 103 | device, | 98 | device, |
| 104 | Config::default(), // don't configure IP yet | 99 | Config::default(), // don't configure IP yet |
| 105 | RESOURCES.init(StackResources::new()), | 100 | RESOURCES.init(StackResources::new()), |
| 106 | seed, | 101 | seed, |
| 107 | )); | 102 | ); |
| 108 | 103 | ||
| 109 | // Launch network task | 104 | // Launch network task |
| 110 | spawner.spawn(net_task(stack)).unwrap(); | 105 | spawner.spawn(net_task(net_runner)).unwrap(); |
| 111 | spawner.spawn(ppp_task(stack, runner, port)).unwrap(); | 106 | spawner.spawn(ppp_task(stack, runner, port)).unwrap(); |
| 112 | 107 | ||
| 113 | // Then we can use it! | 108 | // Then we can use it! |
| @@ -168,53 +163,3 @@ fn main() { | |||
| 168 | spawner.spawn(main_task(spawner)).unwrap(); | 163 | spawner.spawn(main_task(spawner)).unwrap(); |
| 169 | }); | 164 | }); |
| 170 | } | 165 | } |
| 171 | |||
| 172 | mod adapter { | ||
| 173 | use core::future::poll_fn; | ||
| 174 | use core::pin::Pin; | ||
| 175 | |||
| 176 | use futures::AsyncBufReadExt; | ||
| 177 | |||
| 178 | /// Adapter from `futures::io` traits. | ||
| 179 | #[derive(Clone)] | ||
| 180 | pub struct FromFutures<T: ?Sized> { | ||
| 181 | inner: T, | ||
| 182 | } | ||
| 183 | |||
| 184 | impl<T> FromFutures<T> { | ||
| 185 | /// Create a new adapter. | ||
| 186 | pub fn new(inner: T) -> Self { | ||
| 187 | Self { inner } | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | impl<T: ?Sized> embedded_io_async::ErrorType for FromFutures<T> { | ||
| 192 | type Error = std::io::Error; | ||
| 193 | } | ||
| 194 | |||
| 195 | impl<T: futures::io::AsyncRead + Unpin + ?Sized> embedded_io_async::Read for FromFutures<T> { | ||
| 196 | async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> { | ||
| 197 | poll_fn(|cx| Pin::new(&mut self.inner).poll_read(cx, buf)).await | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | impl<T: futures::io::AsyncBufRead + Unpin + ?Sized> embedded_io_async::BufRead for FromFutures<T> { | ||
| 202 | async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { | ||
| 203 | self.inner.fill_buf().await | ||
| 204 | } | ||
| 205 | |||
| 206 | fn consume(&mut self, amt: usize) { | ||
| 207 | Pin::new(&mut self.inner).consume(amt) | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | impl<T: futures::io::AsyncWrite + Unpin + ?Sized> embedded_io_async::Write for FromFutures<T> { | ||
| 212 | async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { | ||
| 213 | poll_fn(|cx| Pin::new(&mut self.inner).poll_write(cx, buf)).await | ||
| 214 | } | ||
| 215 | |||
| 216 | async fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 217 | poll_fn(|cx| Pin::new(&mut self.inner).poll_flush(cx)).await | ||
| 218 | } | ||
| 219 | } | ||
| 220 | } | ||
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index b2ba4915a..53632a5b4 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | use clap::Parser; | 1 | use clap::Parser; |
| 2 | use embassy_executor::{Executor, Spawner}; | 2 | use embassy_executor::{Executor, Spawner}; |
| 3 | use embassy_net::udp::{PacketMetadata, UdpSocket}; | 3 | use embassy_net::udp::{PacketMetadata, UdpSocket}; |
| 4 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 4 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, StackResources}; |
| 5 | use embassy_net_tuntap::TunTapDevice; | 5 | use embassy_net_tuntap::TunTapDevice; |
| 6 | use heapless::Vec; | 6 | use heapless::Vec; |
| 7 | use log::*; | 7 | use log::*; |
| 8 | use rand_core::{OsRng, RngCore}; | 8 | use rand_core::{OsRng, TryRngCore}; |
| 9 | use static_cell::StaticCell; | 9 | use static_cell::StaticCell; |
| 10 | 10 | ||
| 11 | #[derive(Parser)] | 11 | #[derive(Parser)] |
| @@ -20,8 +20,8 @@ struct Opts { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | #[embassy_executor::task] | 22 | #[embassy_executor::task] |
| 23 | async fn net_task(stack: &'static Stack<TunTapDevice>) -> ! { | 23 | async fn net_task(mut runner: embassy_net::Runner<'static, TunTapDevice>) -> ! { |
| 24 | stack.run().await | 24 | runner.run().await |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | #[embassy_executor::task] | 27 | #[embassy_executor::task] |
| @@ -44,16 +44,15 @@ async fn main_task(spawner: Spawner) { | |||
| 44 | 44 | ||
| 45 | // Generate random seed | 45 | // Generate random seed |
| 46 | let mut seed = [0; 8]; | 46 | let mut seed = [0; 8]; |
| 47 | OsRng.fill_bytes(&mut seed); | 47 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 48 | let seed = u64::from_le_bytes(seed); | 48 | let seed = u64::from_le_bytes(seed); |
| 49 | 49 | ||
| 50 | // Init network stack | 50 | // Init network stack |
| 51 | static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new(); | ||
| 52 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 51 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 53 | let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); | 52 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 54 | 53 | ||
| 55 | // Launch network task | 54 | // Launch network task |
| 56 | spawner.spawn(net_task(stack)).unwrap(); | 55 | spawner.spawn(net_task(runner)).unwrap(); |
| 57 | 56 | ||
| 58 | // Then we can use it! | 57 | // Then we can use it! |
| 59 | let mut rx_meta = [PacketMetadata::EMPTY; 16]; | 58 | let mut rx_meta = [PacketMetadata::EMPTY; 16]; |
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index 39b29a449..961c20e2d 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs | |||
| @@ -1,15 +1,13 @@ | |||
| 1 | use core::fmt::Write as _; | ||
| 2 | |||
| 3 | use clap::Parser; | 1 | use clap::Parser; |
| 4 | use embassy_executor::{Executor, Spawner}; | 2 | use embassy_executor::{Executor, Spawner}; |
| 5 | use embassy_net::tcp::TcpSocket; | 3 | use embassy_net::tcp::TcpSocket; |
| 6 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 4 | use embassy_net::{Config, Ipv4Address, Ipv4Cidr, StackResources}; |
| 7 | use embassy_net_tuntap::TunTapDevice; | 5 | use embassy_net_tuntap::TunTapDevice; |
| 8 | use embassy_time::{Duration, Timer}; | 6 | use embassy_time::{Duration, Timer}; |
| 9 | use embedded_io_async::Write as _; | 7 | use embedded_io_async::Write as _; |
| 10 | use heapless::Vec; | 8 | use heapless::Vec; |
| 11 | use log::*; | 9 | use log::*; |
| 12 | use rand_core::{OsRng, RngCore}; | 10 | use rand_core::{OsRng, TryRngCore}; |
| 13 | use static_cell::StaticCell; | 11 | use static_cell::StaticCell; |
| 14 | 12 | ||
| 15 | #[derive(Parser)] | 13 | #[derive(Parser)] |
| @@ -24,18 +22,8 @@ struct Opts { | |||
| 24 | } | 22 | } |
| 25 | 23 | ||
| 26 | #[embassy_executor::task] | 24 | #[embassy_executor::task] |
| 27 | async fn net_task(stack: &'static Stack<TunTapDevice>) -> ! { | 25 | async fn net_task(mut runner: embassy_net::Runner<'static, TunTapDevice>) -> ! { |
| 28 | stack.run().await | 26 | runner.run().await |
| 29 | } | ||
| 30 | |||
| 31 | #[derive(Default)] | ||
| 32 | struct StrWrite(pub heapless::Vec<u8, 30>); | ||
| 33 | |||
| 34 | impl core::fmt::Write for StrWrite { | ||
| 35 | fn write_str(&mut self, s: &str) -> Result<(), core::fmt::Error> { | ||
| 36 | self.0.extend_from_slice(s.as_bytes()).unwrap(); | ||
| 37 | Ok(()) | ||
| 38 | } | ||
| 39 | } | 27 | } |
| 40 | 28 | ||
| 41 | #[embassy_executor::task] | 29 | #[embassy_executor::task] |
| @@ -58,16 +46,15 @@ async fn main_task(spawner: Spawner) { | |||
| 58 | 46 | ||
| 59 | // Generate random seed | 47 | // Generate random seed |
| 60 | let mut seed = [0; 8]; | 48 | let mut seed = [0; 8]; |
| 61 | OsRng.fill_bytes(&mut seed); | 49 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 62 | let seed = u64::from_le_bytes(seed); | 50 | let seed = u64::from_le_bytes(seed); |
| 63 | 51 | ||
| 64 | // Init network stack | 52 | // Init network stack |
| 65 | static STACK: StaticCell<Stack<TunTapDevice>> = StaticCell::new(); | ||
| 66 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 53 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 67 | let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); | 54 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 68 | 55 | ||
| 69 | // Launch network task | 56 | // Launch network task |
| 70 | spawner.spawn(net_task(stack)).unwrap(); | 57 | spawner.spawn(net_task(runner)).unwrap(); |
| 71 | 58 | ||
| 72 | // Then we can use it! | 59 | // Then we can use it! |
| 73 | let mut rx_buffer = [0; 4096]; | 60 | let mut rx_buffer = [0; 4096]; |
| @@ -86,9 +73,8 @@ async fn main_task(spawner: Spawner) { | |||
| 86 | 73 | ||
| 87 | // Write some quick output | 74 | // Write some quick output |
| 88 | for i in 1..=5 { | 75 | for i in 1..=5 { |
| 89 | let mut w = StrWrite::default(); | 76 | let s = format!("{}! ", i); |
| 90 | write!(w, "{}! ", i).unwrap(); | 77 | let r = socket.write_all(s.as_bytes()).await; |
| 91 | let r = socket.write_all(&w.0).await; | ||
| 92 | if let Err(e) = r { | 78 | if let Err(e) = r { |
| 93 | warn!("write error: {:?}", e); | 79 | warn!("write error: {:?}", e); |
| 94 | return; | 80 | return; |
