aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/std/src')
-rw-r--r--examples/std/src/bin/net.rs18
-rw-r--r--examples/std/src/bin/net_dns.rs18
-rw-r--r--examples/std/src/bin/net_udp.rs18
-rw-r--r--examples/std/src/bin/tcp_accept.rs18
4 files changed, 28 insertions, 44 deletions
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs
index d93616254..b42bfc13b 100644
--- a/examples/std/src/bin/net.rs
+++ b/examples/std/src/bin/net.rs
@@ -11,21 +11,12 @@ use embedded_io::asynch::Write;
11use heapless::Vec; 11use heapless::Vec;
12use log::*; 12use log::*;
13use rand_core::{OsRng, RngCore}; 13use rand_core::{OsRng, RngCore};
14use static_cell::StaticCell; 14use static_cell::{make_static, StaticCell};
15 15
16#[path = "../tuntap.rs"] 16#[path = "../tuntap.rs"]
17mod tuntap; 17mod tuntap;
18 18
19use crate::tuntap::TunTapDevice; 19use crate::tuntap::TunTapDevice;
20
21macro_rules! singleton {
22 ($val:expr) => {{
23 type T = impl Sized;
24 static STATIC_CELL: StaticCell<T> = StaticCell::new();
25 STATIC_CELL.init_with(move || $val)
26 }};
27}
28
29#[derive(Parser)] 20#[derive(Parser)]
30#[clap(version = "1.0")] 21#[clap(version = "1.0")]
31struct Opts { 22struct Opts {
@@ -66,7 +57,12 @@ async fn main_task(spawner: Spawner) {
66 let seed = u64::from_le_bytes(seed); 57 let seed = u64::from_le_bytes(seed);
67 58
68 // Init network stack 59 // Init network stack
69 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 60 let stack = &*make_static!(Stack::new(
61 device,
62 config,
63 make_static!(StackResources::<3>::new()),
64 seed
65 ));
70 66
71 // Launch network task 67 // Launch network task
72 spawner.spawn(net_task(stack)).unwrap(); 68 spawner.spawn(net_task(stack)).unwrap();
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs
index d1e1f8212..932ac5831 100644
--- a/examples/std/src/bin/net_dns.rs
+++ b/examples/std/src/bin/net_dns.rs
@@ -9,21 +9,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
9use heapless::Vec; 9use heapless::Vec;
10use log::*; 10use log::*;
11use rand_core::{OsRng, RngCore}; 11use rand_core::{OsRng, RngCore};
12use static_cell::StaticCell; 12use static_cell::{make_static, StaticCell};
13 13
14#[path = "../tuntap.rs"] 14#[path = "../tuntap.rs"]
15mod tuntap; 15mod tuntap;
16 16
17use crate::tuntap::TunTapDevice; 17use crate::tuntap::TunTapDevice;
18
19macro_rules! singleton {
20 ($val:expr) => {{
21 type T = impl Sized;
22 static STATIC_CELL: StaticCell<T> = StaticCell::new();
23 STATIC_CELL.init_with(move || $val)
24 }};
25}
26
27#[derive(Parser)] 18#[derive(Parser)]
28#[clap(version = "1.0")] 19#[clap(version = "1.0")]
29struct Opts { 20struct Opts {
@@ -65,7 +56,12 @@ async fn main_task(spawner: Spawner) {
65 let seed = u64::from_le_bytes(seed); 56 let seed = u64::from_le_bytes(seed);
66 57
67 // Init network stack 58 // Init network stack
68 let stack: &Stack<_> = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 59 let stack: &Stack<_> = &*make_static!(Stack::new(
60 device,
61 config,
62 make_static!(StackResources::<3>::new()),
63 seed
64 ));
69 65
70 // Launch network task 66 // Launch network task
71 spawner.spawn(net_task(stack)).unwrap(); 67 spawner.spawn(net_task(stack)).unwrap();
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs
index 4df23edf6..d89ec7643 100644
--- a/examples/std/src/bin/net_udp.rs
+++ b/examples/std/src/bin/net_udp.rs
@@ -7,21 +7,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
7use heapless::Vec; 7use heapless::Vec;
8use log::*; 8use log::*;
9use rand_core::{OsRng, RngCore}; 9use rand_core::{OsRng, RngCore};
10use static_cell::StaticCell; 10use static_cell::{make_static, 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
17macro_rules! singleton {
18 ($val:expr) => {{
19 type T = impl Sized;
20 static STATIC_CELL: StaticCell<T> = StaticCell::new();
21 STATIC_CELL.init_with(move || $val)
22 }};
23}
24
25#[derive(Parser)] 16#[derive(Parser)]
26#[clap(version = "1.0")] 17#[clap(version = "1.0")]
27struct Opts { 18struct Opts {
@@ -62,7 +53,12 @@ async fn main_task(spawner: Spawner) {
62 let seed = u64::from_le_bytes(seed); 53 let seed = u64::from_le_bytes(seed);
63 54
64 // Init network stack 55 // Init network stack
65 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 56 let stack = &*make_static!(Stack::new(
57 device,
58 config,
59 make_static!(StackResources::<3>::new()),
60 seed
61 ));
66 62
67 // Launch network task 63 // Launch network task
68 spawner.spawn(net_task(stack)).unwrap(); 64 spawner.spawn(net_task(stack)).unwrap();
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs
index 97ce77f42..d24e218dc 100644
--- a/examples/std/src/bin/tcp_accept.rs
+++ b/examples/std/src/bin/tcp_accept.rs
@@ -12,21 +12,12 @@ use embedded_io::asynch::Write as _;
12use heapless::Vec; 12use heapless::Vec;
13use log::*; 13use log::*;
14use rand_core::{OsRng, RngCore}; 14use rand_core::{OsRng, RngCore};
15use static_cell::StaticCell; 15use static_cell::{make_static, StaticCell};
16 16
17#[path = "../tuntap.rs"] 17#[path = "../tuntap.rs"]
18mod tuntap; 18mod tuntap;
19 19
20use crate::tuntap::TunTapDevice; 20use crate::tuntap::TunTapDevice;
21
22macro_rules! singleton {
23 ($val:expr) => {{
24 type T = impl Sized;
25 static STATIC_CELL: StaticCell<T> = StaticCell::new();
26 STATIC_CELL.init_with(move || $val)
27 }};
28}
29
30#[derive(Parser)] 21#[derive(Parser)]
31#[clap(version = "1.0")] 22#[clap(version = "1.0")]
32struct Opts { 23struct Opts {
@@ -77,7 +68,12 @@ async fn main_task(spawner: Spawner) {
77 let seed = u64::from_le_bytes(seed); 68 let seed = u64::from_le_bytes(seed);
78 69
79 // Init network stack 70 // Init network stack
80 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 71 let stack = &*make_static!(Stack::new(
72 device,
73 config,
74 make_static!(StackResources::<3>::new()),
75 seed
76 ));
81 77
82 // Launch network task 78 // Launch network task
83 spawner.spawn(net_task(stack)).unwrap(); 79 spawner.spawn(net_task(stack)).unwrap();