aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src/bin/net_udp.rs
diff options
context:
space:
mode:
authorMathias <[email protected]>2022-08-23 13:24:52 +0200
committerMathias <[email protected]>2022-08-23 13:24:52 +0200
commit36cf719a1899202caeae39a8a6d5443a4acbdcfe (patch)
tree4b58c2773f577dd7bb739358e48052841fff1432 /examples/std/src/bin/net_udp.rs
parent7e3ce2c90befe19ea30c6a784710f6cebf5a48f2 (diff)
parentcb9f0ef5b800ce4a22cde1805e0eb88425f1e07b (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.rs16
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;
4use embassy_executor::{Executor, Spawner}; 4use embassy_executor::{Executor, Spawner};
5use embassy_net::udp::UdpSocket; 5use embassy_net::udp::UdpSocket;
6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; 6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources};
7use embassy_util::Forever;
8use heapless::Vec; 7use heapless::Vec;
9use log::*; 8use log::*;
10use rand_core::{OsRng, RngCore}; 9use rand_core::{OsRng, RngCore};
10use static_cell::StaticCell;
11 11
12#[path = "../tuntap.rs"] 12#[path = "../tuntap.rs"]
13mod tuntap; 13mod tuntap;
14 14
15use crate::tuntap::TunTapDevice; 15use crate::tuntap::TunTapDevice;
16 16
17macro_rules! forever { 17macro_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
96static EXECUTOR: Forever<Executor> = Forever::new(); 96static EXECUTOR: StaticCell<Executor> = StaticCell::new();
97 97
98fn main() { 98fn 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 });