2022-04-06 01:23:42 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::{info, unwrap};
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2022-08-22 21:46:09 +02:00
|
|
|
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
|
|
|
use embassy_sync::mutex::Mutex;
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_time::{Duration, Timer};
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-04-06 01:23:42 +02:00
|
|
|
|
|
|
|
static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0);
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::task]
|
2022-04-06 01:23:42 +02:00
|
|
|
async fn my_task() {
|
|
|
|
loop {
|
|
|
|
{
|
|
|
|
let mut m = MUTEX.lock().await;
|
|
|
|
info!("start long operation");
|
|
|
|
*m += 1000;
|
|
|
|
|
|
|
|
// Hold the mutex for a long time.
|
|
|
|
Timer::after(Duration::from_secs(1)).await;
|
|
|
|
info!("end long operation: count = {}", *m);
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer::after(Duration::from_secs(1)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 18:49:55 +02:00
|
|
|
async fn main(spawner: Spawner) {
|
|
|
|
let _p = embassy_nrf::init(Default::default());
|
2022-04-06 01:23:42 +02:00
|
|
|
unwrap!(spawner.spawn(my_task()));
|
|
|
|
|
|
|
|
loop {
|
|
|
|
Timer::after(Duration::from_millis(300)).await;
|
|
|
|
let mut m = MUTEX.lock().await;
|
|
|
|
*m += 1;
|
|
|
|
info!("short operation: count = {}", *m);
|
|
|
|
}
|
|
|
|
}
|