Remove Forever, switch to static_cell.
This commit is contained in:
@ -22,6 +22,7 @@ embedded-io = "0.3.0"
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.3"
|
||||
|
||||
static_cell = "1.0"
|
||||
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
|
@ -8,7 +8,7 @@ use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_util::blocking_mutex::raw::NoopRawMutex;
|
||||
use embassy_util::channel::mpmc::{Channel, Receiver, Sender};
|
||||
use embassy_util::Forever;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
enum LedState {
|
||||
@ -16,7 +16,7 @@ enum LedState {
|
||||
Off,
|
||||
}
|
||||
|
||||
static CHANNEL: Forever<Channel<NoopRawMutex, LedState, 1>> = Forever::new();
|
||||
static CHANNEL: StaticCell<Channel<NoopRawMutex, LedState, 1>> = StaticCell::new();
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) {
|
||||
@ -43,7 +43,7 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let channel = CHANNEL.put(Channel::new());
|
||||
let channel = CHANNEL.init(Channel::new());
|
||||
|
||||
unwrap!(spawner.spawn(send_task(channel.sender())));
|
||||
unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver())));
|
||||
|
@ -63,7 +63,7 @@ use embassy_nrf::executor::{Executor, InterruptExecutor};
|
||||
use embassy_nrf::interrupt;
|
||||
use embassy_nrf::interrupt::InterruptExt;
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use embassy_util::Forever;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task]
|
||||
@ -108,9 +108,9 @@ async fn run_low() {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new();
|
||||
static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new();
|
||||
static EXECUTOR_LOW: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::SWI1_EGU1>> = StaticCell::new();
|
||||
static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::SWI0_EGU0>> = StaticCell::new();
|
||||
static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@ -121,19 +121,19 @@ fn main() -> ! {
|
||||
// High-priority executor: SWI1_EGU1, priority level 6
|
||||
let irq = interrupt::take!(SWI1_EGU1);
|
||||
irq.set_priority(interrupt::Priority::P6);
|
||||
let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq));
|
||||
let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq));
|
||||
let spawner = executor.start();
|
||||
unwrap!(spawner.spawn(run_high()));
|
||||
|
||||
// Medium-priority executor: SWI0_EGU0, priority level 7
|
||||
let irq = interrupt::take!(SWI0_EGU0);
|
||||
irq.set_priority(interrupt::Priority::P7);
|
||||
let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq));
|
||||
let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq));
|
||||
let spawner = executor.start();
|
||||
unwrap!(spawner.spawn(run_med()));
|
||||
|
||||
// Low priority executor: runs in thread mode, using WFE/SEV
|
||||
let executor = EXECUTOR_LOW.put(Executor::new());
|
||||
let executor = EXECUTOR_LOW.init(Executor::new());
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run_low()));
|
||||
});
|
||||
|
@ -8,7 +8,7 @@ use defmt::{info, unwrap};
|
||||
use embassy_executor::raw::TaskStorage;
|
||||
use embassy_executor::Executor;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_util::Forever;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
async fn run1() {
|
||||
@ -25,14 +25,14 @@ async fn run2() {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let _p = embassy_nrf::init(Default::default());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
let executor = EXECUTOR.init(Executor::new());
|
||||
|
||||
let run1_task = TaskStorage::new();
|
||||
let run2_task = TaskStorage::new();
|
||||
|
@ -18,17 +18,17 @@ use embassy_usb::{Builder, Config, UsbDevice};
|
||||
use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
|
||||
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
|
||||
use embassy_util::channel::mpmc::Channel;
|
||||
use embassy_util::Forever;
|
||||
use embedded_io::asynch::{Read, Write};
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>;
|
||||
|
||||
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)
|
||||
}};
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ async fn main(spawner: Spawner) {
|
||||
control_buf: [u8; 128],
|
||||
serial_state: State<'static>,
|
||||
}
|
||||
let res: &mut Resources = forever!(Resources {
|
||||
let res: &mut Resources = singleton!(Resources {
|
||||
device_descriptor: [0; 256],
|
||||
config_descriptor: [0; 256],
|
||||
bos_descriptor: [0; 256],
|
||||
@ -174,10 +174,10 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
// Init network stack
|
||||
let device = Device { mac_addr: our_mac_addr };
|
||||
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
|
||||
));
|
||||
|
||||
|
@ -12,7 +12,7 @@ use embassy_nrf::{interrupt, pac, peripherals};
|
||||
use embassy_usb::driver::EndpointError;
|
||||
use embassy_usb::{Builder, Config, UsbDevice};
|
||||
use embassy_usb_serial::{CdcAcmClass, State};
|
||||
use embassy_util::Forever;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>;
|
||||
@ -67,8 +67,8 @@ async fn main(spawner: Spawner) {
|
||||
control_buf: [u8; 64],
|
||||
serial_state: State<'static>,
|
||||
}
|
||||
static RESOURCES: Forever<Resources> = Forever::new();
|
||||
let res = RESOURCES.put(Resources {
|
||||
static RESOURCES: StaticCell<Resources> = StaticCell::new();
|
||||
let res = RESOURCES.init(Resources {
|
||||
device_descriptor: [0; 256],
|
||||
config_descriptor: [0; 256],
|
||||
bos_descriptor: [0; 256],
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -23,3 +23,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
nb = "1.0.0"
|
||||
embedded-storage = "0.3.0"
|
||||
static_cell = "1.0"
|
||||
|
@ -63,7 +63,7 @@ use embassy_stm32::executor::{Executor, InterruptExecutor};
|
||||
use embassy_stm32::interrupt;
|
||||
use embassy_stm32::interrupt::InterruptExt;
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use embassy_util::Forever;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task]
|
||||
@ -108,9 +108,9 @@ async fn run_low() {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::UART4>> = Forever::new();
|
||||
static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::UART5>> = Forever::new();
|
||||
static EXECUTOR_LOW: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new();
|
||||
static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new();
|
||||
static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@ -121,19 +121,19 @@ fn main() -> ! {
|
||||
// High-priority executor: SWI1_EGU1, priority level 6
|
||||
let irq = interrupt::take!(UART4);
|
||||
irq.set_priority(interrupt::Priority::P6);
|
||||
let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq));
|
||||
let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq));
|
||||
let spawner = executor.start();
|
||||
unwrap!(spawner.spawn(run_high()));
|
||||
|
||||
// Medium-priority executor: SWI0_EGU0, priority level 7
|
||||
let irq = interrupt::take!(UART5);
|
||||
irq.set_priority(interrupt::Priority::P7);
|
||||
let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq));
|
||||
let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq));
|
||||
let spawner = executor.start();
|
||||
unwrap!(spawner.spawn(run_med()));
|
||||
|
||||
// Low priority executor: runs in thread mode, using WFE/SEV
|
||||
let executor = EXECUTOR_LOW.put(Executor::new());
|
||||
let executor = EXECUTOR_LOW.init(Executor::new());
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run_low()));
|
||||
});
|
||||
|
@ -23,6 +23,7 @@ heapless = { version = "0.7.5", default-features = false }
|
||||
nb = "1.0.0"
|
||||
embedded-storage = "0.3.0"
|
||||
micromath = "2.0.0"
|
||||
static_cell = "1.0"
|
||||
|
||||
usb-device = "0.2"
|
||||
usbd-serial = "0.1.1"
|
||||
|
@ -63,7 +63,7 @@ use embassy_stm32::executor::{Executor, InterruptExecutor};
|
||||
use embassy_stm32::interrupt;
|
||||
use embassy_stm32::interrupt::InterruptExt;
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use embassy_util::Forever;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task]
|
||||
@ -108,9 +108,9 @@ async fn run_low() {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::UART4>> = Forever::new();
|
||||
static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::UART5>> = Forever::new();
|
||||
static EXECUTOR_LOW: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new();
|
||||
static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new();
|
||||
static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@ -121,19 +121,19 @@ fn main() -> ! {
|
||||
// High-priority executor: SWI1_EGU1, priority level 6
|
||||
let irq = interrupt::take!(UART4);
|
||||
irq.set_priority(interrupt::Priority::P6);
|
||||
let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq));
|
||||
let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq));
|
||||
let spawner = executor.start();
|
||||
unwrap!(spawner.spawn(run_high()));
|
||||
|
||||
// Medium-priority executor: SWI0_EGU0, priority level 7
|
||||
let irq = interrupt::take!(UART5);
|
||||
irq.set_priority(interrupt::Priority::P7);
|
||||
let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq));
|
||||
let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq));
|
||||
let spawner = executor.start();
|
||||
unwrap!(spawner.spawn(run_med()));
|
||||
|
||||
// Low priority executor: runs in thread mode, using WFE/SEV
|
||||
let executor = EXECUTOR_LOW.put(Executor::new());
|
||||
let executor = EXECUTOR_LOW.init(Executor::new());
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run_low()));
|
||||
});
|
||||
|
@ -24,3 +24,4 @@ nb = "1.0.0"
|
||||
rand_core = "0.6.3"
|
||||
critical-section = "1.1"
|
||||
embedded-storage = "0.3.0"
|
||||
static_cell = "1.0"
|
||||
|
@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::time::mhz;
|
||||
use embassy_stm32::{interrupt, Config};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_util::Forever;
|
||||
use embedded_io::asynch::Write;
|
||||
use rand_core::RngCore;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
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)
|
||||
}};
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
|
||||
let device = unsafe {
|
||||
Ethernet::new(
|
||||
forever!(State::new()),
|
||||
singleton!(State::new()),
|
||||
p.ETH,
|
||||
eth_int,
|
||||
p.PA1,
|
||||
@ -78,10 +78,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
//});
|
||||
|
||||
// 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
|
||||
));
|
||||
|
||||
|
@ -28,6 +28,7 @@ critical-section = "1.1"
|
||||
micromath = "2.0.0"
|
||||
stm32-fmc = "0.2.4"
|
||||
embedded-storage = "0.3.0"
|
||||
static_cell = "1.0"
|
||||
|
||||
# cargo build/run
|
||||
[profile.dev]
|
||||
|
@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::time::mhz;
|
||||
use embassy_stm32::{interrupt, Config};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_util::Forever;
|
||||
use embedded_io::asynch::Write;
|
||||
use rand_core::RngCore;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
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)
|
||||
}};
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
|
||||
let device = unsafe {
|
||||
Ethernet::new(
|
||||
forever!(State::new()),
|
||||
singleton!(State::new()),
|
||||
p.ETH,
|
||||
eth_int,
|
||||
p.PA1,
|
||||
@ -79,10 +79,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
//});
|
||||
|
||||
// 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
|
||||
));
|
||||
|
||||
|
@ -13,17 +13,17 @@ use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::time::mhz;
|
||||
use embassy_stm32::{interrupt, Config};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_util::Forever;
|
||||
use embedded_io::asynch::Write;
|
||||
use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect};
|
||||
use rand_core::RngCore;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
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)
|
||||
}};
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
|
||||
let device = unsafe {
|
||||
Ethernet::new(
|
||||
forever!(State::new()),
|
||||
singleton!(State::new()),
|
||||
p.ETH,
|
||||
eth_int,
|
||||
p.PA1,
|
||||
@ -80,10 +80,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
//});
|
||||
|
||||
// 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
|
||||
));
|
||||
|
||||
|
@ -12,8 +12,8 @@ use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::peripherals::SPI3;
|
||||
use embassy_stm32::time::mhz;
|
||||
use embassy_stm32::{spi, Config};
|
||||
use embassy_util::Forever;
|
||||
use heapless::String;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task]
|
||||
@ -31,7 +31,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@ -54,7 +54,7 @@ fn main() -> ! {
|
||||
spi::Config::default(),
|
||||
);
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
let executor = EXECUTOR.init(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(main_task(spi)));
|
||||
|
@ -11,8 +11,8 @@ use embassy_executor::Executor;
|
||||
use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
|
||||
use embassy_stm32::time::mhz;
|
||||
use embassy_stm32::{spi, Config};
|
||||
use embassy_util::Forever;
|
||||
use heapless::String;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task]
|
||||
@ -27,7 +27,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@ -50,7 +50,7 @@ fn main() -> ! {
|
||||
spi::Config::default(),
|
||||
);
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
let executor = EXECUTOR.init(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(main_task(spi)));
|
||||
|
@ -7,7 +7,7 @@ use defmt::*;
|
||||
use embassy_executor::Executor;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_util::Forever;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task]
|
||||
@ -27,13 +27,13 @@ async fn main_task() {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
let executor = EXECUTOR.init(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(main_task()));
|
||||
|
@ -9,8 +9,8 @@ use defmt::*;
|
||||
use embassy_executor::Executor;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_util::Forever;
|
||||
use heapless::String;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task]
|
||||
@ -30,13 +30,13 @@ async fn main_task() {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
let executor = EXECUTOR.init(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(main_task()));
|
||||
|
@ -29,3 +29,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
embedded-hal = "0.2.6"
|
||||
static_cell = "1.0"
|
||||
|
@ -8,7 +8,7 @@ use defmt::*;
|
||||
use embassy_executor::raw::TaskStorage;
|
||||
use embassy_executor::Executor;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_util::Forever;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
async fn run1() {
|
||||
@ -25,14 +25,14 @@ async fn run2() {
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let _p = embassy_stm32::init(Default::default());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
let executor = EXECUTOR.init(Executor::new());
|
||||
|
||||
let run1_task = TaskStorage::new();
|
||||
let run2_task = TaskStorage::new();
|
||||
|
@ -28,3 +28,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
rand_core = { version = "0.6.3", default-features = false }
|
||||
embedded-io = { version = "0.3.0", features = ["async"] }
|
||||
static_cell = "1.0"
|
||||
|
@ -19,18 +19,18 @@ use embassy_usb::{Builder, UsbDevice};
|
||||
use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
|
||||
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
|
||||
use embassy_util::channel::mpmc::Channel;
|
||||
use embassy_util::Forever;
|
||||
use embedded_io::asynch::{Read, Write};
|
||||
use rand_core::RngCore;
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>;
|
||||
|
||||
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)
|
||||
}};
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ async fn main(spawner: Spawner) {
|
||||
control_buf: [u8; 128],
|
||||
serial_state: State<'static>,
|
||||
}
|
||||
let res: &mut Resources = forever!(Resources {
|
||||
let res: &mut Resources = singleton!(Resources {
|
||||
device_descriptor: [0; 256],
|
||||
config_descriptor: [0; 256],
|
||||
bos_descriptor: [0; 256],
|
||||
@ -171,10 +171,10 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
// Init network stack
|
||||
let device = Device { mac_addr: our_mac_addr };
|
||||
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
|
||||
));
|
||||
|
||||
|
Reference in New Issue
Block a user