diff options
| author | Dominik Boehi <[email protected]> | 2023-01-09 22:29:58 +0100 |
|---|---|---|
| committer | Dominik Boehi <[email protected]> | 2023-01-09 22:30:02 +0100 |
| commit | 0a27b6cedb52453123190671f294bbd34918e09a (patch) | |
| tree | 3888e0b352388ace235517ec97c4d3a88fd7fcfa /examples/nrf52840/src/bin/self_spawn.rs | |
| parent | 401185b1d95a2519ee94e5d5654cc9325fe85eec (diff) | |
Rename examples/nrf to examples/nrf52840
Diffstat (limited to 'examples/nrf52840/src/bin/self_spawn.rs')
| -rw-r--r-- | examples/nrf52840/src/bin/self_spawn.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/nrf52840/src/bin/self_spawn.rs b/examples/nrf52840/src/bin/self_spawn.rs new file mode 100644 index 000000000..196255a52 --- /dev/null +++ b/examples/nrf52840/src/bin/self_spawn.rs | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{info, unwrap}; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_time::{Duration, Timer}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::task(pool_size = 2)] | ||
| 11 | async fn my_task(spawner: Spawner, n: u32) { | ||
| 12 | Timer::after(Duration::from_secs(1)).await; | ||
| 13 | info!("Spawning self! {}", n); | ||
| 14 | unwrap!(spawner.spawn(my_task(spawner, n + 1))); | ||
| 15 | } | ||
| 16 | |||
| 17 | #[embassy_executor::main] | ||
| 18 | async fn main(spawner: Spawner) { | ||
| 19 | let _p = embassy_nrf::init(Default::default()); | ||
| 20 | info!("Hello World!"); | ||
| 21 | unwrap!(spawner.spawn(my_task(spawner, 0))); | ||
| 22 | } | ||
