From 478f4727846f6a43c28fff3b09cb639c0b800465 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 22 Aug 2022 15:51:44 +0200 Subject: Remove Forever, switch to static_cell. --- examples/std/Cargo.toml | 1 + examples/std/src/bin/net.rs | 16 ++++++++-------- examples/std/src/bin/net_udp.rs | 16 ++++++++-------- examples/std/src/bin/serial.rs | 6 +++--- 4 files changed, 20 insertions(+), 19 deletions(-) (limited to 'examples/std') diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index b7009017c..164a2b42d 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -20,3 +20,4 @@ libc = "0.2.101" clap = { version = "3.0.0-beta.5", features = ["derive"] } rand_core = { version = "0.6.3", features = ["std"] } heapless = { version = "0.7.5", default-features = false } +static_cell = "1.0" diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 528609260..9b1450b72 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs @@ -4,22 +4,22 @@ use clap::Parser; use embassy_executor::{Executor, Spawner}; use embassy_net::tcp::TcpSocket; use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; -use embassy_util::Forever; use embedded_io::asynch::Write; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; +use static_cell::StaticCell; #[path = "../tuntap.rs"] mod tuntap; use crate::tuntap::TunTapDevice; -macro_rules! forever { +macro_rules! singleton { ($val:expr) => {{ type T = impl Sized; - static FOREVER: Forever = Forever::new(); - FOREVER.put_with(move || $val) + static STATIC_CELL: StaticCell = StaticCell::new(); + STATIC_CELL.init_with(move || $val) }}; } @@ -63,10 +63,10 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*forever!(Stack::new( + let stack = &*singleton!(Stack::new( device, config, - forever!(StackResources::<1, 2, 8>::new()), + singleton!(StackResources::<1, 2, 8>::new()), seed )); @@ -97,7 +97,7 @@ async fn main_task(spawner: Spawner) { } } -static EXECUTOR: Forever = Forever::new(); +static EXECUTOR: StaticCell = StaticCell::new(); fn main() { env_logger::builder() @@ -106,7 +106,7 @@ fn main() { .format_timestamp_nanos() .init(); - let executor = EXECUTOR.put(Executor::new()); + let executor = EXECUTOR.init(Executor::new()); executor.run(|spawner| { spawner.spawn(main_task(spawner)).unwrap(); }); 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; use embassy_executor::{Executor, Spawner}; use embassy_net::udp::UdpSocket; use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; -use embassy_util::Forever; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; +use static_cell::StaticCell; #[path = "../tuntap.rs"] mod tuntap; use crate::tuntap::TunTapDevice; -macro_rules! forever { +macro_rules! singleton { ($val:expr) => {{ type T = impl Sized; - static FOREVER: Forever = Forever::new(); - FOREVER.put_with(move || $val) + static STATIC_CELL: StaticCell = StaticCell::new(); + STATIC_CELL.init_with(move || $val) }}; } @@ -62,10 +62,10 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*forever!(Stack::new( + let stack = &*singleton!(Stack::new( device, config, - forever!(StackResources::<1, 2, 8>::new()), + singleton!(StackResources::<1, 2, 8>::new()), seed )); @@ -93,7 +93,7 @@ async fn main_task(spawner: Spawner) { } } -static EXECUTOR: Forever = Forever::new(); +static EXECUTOR: StaticCell = StaticCell::new(); fn main() { env_logger::builder() @@ -102,7 +102,7 @@ fn main() { .format_timestamp_nanos() .init(); - let executor = EXECUTOR.put(Executor::new()); + let executor = EXECUTOR.init(Executor::new()); executor.run(|spawner| { spawner.spawn(main_task(spawner)).unwrap(); }); diff --git a/examples/std/src/bin/serial.rs b/examples/std/src/bin/serial.rs index 35cba4cee..85ee54f70 100644 --- a/examples/std/src/bin/serial.rs +++ b/examples/std/src/bin/serial.rs @@ -5,10 +5,10 @@ mod serial_port; use async_io::Async; use embassy_executor::Executor; -use embassy_util::Forever; use embedded_io::asynch::Read; use log::*; use nix::sys::termios; +use static_cell::StaticCell; use self::serial_port::SerialPort; @@ -40,7 +40,7 @@ async fn run() { } } -static EXECUTOR: Forever = Forever::new(); +static EXECUTOR: StaticCell = StaticCell::new(); fn main() { env_logger::builder() @@ -49,7 +49,7 @@ fn main() { .format_timestamp_nanos() .init(); - let executor = EXECUTOR.put(Executor::new()); + let executor = EXECUTOR.init(Executor::new()); executor.run(|spawner| { spawner.spawn(run()).unwrap(); }); -- cgit From 21072bee48ff6ec19b79e0d9527ad8cc34a4e9e0 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 22 Aug 2022 21:46:09 +0200 Subject: split `embassy-util` into `embassy-futures`, `embassy-sync`. --- examples/std/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/std') diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 164a2b42d..c7cec6b19 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -4,7 +4,7 @@ name = "embassy-std-examples" version = "0.1.0" [dependencies] -embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } +embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["log"] } embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] } embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] } embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] } -- cgit