Remove Forever, switch to static_cell.

This commit is contained in:
Dario Nieuwenhuis
2022-08-22 15:51:44 +02:00
parent 1b95990258
commit 478f472784
45 changed files with 139 additions and 220 deletions

View File

@ -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
));

View File

@ -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
));

View File

@ -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)));

View File

@ -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)));

View File

@ -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()));

View File

@ -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()));