aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src/bin/net.rs
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-06-19 15:52:33 -0500
committerxoviat <[email protected]>2023-06-19 15:52:33 -0500
commitaaad9068156305e5f6f41ee4013e025083bd0668 (patch)
tree67a08c8a512e8791433891a3b6deec813fc4c578 /examples/std/src/bin/net.rs
parent35083b262b364387713f4273649b62180123182c (diff)
parent3c70f799a28f5f28d84fa8ee8b4b232f5e9aad82 (diff)
Merge branch 'main' of https://github.com/embassy-rs/embassy into can
Diffstat (limited to 'examples/std/src/bin/net.rs')
-rw-r--r--examples/std/src/bin/net.rs22
1 files changed, 9 insertions, 13 deletions
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs
index d93616254..3aadb029d 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 {
@@ -51,13 +42,13 @@ async fn main_task(spawner: Spawner) {
51 42
52 // Choose between dhcp or static ip 43 // Choose between dhcp or static ip
53 let config = if opts.static_ip { 44 let config = if opts.static_ip {
54 Config::Static(embassy_net::StaticConfig { 45 Config::ipv4_static(embassy_net::StaticConfigV4 {
55 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), 46 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
56 dns_servers: Vec::new(), 47 dns_servers: Vec::new(),
57 gateway: Some(Ipv4Address::new(192, 168, 69, 1)), 48 gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
58 }) 49 })
59 } else { 50 } else {
60 Config::Dhcp(Default::default()) 51 Config::dhcpv4(Default::default())
61 }; 52 };
62 53
63 // Generate random seed 54 // Generate random seed
@@ -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();