diff options
| author | Mathias <[email protected]> | 2022-08-23 13:24:52 +0200 |
|---|---|---|
| committer | Mathias <[email protected]> | 2022-08-23 13:24:52 +0200 |
| commit | 36cf719a1899202caeae39a8a6d5443a4acbdcfe (patch) | |
| tree | 4b58c2773f577dd7bb739358e48052841fff1432 /examples/std/src/bin/net_udp.rs | |
| parent | 7e3ce2c90befe19ea30c6a784710f6cebf5a48f2 (diff) | |
| parent | cb9f0ef5b800ce4a22cde1805e0eb88425f1e07b (diff) | |
Merge branch 'master' of https://github.com/embassy-rs/embassy into embassy-rp/dma
Diffstat (limited to 'examples/std/src/bin/net_udp.rs')
| -rw-r--r-- | examples/std/src/bin/net_udp.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index 07e11c385..392a97f0d 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -4,21 +4,21 @@ use clap::Parser; | |||
| 4 | use embassy_executor::{Executor, Spawner}; | 4 | use embassy_executor::{Executor, Spawner}; |
| 5 | use embassy_net::udp::UdpSocket; | 5 | use embassy_net::udp::UdpSocket; |
| 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; | 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; |
| 7 | use embassy_util::Forever; | ||
| 8 | use heapless::Vec; | 7 | use heapless::Vec; |
| 9 | use log::*; | 8 | use log::*; |
| 10 | use rand_core::{OsRng, RngCore}; | 9 | use rand_core::{OsRng, RngCore}; |
| 10 | use static_cell::StaticCell; | ||
| 11 | 11 | ||
| 12 | #[path = "../tuntap.rs"] | 12 | #[path = "../tuntap.rs"] |
| 13 | mod tuntap; | 13 | mod tuntap; |
| 14 | 14 | ||
| 15 | use crate::tuntap::TunTapDevice; | 15 | use crate::tuntap::TunTapDevice; |
| 16 | 16 | ||
| 17 | macro_rules! forever { | 17 | macro_rules! singleton { |
| 18 | ($val:expr) => {{ | 18 | ($val:expr) => {{ |
| 19 | type T = impl Sized; | 19 | type T = impl Sized; |
| 20 | static FOREVER: Forever<T> = Forever::new(); | 20 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 21 | FOREVER.put_with(move || $val) | 21 | STATIC_CELL.init_with(move || $val) |
| 22 | }}; | 22 | }}; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| @@ -62,10 +62,10 @@ async fn main_task(spawner: Spawner) { | |||
| 62 | let seed = u64::from_le_bytes(seed); | 62 | let seed = u64::from_le_bytes(seed); |
| 63 | 63 | ||
| 64 | // Init network stack | 64 | // Init network stack |
| 65 | let stack = &*forever!(Stack::new( | 65 | let stack = &*singleton!(Stack::new( |
| 66 | device, | 66 | device, |
| 67 | config, | 67 | config, |
| 68 | forever!(StackResources::<1, 2, 8>::new()), | 68 | singleton!(StackResources::<1, 2, 8>::new()), |
| 69 | seed | 69 | seed |
| 70 | )); | 70 | )); |
| 71 | 71 | ||
| @@ -93,7 +93,7 @@ async fn main_task(spawner: Spawner) { | |||
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | static EXECUTOR: Forever<Executor> = Forever::new(); | 96 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 97 | 97 | ||
| 98 | fn main() { | 98 | fn main() { |
| 99 | env_logger::builder() | 99 | env_logger::builder() |
| @@ -102,7 +102,7 @@ fn main() { | |||
| 102 | .format_timestamp_nanos() | 102 | .format_timestamp_nanos() |
| 103 | .init(); | 103 | .init(); |
| 104 | 104 | ||
| 105 | let executor = EXECUTOR.put(Executor::new()); | 105 | let executor = EXECUTOR.init(Executor::new()); |
| 106 | executor.run(|spawner| { | 106 | executor.run(|spawner| { |
| 107 | spawner.spawn(main_task(spawner)).unwrap(); | 107 | spawner.spawn(main_task(spawner)).unwrap(); |
| 108 | }); | 108 | }); |
