diff options
| author | Quentin Smith <[email protected]> | 2022-08-23 23:01:51 -0400 |
|---|---|---|
| committer | Quentin Smith <[email protected]> | 2022-08-23 23:01:51 -0400 |
| commit | 2900ab79e7afa0ca3e0d800f8a91c3253a333db1 (patch) | |
| tree | a5066235f8b1ac6c2520105db2e5c48630bc006d /examples/std/src/bin/net.rs | |
| parent | 14eae9ca06f63a69ccc29d5fd9e1dec3848a3e98 (diff) | |
| parent | 529535194d4b5d58b31fd6a7541176105e3c63f7 (diff) | |
Merge remote-tracking branch 'origin/master' into nrf-pdm
Diffstat (limited to 'examples/std/src/bin/net.rs')
| -rw-r--r-- | examples/std/src/bin/net.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 528609260..9b1450b72 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -4,22 +4,22 @@ use clap::Parser; | |||
| 4 | use embassy_executor::{Executor, Spawner}; | 4 | use embassy_executor::{Executor, Spawner}; |
| 5 | use embassy_net::tcp::TcpSocket; | 5 | use embassy_net::tcp::TcpSocket; |
| 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; |
| 7 | use embassy_util::Forever; | ||
| 8 | use embedded_io::asynch::Write; | 7 | use embedded_io::asynch::Write; |
| 9 | use heapless::Vec; | 8 | use heapless::Vec; |
| 10 | use log::*; | 9 | use log::*; |
| 11 | use rand_core::{OsRng, RngCore}; | 10 | use rand_core::{OsRng, RngCore}; |
| 11 | use static_cell::StaticCell; | ||
| 12 | 12 | ||
| 13 | #[path = "../tuntap.rs"] | 13 | #[path = "../tuntap.rs"] |
| 14 | mod tuntap; | 14 | mod tuntap; |
| 15 | 15 | ||
| 16 | use crate::tuntap::TunTapDevice; | 16 | use crate::tuntap::TunTapDevice; |
| 17 | 17 | ||
| 18 | macro_rules! forever { | 18 | macro_rules! singleton { |
| 19 | ($val:expr) => {{ | 19 | ($val:expr) => {{ |
| 20 | type T = impl Sized; | 20 | type T = impl Sized; |
| 21 | static FOREVER: Forever<T> = Forever::new(); | 21 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 22 | FOREVER.put_with(move || $val) | 22 | STATIC_CELL.init_with(move || $val) |
| 23 | }}; | 23 | }}; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| @@ -63,10 +63,10 @@ async fn main_task(spawner: Spawner) { | |||
| 63 | let seed = u64::from_le_bytes(seed); | 63 | let seed = u64::from_le_bytes(seed); |
| 64 | 64 | ||
| 65 | // Init network stack | 65 | // Init network stack |
| 66 | let stack = &*forever!(Stack::new( | 66 | let stack = &*singleton!(Stack::new( |
| 67 | device, | 67 | device, |
| 68 | config, | 68 | config, |
| 69 | forever!(StackResources::<1, 2, 8>::new()), | 69 | singleton!(StackResources::<1, 2, 8>::new()), |
| 70 | seed | 70 | seed |
| 71 | )); | 71 | )); |
| 72 | 72 | ||
| @@ -97,7 +97,7 @@ async fn main_task(spawner: Spawner) { | |||
| 97 | } | 97 | } |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | static EXECUTOR: Forever<Executor> = Forever::new(); | 100 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 101 | 101 | ||
| 102 | fn main() { | 102 | fn main() { |
| 103 | env_logger::builder() | 103 | env_logger::builder() |
| @@ -106,7 +106,7 @@ fn main() { | |||
| 106 | .format_timestamp_nanos() | 106 | .format_timestamp_nanos() |
| 107 | .init(); | 107 | .init(); |
| 108 | 108 | ||
| 109 | let executor = EXECUTOR.put(Executor::new()); | 109 | let executor = EXECUTOR.init(Executor::new()); |
| 110 | executor.run(|spawner| { | 110 | executor.run(|spawner| { |
| 111 | spawner.spawn(main_task(spawner)).unwrap(); | 111 | spawner.spawn(main_task(spawner)).unwrap(); |
| 112 | }); | 112 | }); |
