diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-08-22 14:12:13 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-22 14:12:13 +0000 |
| commit | 381ac97746c318963b42eec6ced6773301c91519 (patch) | |
| tree | b1b3f644b77c6fcf4a0bbe2eabe19caba27c4c08 /examples | |
| parent | 1b9599025868d3a5d0d8e773593b05df8b2fecf2 (diff) | |
| parent | 478f4727846f6a43c28fff3b09cb639c0b800465 (diff) | |
Merge #920
920: Remove Forever, switch to static_cell. r=Dirbaio a=Dirbaio
Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
27 files changed, 107 insertions, 99 deletions
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 2fcc31221..17f29b8fb 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -22,6 +22,7 @@ embedded-io = "0.3.0" | |||
| 22 | defmt = "0.3" | 22 | defmt = "0.3" |
| 23 | defmt-rtt = "0.3" | 23 | defmt-rtt = "0.3" |
| 24 | 24 | ||
| 25 | static_cell = "1.0" | ||
| 25 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 26 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 26 | cortex-m-rt = "0.7.0" | 27 | cortex-m-rt = "0.7.0" |
| 27 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 28 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs index c9c458aec..d250b6a5c 100644 --- a/examples/nrf/src/bin/channel_sender_receiver.rs +++ b/examples/nrf/src/bin/channel_sender_receiver.rs | |||
| @@ -8,7 +8,7 @@ use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; | |||
| 8 | use embassy_time::{Duration, Timer}; | 8 | use embassy_time::{Duration, Timer}; |
| 9 | use embassy_util::blocking_mutex::raw::NoopRawMutex; | 9 | use embassy_util::blocking_mutex::raw::NoopRawMutex; |
| 10 | use embassy_util::channel::mpmc::{Channel, Receiver, Sender}; | 10 | use embassy_util::channel::mpmc::{Channel, Receiver, Sender}; |
| 11 | use embassy_util::Forever; | 11 | use static_cell::StaticCell; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | enum LedState { | 14 | enum LedState { |
| @@ -16,7 +16,7 @@ enum LedState { | |||
| 16 | Off, | 16 | Off, |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | static CHANNEL: Forever<Channel<NoopRawMutex, LedState, 1>> = Forever::new(); | 19 | static CHANNEL: StaticCell<Channel<NoopRawMutex, LedState, 1>> = StaticCell::new(); |
| 20 | 20 | ||
| 21 | #[embassy_executor::task] | 21 | #[embassy_executor::task] |
| 22 | async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) { | 22 | 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 | |||
| 43 | #[embassy_executor::main] | 43 | #[embassy_executor::main] |
| 44 | async fn main(spawner: Spawner) { | 44 | async fn main(spawner: Spawner) { |
| 45 | let p = embassy_nrf::init(Default::default()); | 45 | let p = embassy_nrf::init(Default::default()); |
| 46 | let channel = CHANNEL.put(Channel::new()); | 46 | let channel = CHANNEL.init(Channel::new()); |
| 47 | 47 | ||
| 48 | unwrap!(spawner.spawn(send_task(channel.sender()))); | 48 | unwrap!(spawner.spawn(send_task(channel.sender()))); |
| 49 | unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver()))); | 49 | unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver()))); |
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs index b653689a7..25806ae48 100644 --- a/examples/nrf/src/bin/multiprio.rs +++ b/examples/nrf/src/bin/multiprio.rs | |||
| @@ -63,7 +63,7 @@ use embassy_nrf::executor::{Executor, InterruptExecutor}; | |||
| 63 | use embassy_nrf::interrupt; | 63 | use embassy_nrf::interrupt; |
| 64 | use embassy_nrf::interrupt::InterruptExt; | 64 | use embassy_nrf::interrupt::InterruptExt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use embassy_util::Forever; | 66 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| 68 | 68 | ||
| 69 | #[embassy_executor::task] | 69 | #[embassy_executor::task] |
| @@ -108,9 +108,9 @@ async fn run_low() { | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new(); | 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::SWI1_EGU1>> = StaticCell::new(); |
| 112 | static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new(); | 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::SWI0_EGU0>> = StaticCell::new(); |
| 113 | static EXECUTOR_LOW: Forever<Executor> = Forever::new(); | 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 114 | ||
| 115 | #[entry] | 115 | #[entry] |
| 116 | fn main() -> ! { | 116 | fn main() -> ! { |
| @@ -121,19 +121,19 @@ fn main() -> ! { | |||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 121 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 122 | let irq = interrupt::take!(SWI1_EGU1); | 122 | let irq = interrupt::take!(SWI1_EGU1); |
| 123 | irq.set_priority(interrupt::Priority::P6); | 123 | irq.set_priority(interrupt::Priority::P6); |
| 124 | let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); | 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); |
| 125 | let spawner = executor.start(); | 125 | let spawner = executor.start(); |
| 126 | unwrap!(spawner.spawn(run_high())); | 126 | unwrap!(spawner.spawn(run_high())); |
| 127 | 127 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 129 | let irq = interrupt::take!(SWI0_EGU0); | 129 | let irq = interrupt::take!(SWI0_EGU0); |
| 130 | irq.set_priority(interrupt::Priority::P7); | 130 | irq.set_priority(interrupt::Priority::P7); |
| 131 | let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); | 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); |
| 132 | let spawner = executor.start(); | 132 | let spawner = executor.start(); |
| 133 | unwrap!(spawner.spawn(run_med())); | 133 | unwrap!(spawner.spawn(run_med())); |
| 134 | 134 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 135 | // Low priority executor: runs in thread mode, using WFE/SEV |
| 136 | let executor = EXECUTOR_LOW.put(Executor::new()); | 136 | let executor = EXECUTOR_LOW.init(Executor::new()); |
| 137 | executor.run(|spawner| { | 137 | executor.run(|spawner| { |
| 138 | unwrap!(spawner.spawn(run_low())); | 138 | unwrap!(spawner.spawn(run_low())); |
| 139 | }); | 139 | }); |
diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs index 415579be7..1b067f5e4 100644 --- a/examples/nrf/src/bin/raw_spawn.rs +++ b/examples/nrf/src/bin/raw_spawn.rs | |||
| @@ -8,7 +8,7 @@ use defmt::{info, unwrap}; | |||
| 8 | use embassy_executor::raw::TaskStorage; | 8 | use embassy_executor::raw::TaskStorage; |
| 9 | use embassy_executor::Executor; | 9 | use embassy_executor::Executor; |
| 10 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 11 | use embassy_util::Forever; | 11 | use static_cell::StaticCell; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | async fn run1() { | 14 | async fn run1() { |
| @@ -25,14 +25,14 @@ async fn run2() { | |||
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | static EXECUTOR: Forever<Executor> = Forever::new(); | 28 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 29 | 29 | ||
| 30 | #[entry] | 30 | #[entry] |
| 31 | fn main() -> ! { | 31 | fn main() -> ! { |
| 32 | info!("Hello World!"); | 32 | info!("Hello World!"); |
| 33 | 33 | ||
| 34 | let _p = embassy_nrf::init(Default::default()); | 34 | let _p = embassy_nrf::init(Default::default()); |
| 35 | let executor = EXECUTOR.put(Executor::new()); | 35 | let executor = EXECUTOR.init(Executor::new()); |
| 36 | 36 | ||
| 37 | let run1_task = TaskStorage::new(); | 37 | let run1_task = TaskStorage::new(); |
| 38 | let run2_task = TaskStorage::new(); | 38 | let run2_task = TaskStorage::new(); |
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index f0a870317..d427f7563 100644 --- a/examples/nrf/src/bin/usb_ethernet.rs +++ b/examples/nrf/src/bin/usb_ethernet.rs | |||
| @@ -18,17 +18,17 @@ use embassy_usb::{Builder, Config, UsbDevice}; | |||
| 18 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | 18 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; |
| 19 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | 19 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; |
| 20 | use embassy_util::channel::mpmc::Channel; | 20 | use embassy_util::channel::mpmc::Channel; |
| 21 | use embassy_util::Forever; | ||
| 22 | use embedded_io::asynch::{Read, Write}; | 21 | use embedded_io::asynch::{Read, Write}; |
| 22 | use static_cell::StaticCell; | ||
| 23 | use {defmt_rtt as _, panic_probe as _}; | 23 | use {defmt_rtt as _, panic_probe as _}; |
| 24 | 24 | ||
| 25 | type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; | 25 | type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; |
| 26 | 26 | ||
| 27 | macro_rules! forever { | 27 | macro_rules! singleton { |
| 28 | ($val:expr) => {{ | 28 | ($val:expr) => {{ |
| 29 | type T = impl Sized; | 29 | type T = impl Sized; |
| 30 | static FOREVER: Forever<T> = Forever::new(); | 30 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 31 | FOREVER.put_with(move || $val) | 31 | STATIC_CELL.init_with(move || $val) |
| 32 | }}; | 32 | }}; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| @@ -116,7 +116,7 @@ async fn main(spawner: Spawner) { | |||
| 116 | control_buf: [u8; 128], | 116 | control_buf: [u8; 128], |
| 117 | serial_state: State<'static>, | 117 | serial_state: State<'static>, |
| 118 | } | 118 | } |
| 119 | let res: &mut Resources = forever!(Resources { | 119 | let res: &mut Resources = singleton!(Resources { |
| 120 | device_descriptor: [0; 256], | 120 | device_descriptor: [0; 256], |
| 121 | config_descriptor: [0; 256], | 121 | config_descriptor: [0; 256], |
| 122 | bos_descriptor: [0; 256], | 122 | bos_descriptor: [0; 256], |
| @@ -174,10 +174,10 @@ async fn main(spawner: Spawner) { | |||
| 174 | 174 | ||
| 175 | // Init network stack | 175 | // Init network stack |
| 176 | let device = Device { mac_addr: our_mac_addr }; | 176 | let device = Device { mac_addr: our_mac_addr }; |
| 177 | let stack = &*forever!(Stack::new( | 177 | let stack = &*singleton!(Stack::new( |
| 178 | device, | 178 | device, |
| 179 | config, | 179 | config, |
| 180 | forever!(StackResources::<1, 2, 8>::new()), | 180 | singleton!(StackResources::<1, 2, 8>::new()), |
| 181 | seed | 181 | seed |
| 182 | )); | 182 | )); |
| 183 | 183 | ||
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs index 4c1a93087..d62d7e520 100644 --- a/examples/nrf/src/bin/usb_serial_multitask.rs +++ b/examples/nrf/src/bin/usb_serial_multitask.rs | |||
| @@ -12,7 +12,7 @@ use embassy_nrf::{interrupt, pac, peripherals}; | |||
| 12 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 13 | use embassy_usb::{Builder, Config, UsbDevice}; | 13 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 14 | use embassy_usb_serial::{CdcAcmClass, State}; | 14 | use embassy_usb_serial::{CdcAcmClass, State}; |
| 15 | use embassy_util::Forever; | 15 | use static_cell::StaticCell; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; | 18 | type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; |
| @@ -67,8 +67,8 @@ async fn main(spawner: Spawner) { | |||
| 67 | control_buf: [u8; 64], | 67 | control_buf: [u8; 64], |
| 68 | serial_state: State<'static>, | 68 | serial_state: State<'static>, |
| 69 | } | 69 | } |
| 70 | static RESOURCES: Forever<Resources> = Forever::new(); | 70 | static RESOURCES: StaticCell<Resources> = StaticCell::new(); |
| 71 | let res = RESOURCES.put(Resources { | 71 | let res = RESOURCES.init(Resources { |
| 72 | device_descriptor: [0; 256], | 72 | device_descriptor: [0; 256], |
| 73 | config_descriptor: [0; 256], | 73 | config_descriptor: [0; 256], |
| 74 | bos_descriptor: [0; 256], | 74 | bos_descriptor: [0; 256], |
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" | |||
| 20 | clap = { version = "3.0.0-beta.5", features = ["derive"] } | 20 | clap = { version = "3.0.0-beta.5", features = ["derive"] } |
| 21 | rand_core = { version = "0.6.3", features = ["std"] } | 21 | rand_core = { version = "0.6.3", features = ["std"] } |
| 22 | heapless = { version = "0.7.5", default-features = false } | 22 | heapless = { version = "0.7.5", default-features = false } |
| 23 | 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; | |||
| 4 | use embassy_executor::{Executor, Spawner}; | 4 | use embassy_executor::{Executor, Spawner}; |
| 5 | use embassy_net::tcp::TcpSocket; | 5 | use embassy_net::tcp::TcpSocket; |
| 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; |
| 7 | use embassy_util::Forever; | ||
| 8 | use embedded_io::asynch::Write; | 7 | use embedded_io::asynch::Write; |
| 9 | use heapless::Vec; | 8 | use heapless::Vec; |
| 10 | use log::*; | 9 | use log::*; |
| 11 | use rand_core::{OsRng, RngCore}; | 10 | use rand_core::{OsRng, RngCore}; |
| 11 | use static_cell::StaticCell; | ||
| 12 | 12 | ||
| 13 | #[path = "../tuntap.rs"] | 13 | #[path = "../tuntap.rs"] |
| 14 | mod tuntap; | 14 | mod tuntap; |
| 15 | 15 | ||
| 16 | use crate::tuntap::TunTapDevice; | 16 | use crate::tuntap::TunTapDevice; |
| 17 | 17 | ||
| 18 | macro_rules! forever { | 18 | macro_rules! singleton { |
| 19 | ($val:expr) => {{ | 19 | ($val:expr) => {{ |
| 20 | type T = impl Sized; | 20 | type T = impl Sized; |
| 21 | static FOREVER: Forever<T> = Forever::new(); | 21 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 22 | FOREVER.put_with(move || $val) | 22 | STATIC_CELL.init_with(move || $val) |
| 23 | }}; | 23 | }}; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| @@ -63,10 +63,10 @@ async fn main_task(spawner: Spawner) { | |||
| 63 | let seed = u64::from_le_bytes(seed); | 63 | let seed = u64::from_le_bytes(seed); |
| 64 | 64 | ||
| 65 | // Init network stack | 65 | // Init network stack |
| 66 | let stack = &*forever!(Stack::new( | 66 | let stack = &*singleton!(Stack::new( |
| 67 | device, | 67 | device, |
| 68 | config, | 68 | config, |
| 69 | forever!(StackResources::<1, 2, 8>::new()), | 69 | singleton!(StackResources::<1, 2, 8>::new()), |
| 70 | seed | 70 | seed |
| 71 | )); | 71 | )); |
| 72 | 72 | ||
| @@ -97,7 +97,7 @@ async fn main_task(spawner: Spawner) { | |||
| 97 | } | 97 | } |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | static EXECUTOR: Forever<Executor> = Forever::new(); | 100 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 101 | 101 | ||
| 102 | fn main() { | 102 | fn main() { |
| 103 | env_logger::builder() | 103 | env_logger::builder() |
| @@ -106,7 +106,7 @@ fn main() { | |||
| 106 | .format_timestamp_nanos() | 106 | .format_timestamp_nanos() |
| 107 | .init(); | 107 | .init(); |
| 108 | 108 | ||
| 109 | let executor = EXECUTOR.put(Executor::new()); | 109 | let executor = EXECUTOR.init(Executor::new()); |
| 110 | executor.run(|spawner| { | 110 | executor.run(|spawner| { |
| 111 | spawner.spawn(main_task(spawner)).unwrap(); | 111 | spawner.spawn(main_task(spawner)).unwrap(); |
| 112 | }); | 112 | }); |
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; | |||
| 4 | use embassy_executor::{Executor, Spawner}; | 4 | use embassy_executor::{Executor, Spawner}; |
| 5 | use embassy_net::udp::UdpSocket; | 5 | use embassy_net::udp::UdpSocket; |
| 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; | 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; |
| 7 | use embassy_util::Forever; | ||
| 8 | use heapless::Vec; | 7 | use heapless::Vec; |
| 9 | use log::*; | 8 | use log::*; |
| 10 | use rand_core::{OsRng, RngCore}; | 9 | use rand_core::{OsRng, RngCore}; |
| 10 | use static_cell::StaticCell; | ||
| 11 | 11 | ||
| 12 | #[path = "../tuntap.rs"] | 12 | #[path = "../tuntap.rs"] |
| 13 | mod tuntap; | 13 | mod tuntap; |
| 14 | 14 | ||
| 15 | use crate::tuntap::TunTapDevice; | 15 | use crate::tuntap::TunTapDevice; |
| 16 | 16 | ||
| 17 | macro_rules! forever { | 17 | macro_rules! singleton { |
| 18 | ($val:expr) => {{ | 18 | ($val:expr) => {{ |
| 19 | type T = impl Sized; | 19 | type T = impl Sized; |
| 20 | static FOREVER: Forever<T> = Forever::new(); | 20 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 21 | FOREVER.put_with(move || $val) | 21 | STATIC_CELL.init_with(move || $val) |
| 22 | }}; | 22 | }}; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| @@ -62,10 +62,10 @@ async fn main_task(spawner: Spawner) { | |||
| 62 | let seed = u64::from_le_bytes(seed); | 62 | let seed = u64::from_le_bytes(seed); |
| 63 | 63 | ||
| 64 | // Init network stack | 64 | // Init network stack |
| 65 | let stack = &*forever!(Stack::new( | 65 | let stack = &*singleton!(Stack::new( |
| 66 | device, | 66 | device, |
| 67 | config, | 67 | config, |
| 68 | forever!(StackResources::<1, 2, 8>::new()), | 68 | singleton!(StackResources::<1, 2, 8>::new()), |
| 69 | seed | 69 | seed |
| 70 | )); | 70 | )); |
| 71 | 71 | ||
| @@ -93,7 +93,7 @@ async fn main_task(spawner: Spawner) { | |||
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | static EXECUTOR: Forever<Executor> = Forever::new(); | 96 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 97 | 97 | ||
| 98 | fn main() { | 98 | fn main() { |
| 99 | env_logger::builder() | 99 | env_logger::builder() |
| @@ -102,7 +102,7 @@ fn main() { | |||
| 102 | .format_timestamp_nanos() | 102 | .format_timestamp_nanos() |
| 103 | .init(); | 103 | .init(); |
| 104 | 104 | ||
| 105 | let executor = EXECUTOR.put(Executor::new()); | 105 | let executor = EXECUTOR.init(Executor::new()); |
| 106 | executor.run(|spawner| { | 106 | executor.run(|spawner| { |
| 107 | spawner.spawn(main_task(spawner)).unwrap(); | 107 | spawner.spawn(main_task(spawner)).unwrap(); |
| 108 | }); | 108 | }); |
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; | |||
| 5 | 5 | ||
| 6 | use async_io::Async; | 6 | use async_io::Async; |
| 7 | use embassy_executor::Executor; | 7 | use embassy_executor::Executor; |
| 8 | use embassy_util::Forever; | ||
| 9 | use embedded_io::asynch::Read; | 8 | use embedded_io::asynch::Read; |
| 10 | use log::*; | 9 | use log::*; |
| 11 | use nix::sys::termios; | 10 | use nix::sys::termios; |
| 11 | use static_cell::StaticCell; | ||
| 12 | 12 | ||
| 13 | use self::serial_port::SerialPort; | 13 | use self::serial_port::SerialPort; |
| 14 | 14 | ||
| @@ -40,7 +40,7 @@ async fn run() { | |||
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | static EXECUTOR: Forever<Executor> = Forever::new(); | 43 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 44 | 44 | ||
| 45 | fn main() { | 45 | fn main() { |
| 46 | env_logger::builder() | 46 | env_logger::builder() |
| @@ -49,7 +49,7 @@ fn main() { | |||
| 49 | .format_timestamp_nanos() | 49 | .format_timestamp_nanos() |
| 50 | .init(); | 50 | .init(); |
| 51 | 51 | ||
| 52 | let executor = EXECUTOR.put(Executor::new()); | 52 | let executor = EXECUTOR.init(Executor::new()); |
| 53 | executor.run(|spawner| { | 53 | executor.run(|spawner| { |
| 54 | spawner.spawn(run()).unwrap(); | 54 | spawner.spawn(run()).unwrap(); |
| 55 | }); | 55 | }); |
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index b5ea28bb6..4e6b0ea1e 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml | |||
| @@ -23,3 +23,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 23 | heapless = { version = "0.7.5", default-features = false } | 23 | heapless = { version = "0.7.5", default-features = false } |
| 24 | nb = "1.0.0" | 24 | nb = "1.0.0" |
| 25 | embedded-storage = "0.3.0" | 25 | embedded-storage = "0.3.0" |
| 26 | static_cell = "1.0" | ||
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index e96c31249..9e8228a4b 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs | |||
| @@ -63,7 +63,7 @@ use embassy_stm32::executor::{Executor, InterruptExecutor}; | |||
| 63 | use embassy_stm32::interrupt; | 63 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 64 | use embassy_stm32::interrupt::InterruptExt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use embassy_util::Forever; | 66 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| 68 | 68 | ||
| 69 | #[embassy_executor::task] | 69 | #[embassy_executor::task] |
| @@ -108,9 +108,9 @@ async fn run_low() { | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::UART4>> = Forever::new(); | 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new(); |
| 112 | static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::UART5>> = Forever::new(); | 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new(); |
| 113 | static EXECUTOR_LOW: Forever<Executor> = Forever::new(); | 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 114 | ||
| 115 | #[entry] | 115 | #[entry] |
| 116 | fn main() -> ! { | 116 | fn main() -> ! { |
| @@ -121,19 +121,19 @@ fn main() -> ! { | |||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 121 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 122 | let irq = interrupt::take!(UART4); | 122 | let irq = interrupt::take!(UART4); |
| 123 | irq.set_priority(interrupt::Priority::P6); | 123 | irq.set_priority(interrupt::Priority::P6); |
| 124 | let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); | 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); |
| 125 | let spawner = executor.start(); | 125 | let spawner = executor.start(); |
| 126 | unwrap!(spawner.spawn(run_high())); | 126 | unwrap!(spawner.spawn(run_high())); |
| 127 | 127 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 129 | let irq = interrupt::take!(UART5); | 129 | let irq = interrupt::take!(UART5); |
| 130 | irq.set_priority(interrupt::Priority::P7); | 130 | irq.set_priority(interrupt::Priority::P7); |
| 131 | let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); | 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); |
| 132 | let spawner = executor.start(); | 132 | let spawner = executor.start(); |
| 133 | unwrap!(spawner.spawn(run_med())); | 133 | unwrap!(spawner.spawn(run_med())); |
| 134 | 134 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 135 | // Low priority executor: runs in thread mode, using WFE/SEV |
| 136 | let executor = EXECUTOR_LOW.put(Executor::new()); | 136 | let executor = EXECUTOR_LOW.init(Executor::new()); |
| 137 | executor.run(|spawner| { | 137 | executor.run(|spawner| { |
| 138 | unwrap!(spawner.spawn(run_low())); | 138 | unwrap!(spawner.spawn(run_low())); |
| 139 | }); | 139 | }); |
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 04a217aff..f93a1d0f9 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -23,6 +23,7 @@ heapless = { version = "0.7.5", default-features = false } | |||
| 23 | nb = "1.0.0" | 23 | nb = "1.0.0" |
| 24 | embedded-storage = "0.3.0" | 24 | embedded-storage = "0.3.0" |
| 25 | micromath = "2.0.0" | 25 | micromath = "2.0.0" |
| 26 | static_cell = "1.0" | ||
| 26 | 27 | ||
| 27 | usb-device = "0.2" | 28 | usb-device = "0.2" |
| 28 | usbd-serial = "0.1.1" | 29 | usbd-serial = "0.1.1" |
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index e96c31249..9e8228a4b 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs | |||
| @@ -63,7 +63,7 @@ use embassy_stm32::executor::{Executor, InterruptExecutor}; | |||
| 63 | use embassy_stm32::interrupt; | 63 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 64 | use embassy_stm32::interrupt::InterruptExt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use embassy_util::Forever; | 66 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| 68 | 68 | ||
| 69 | #[embassy_executor::task] | 69 | #[embassy_executor::task] |
| @@ -108,9 +108,9 @@ async fn run_low() { | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::UART4>> = Forever::new(); | 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new(); |
| 112 | static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::UART5>> = Forever::new(); | 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new(); |
| 113 | static EXECUTOR_LOW: Forever<Executor> = Forever::new(); | 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 114 | ||
| 115 | #[entry] | 115 | #[entry] |
| 116 | fn main() -> ! { | 116 | fn main() -> ! { |
| @@ -121,19 +121,19 @@ fn main() -> ! { | |||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 121 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 122 | let irq = interrupt::take!(UART4); | 122 | let irq = interrupt::take!(UART4); |
| 123 | irq.set_priority(interrupt::Priority::P6); | 123 | irq.set_priority(interrupt::Priority::P6); |
| 124 | let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); | 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); |
| 125 | let spawner = executor.start(); | 125 | let spawner = executor.start(); |
| 126 | unwrap!(spawner.spawn(run_high())); | 126 | unwrap!(spawner.spawn(run_high())); |
| 127 | 127 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 129 | let irq = interrupt::take!(UART5); | 129 | let irq = interrupt::take!(UART5); |
| 130 | irq.set_priority(interrupt::Priority::P7); | 130 | irq.set_priority(interrupt::Priority::P7); |
| 131 | let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); | 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); |
| 132 | let spawner = executor.start(); | 132 | let spawner = executor.start(); |
| 133 | unwrap!(spawner.spawn(run_med())); | 133 | unwrap!(spawner.spawn(run_med())); |
| 134 | 134 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 135 | // Low priority executor: runs in thread mode, using WFE/SEV |
| 136 | let executor = EXECUTOR_LOW.put(Executor::new()); | 136 | let executor = EXECUTOR_LOW.init(Executor::new()); |
| 137 | executor.run(|spawner| { | 137 | executor.run(|spawner| { |
| 138 | unwrap!(spawner.spawn(run_low())); | 138 | unwrap!(spawner.spawn(run_low())); |
| 139 | }); | 139 | }); |
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 29d6da4d8..e286d2310 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml | |||
| @@ -24,3 +24,4 @@ nb = "1.0.0" | |||
| 24 | rand_core = "0.6.3" | 24 | rand_core = "0.6.3" |
| 25 | critical-section = "1.1" | 25 | critical-section = "1.1" |
| 26 | embedded-storage = "0.3.0" | 26 | embedded-storage = "0.3.0" |
| 27 | static_cell = "1.0" | ||
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index bdffabcb3..5202edf62 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng; | |||
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{interrupt, Config}; | 14 | use embassy_stm32::{interrupt, Config}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embassy_util::Forever; | ||
| 17 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 18 | use rand_core::RngCore; | 17 | use rand_core::RngCore; |
| 18 | use static_cell::StaticCell; | ||
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 20 | ||
| 21 | macro_rules! forever { | 21 | macro_rules! singleton { |
| 22 | ($val:expr) => {{ | 22 | ($val:expr) => {{ |
| 23 | type T = impl Sized; | 23 | type T = impl Sized; |
| 24 | static FOREVER: Forever<T> = Forever::new(); | 24 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 25 | FOREVER.put_with(move || $val) | 25 | STATIC_CELL.init_with(move || $val) |
| 26 | }}; | 26 | }}; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| @@ -52,7 +52,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 52 | 52 | ||
| 53 | let device = unsafe { | 53 | let device = unsafe { |
| 54 | Ethernet::new( | 54 | Ethernet::new( |
| 55 | forever!(State::new()), | 55 | singleton!(State::new()), |
| 56 | p.ETH, | 56 | p.ETH, |
| 57 | eth_int, | 57 | eth_int, |
| 58 | p.PA1, | 58 | p.PA1, |
| @@ -78,10 +78,10 @@ async fn main(spawner: Spawner) -> ! { | |||
| 78 | //}); | 78 | //}); |
| 79 | 79 | ||
| 80 | // Init network stack | 80 | // Init network stack |
| 81 | let stack = &*forever!(Stack::new( | 81 | let stack = &*singleton!(Stack::new( |
| 82 | device, | 82 | device, |
| 83 | config, | 83 | config, |
| 84 | forever!(StackResources::<1, 2, 8>::new()), | 84 | singleton!(StackResources::<1, 2, 8>::new()), |
| 85 | seed | 85 | seed |
| 86 | )); | 86 | )); |
| 87 | 87 | ||
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index a416796ea..fc5f74f99 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml | |||
| @@ -28,6 +28,7 @@ critical-section = "1.1" | |||
| 28 | micromath = "2.0.0" | 28 | micromath = "2.0.0" |
| 29 | stm32-fmc = "0.2.4" | 29 | stm32-fmc = "0.2.4" |
| 30 | embedded-storage = "0.3.0" | 30 | embedded-storage = "0.3.0" |
| 31 | static_cell = "1.0" | ||
| 31 | 32 | ||
| 32 | # cargo build/run | 33 | # cargo build/run |
| 33 | [profile.dev] | 34 | [profile.dev] |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 83210bcb5..4ccc0b5ef 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng; | |||
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{interrupt, Config}; | 14 | use embassy_stm32::{interrupt, Config}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embassy_util::Forever; | ||
| 17 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 18 | use rand_core::RngCore; | 17 | use rand_core::RngCore; |
| 18 | use static_cell::StaticCell; | ||
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 20 | ||
| 21 | macro_rules! forever { | 21 | macro_rules! singleton { |
| 22 | ($val:expr) => {{ | 22 | ($val:expr) => {{ |
| 23 | type T = impl Sized; | 23 | type T = impl Sized; |
| 24 | static FOREVER: Forever<T> = Forever::new(); | 24 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 25 | FOREVER.put_with(move || $val) | 25 | STATIC_CELL.init_with(move || $val) |
| 26 | }}; | 26 | }}; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| @@ -53,7 +53,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 53 | 53 | ||
| 54 | let device = unsafe { | 54 | let device = unsafe { |
| 55 | Ethernet::new( | 55 | Ethernet::new( |
| 56 | forever!(State::new()), | 56 | singleton!(State::new()), |
| 57 | p.ETH, | 57 | p.ETH, |
| 58 | eth_int, | 58 | eth_int, |
| 59 | p.PA1, | 59 | p.PA1, |
| @@ -79,10 +79,10 @@ async fn main(spawner: Spawner) -> ! { | |||
| 79 | //}); | 79 | //}); |
| 80 | 80 | ||
| 81 | // Init network stack | 81 | // Init network stack |
| 82 | let stack = &*forever!(Stack::new( | 82 | let stack = &*singleton!(Stack::new( |
| 83 | device, | 83 | device, |
| 84 | config, | 84 | config, |
| 85 | forever!(StackResources::<1, 2, 8>::new()), | 85 | singleton!(StackResources::<1, 2, 8>::new()), |
| 86 | seed | 86 | seed |
| 87 | )); | 87 | )); |
| 88 | 88 | ||
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 99946f504..64fd84141 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs | |||
| @@ -13,17 +13,17 @@ use embassy_stm32::rng::Rng; | |||
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{interrupt, Config}; | 14 | use embassy_stm32::{interrupt, Config}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embassy_util::Forever; | ||
| 17 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 18 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; | 17 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; |
| 19 | use rand_core::RngCore; | 18 | use rand_core::RngCore; |
| 19 | use static_cell::StaticCell; | ||
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | 21 | ||
| 22 | macro_rules! forever { | 22 | macro_rules! singleton { |
| 23 | ($val:expr) => {{ | 23 | ($val:expr) => {{ |
| 24 | type T = impl Sized; | 24 | type T = impl Sized; |
| 25 | static FOREVER: Forever<T> = Forever::new(); | 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 26 | FOREVER.put_with(move || $val) | 26 | STATIC_CELL.init_with(move || $val) |
| 27 | }}; | 27 | }}; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| @@ -54,7 +54,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 54 | 54 | ||
| 55 | let device = unsafe { | 55 | let device = unsafe { |
| 56 | Ethernet::new( | 56 | Ethernet::new( |
| 57 | forever!(State::new()), | 57 | singleton!(State::new()), |
| 58 | p.ETH, | 58 | p.ETH, |
| 59 | eth_int, | 59 | eth_int, |
| 60 | p.PA1, | 60 | p.PA1, |
| @@ -80,10 +80,10 @@ async fn main(spawner: Spawner) -> ! { | |||
| 80 | //}); | 80 | //}); |
| 81 | 81 | ||
| 82 | // Init network stack | 82 | // Init network stack |
| 83 | let stack = &*forever!(Stack::new( | 83 | let stack = &*singleton!(Stack::new( |
| 84 | device, | 84 | device, |
| 85 | config, | 85 | config, |
| 86 | forever!(StackResources::<1, 2, 8>::new()), | 86 | singleton!(StackResources::<1, 2, 8>::new()), |
| 87 | seed | 87 | seed |
| 88 | )); | 88 | )); |
| 89 | 89 | ||
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index c28f937a8..1f407f002 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs | |||
| @@ -12,8 +12,8 @@ use embassy_stm32::dma::NoDma; | |||
| 12 | use embassy_stm32::peripherals::SPI3; | 12 | use embassy_stm32::peripherals::SPI3; |
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{spi, Config}; | 14 | use embassy_stm32::{spi, Config}; |
| 15 | use embassy_util::Forever; | ||
| 16 | use heapless::String; | 15 | use heapless::String; |
| 16 | use static_cell::StaticCell; | ||
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 18 | ||
| 19 | #[embassy_executor::task] | 19 | #[embassy_executor::task] |
| @@ -31,7 +31,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) { | |||
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | static EXECUTOR: Forever<Executor> = Forever::new(); | 34 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 35 | 35 | ||
| 36 | #[entry] | 36 | #[entry] |
| 37 | fn main() -> ! { | 37 | fn main() -> ! { |
| @@ -54,7 +54,7 @@ fn main() -> ! { | |||
| 54 | spi::Config::default(), | 54 | spi::Config::default(), |
| 55 | ); | 55 | ); |
| 56 | 56 | ||
| 57 | let executor = EXECUTOR.put(Executor::new()); | 57 | let executor = EXECUTOR.init(Executor::new()); |
| 58 | 58 | ||
| 59 | executor.run(|spawner| { | 59 | executor.run(|spawner| { |
| 60 | unwrap!(spawner.spawn(main_task(spi))); | 60 | unwrap!(spawner.spawn(main_task(spi))); |
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 6c78c194f..53004fc9b 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs | |||
| @@ -11,8 +11,8 @@ use embassy_executor::Executor; | |||
| 11 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; | 11 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; |
| 12 | use embassy_stm32::time::mhz; | 12 | use embassy_stm32::time::mhz; |
| 13 | use embassy_stm32::{spi, Config}; | 13 | use embassy_stm32::{spi, Config}; |
| 14 | use embassy_util::Forever; | ||
| 15 | use heapless::String; | 14 | use heapless::String; |
| 15 | use static_cell::StaticCell; | ||
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | #[embassy_executor::task] | 18 | #[embassy_executor::task] |
| @@ -27,7 +27,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) { | |||
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | static EXECUTOR: Forever<Executor> = Forever::new(); | 30 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 31 | 31 | ||
| 32 | #[entry] | 32 | #[entry] |
| 33 | fn main() -> ! { | 33 | fn main() -> ! { |
| @@ -50,7 +50,7 @@ fn main() -> ! { | |||
| 50 | spi::Config::default(), | 50 | spi::Config::default(), |
| 51 | ); | 51 | ); |
| 52 | 52 | ||
| 53 | let executor = EXECUTOR.put(Executor::new()); | 53 | let executor = EXECUTOR.init(Executor::new()); |
| 54 | 54 | ||
| 55 | executor.run(|spawner| { | 55 | executor.run(|spawner| { |
| 56 | unwrap!(spawner.spawn(main_task(spi))); | 56 | unwrap!(spawner.spawn(main_task(spi))); |
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs index 1384d54c6..87c2b1253 100644 --- a/examples/stm32h7/src/bin/usart.rs +++ b/examples/stm32h7/src/bin/usart.rs | |||
| @@ -7,7 +7,7 @@ use defmt::*; | |||
| 7 | use embassy_executor::Executor; | 7 | use embassy_executor::Executor; |
| 8 | use embassy_stm32::dma::NoDma; | 8 | use embassy_stm32::dma::NoDma; |
| 9 | use embassy_stm32::usart::{Config, Uart}; | 9 | use embassy_stm32::usart::{Config, Uart}; |
| 10 | use embassy_util::Forever; | 10 | use static_cell::StaticCell; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | #[embassy_executor::task] | 13 | #[embassy_executor::task] |
| @@ -27,13 +27,13 @@ async fn main_task() { | |||
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | static EXECUTOR: Forever<Executor> = Forever::new(); | 30 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 31 | 31 | ||
| 32 | #[entry] | 32 | #[entry] |
| 33 | fn main() -> ! { | 33 | fn main() -> ! { |
| 34 | info!("Hello World!"); | 34 | info!("Hello World!"); |
| 35 | 35 | ||
| 36 | let executor = EXECUTOR.put(Executor::new()); | 36 | let executor = EXECUTOR.init(Executor::new()); |
| 37 | 37 | ||
| 38 | executor.run(|spawner| { | 38 | executor.run(|spawner| { |
| 39 | unwrap!(spawner.spawn(main_task())); | 39 | unwrap!(spawner.spawn(main_task())); |
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs index f8d58bb84..3adffcbeb 100644 --- a/examples/stm32h7/src/bin/usart_dma.rs +++ b/examples/stm32h7/src/bin/usart_dma.rs | |||
| @@ -9,8 +9,8 @@ use defmt::*; | |||
| 9 | use embassy_executor::Executor; | 9 | use embassy_executor::Executor; |
| 10 | use embassy_stm32::dma::NoDma; | 10 | use embassy_stm32::dma::NoDma; |
| 11 | use embassy_stm32::usart::{Config, Uart}; | 11 | use embassy_stm32::usart::{Config, Uart}; |
| 12 | use embassy_util::Forever; | ||
| 13 | use heapless::String; | 12 | use heapless::String; |
| 13 | use static_cell::StaticCell; | ||
| 14 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 15 | ||
| 16 | #[embassy_executor::task] | 16 | #[embassy_executor::task] |
| @@ -30,13 +30,13 @@ async fn main_task() { | |||
| 30 | } | 30 | } |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | static EXECUTOR: Forever<Executor> = Forever::new(); | 33 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 34 | 34 | ||
| 35 | #[entry] | 35 | #[entry] |
| 36 | fn main() -> ! { | 36 | fn main() -> ! { |
| 37 | info!("Hello World!"); | 37 | info!("Hello World!"); |
| 38 | 38 | ||
| 39 | let executor = EXECUTOR.put(Executor::new()); | 39 | let executor = EXECUTOR.init(Executor::new()); |
| 40 | 40 | ||
| 41 | executor.run(|spawner| { | 41 | executor.run(|spawner| { |
| 42 | unwrap!(spawner.spawn(main_task())); | 42 | unwrap!(spawner.spawn(main_task())); |
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index fdb716d15..72365a640 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml | |||
| @@ -29,3 +29,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } | |||
| 29 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 29 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 30 | heapless = { version = "0.7.5", default-features = false } | 30 | heapless = { version = "0.7.5", default-features = false } |
| 31 | embedded-hal = "0.2.6" | 31 | embedded-hal = "0.2.6" |
| 32 | static_cell = "1.0" | ||
diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs index bd87e62a4..edc17304a 100644 --- a/examples/stm32l0/src/bin/raw_spawn.rs +++ b/examples/stm32l0/src/bin/raw_spawn.rs | |||
| @@ -8,7 +8,7 @@ use defmt::*; | |||
| 8 | use embassy_executor::raw::TaskStorage; | 8 | use embassy_executor::raw::TaskStorage; |
| 9 | use embassy_executor::Executor; | 9 | use embassy_executor::Executor; |
| 10 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 11 | use embassy_util::Forever; | 11 | use static_cell::StaticCell; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | async fn run1() { | 14 | async fn run1() { |
| @@ -25,14 +25,14 @@ async fn run2() { | |||
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | static EXECUTOR: Forever<Executor> = Forever::new(); | 28 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 29 | 29 | ||
| 30 | #[entry] | 30 | #[entry] |
| 31 | fn main() -> ! { | 31 | fn main() -> ! { |
| 32 | info!("Hello World!"); | 32 | info!("Hello World!"); |
| 33 | 33 | ||
| 34 | let _p = embassy_stm32::init(Default::default()); | 34 | let _p = embassy_stm32::init(Default::default()); |
| 35 | let executor = EXECUTOR.put(Executor::new()); | 35 | let executor = EXECUTOR.init(Executor::new()); |
| 36 | 36 | ||
| 37 | let run1_task = TaskStorage::new(); | 37 | let run1_task = TaskStorage::new(); |
| 38 | let run2_task = TaskStorage::new(); | 38 | let run2_task = TaskStorage::new(); |
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 4d96d31fc..d8e78088a 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml | |||
| @@ -28,3 +28,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 28 | heapless = { version = "0.7.5", default-features = false } | 28 | heapless = { version = "0.7.5", default-features = false } |
| 29 | rand_core = { version = "0.6.3", default-features = false } | 29 | rand_core = { version = "0.6.3", default-features = false } |
| 30 | embedded-io = { version = "0.3.0", features = ["async"] } | 30 | embedded-io = { version = "0.3.0", features = ["async"] } |
| 31 | static_cell = "1.0" | ||
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 7c53d03cc..959195518 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs | |||
| @@ -19,18 +19,18 @@ use embassy_usb::{Builder, UsbDevice}; | |||
| 19 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | 19 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; |
| 20 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | 20 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; |
| 21 | use embassy_util::channel::mpmc::Channel; | 21 | use embassy_util::channel::mpmc::Channel; |
| 22 | use embassy_util::Forever; | ||
| 23 | use embedded_io::asynch::{Read, Write}; | 22 | use embedded_io::asynch::{Read, Write}; |
| 24 | use rand_core::RngCore; | 23 | use rand_core::RngCore; |
| 24 | use static_cell::StaticCell; | ||
| 25 | use {defmt_rtt as _, panic_probe as _}; | 25 | use {defmt_rtt as _, panic_probe as _}; |
| 26 | 26 | ||
| 27 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; | 27 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; |
| 28 | 28 | ||
| 29 | macro_rules! forever { | 29 | macro_rules! singleton { |
| 30 | ($val:expr) => {{ | 30 | ($val:expr) => {{ |
| 31 | type T = impl Sized; | 31 | type T = impl Sized; |
| 32 | static FOREVER: Forever<T> = Forever::new(); | 32 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 33 | FOREVER.put_with(move || $val) | 33 | STATIC_CELL.init_with(move || $val) |
| 34 | }}; | 34 | }}; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| @@ -115,7 +115,7 @@ async fn main(spawner: Spawner) { | |||
| 115 | control_buf: [u8; 128], | 115 | control_buf: [u8; 128], |
| 116 | serial_state: State<'static>, | 116 | serial_state: State<'static>, |
| 117 | } | 117 | } |
| 118 | let res: &mut Resources = forever!(Resources { | 118 | let res: &mut Resources = singleton!(Resources { |
| 119 | device_descriptor: [0; 256], | 119 | device_descriptor: [0; 256], |
| 120 | config_descriptor: [0; 256], | 120 | config_descriptor: [0; 256], |
| 121 | bos_descriptor: [0; 256], | 121 | bos_descriptor: [0; 256], |
| @@ -171,10 +171,10 @@ async fn main(spawner: Spawner) { | |||
| 171 | 171 | ||
| 172 | // Init network stack | 172 | // Init network stack |
| 173 | let device = Device { mac_addr: our_mac_addr }; | 173 | let device = Device { mac_addr: our_mac_addr }; |
| 174 | let stack = &*forever!(Stack::new( | 174 | let stack = &*singleton!(Stack::new( |
| 175 | device, | 175 | device, |
| 176 | config, | 176 | config, |
| 177 | forever!(StackResources::<1, 2, 8>::new()), | 177 | singleton!(StackResources::<1, 2, 8>::new()), |
| 178 | seed | 178 | seed |
| 179 | )); | 179 | )); |
| 180 | 180 | ||
