Remove Forever, switch to static_cell.
This commit is contained in:
@ -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"
|
||||
|
@ -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<T> = Forever::new();
|
||||
FOREVER.put_with(move || $val)
|
||||
static STATIC_CELL: StaticCell<T> = 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<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = 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();
|
||||
});
|
||||
|
@ -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<T> = Forever::new();
|
||||
FOREVER.put_with(move || $val)
|
||||
static STATIC_CELL: StaticCell<T> = 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<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = 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();
|
||||
});
|
||||
|
@ -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<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = 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();
|
||||
});
|
||||
|
Reference in New Issue
Block a user