aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'examples/std/src/bin')
-rw-r--r--examples/std/src/bin/net.rs22
-rw-r--r--examples/std/src/bin/net_dns.rs22
-rw-r--r--examples/std/src/bin/net_udp.rs22
-rw-r--r--examples/std/src/bin/tcp_accept.rs24
4 files changed, 37 insertions, 53 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();
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs
index d1e1f8212..65b5a2cd9 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 {
@@ -49,14 +40,14 @@ async fn main_task(spawner: Spawner) {
49 40
50 // Choose between dhcp or static ip 41 // Choose between dhcp or static ip
51 let config = if opts.static_ip { 42 let config = if opts.static_ip {
52 Config::Static(embassy_net::StaticConfig { 43 Config::ipv4_static(embassy_net::StaticConfigV4 {
53 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24), 44 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24),
54 dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()]) 45 dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()])
55 .unwrap(), 46 .unwrap(),
56 gateway: Some(Ipv4Address::new(192, 168, 69, 100)), 47 gateway: Some(Ipv4Address::new(192, 168, 69, 100)),
57 }) 48 })
58 } else { 49 } else {
59 Config::Dhcp(Default::default()) 50 Config::dhcpv4(Default::default())
60 }; 51 };
61 52
62 // Generate random seed 53 // Generate random seed
@@ -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..3fc46156c 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 {
@@ -47,13 +38,13 @@ async fn main_task(spawner: Spawner) {
47 38
48 // Choose between dhcp or static ip 39 // Choose between dhcp or static ip
49 let config = if opts.static_ip { 40 let config = if opts.static_ip {
50 Config::Static(embassy_net::StaticConfig { 41 Config::ipv4_static(embassy_net::StaticConfigV4 {
51 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), 42 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
52 dns_servers: Vec::new(), 43 dns_servers: Vec::new(),
53 gateway: Some(Ipv4Address::new(192, 168, 69, 1)), 44 gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
54 }) 45 })
55 } else { 46 } else {
56 Config::Dhcp(Default::default()) 47 Config::dhcpv4(Default::default())
57 }; 48 };
58 49
59 // Generate random seed 50 // Generate random seed
@@ -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..df09986ac 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 {
@@ -62,13 +53,13 @@ async fn main_task(spawner: Spawner) {
62 53
63 // Choose between dhcp or static ip 54 // Choose between dhcp or static ip
64 let config = if opts.static_ip { 55 let config = if opts.static_ip {
65 Config::Static(embassy_net::StaticConfig { 56 Config::ipv4_static(embassy_net::StaticConfigV4 {
66 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), 57 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
67 dns_servers: Vec::new(), 58 dns_servers: Vec::new(),
68 gateway: Some(Ipv4Address::new(192, 168, 69, 1)), 59 gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
69 }) 60 })
70 } else { 61 } else {
71 Config::Dhcp(Default::default()) 62 Config::dhcpv4(Default::default())
72 }; 63 };
73 64
74 // Generate random seed 65 // Generate random seed
@@ -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();
@@ -112,7 +108,7 @@ async fn main_task(spawner: Spawner) {
112 info!("Closing the connection"); 108 info!("Closing the connection");
113 socket.abort(); 109 socket.abort();
114 info!("Flushing the RST out..."); 110 info!("Flushing the RST out...");
115 socket.flush().await; 111 _ = socket.flush().await;
116 info!("Finished with the socket"); 112 info!("Finished with the socket");
117 } 113 }
118} 114}