#![no_main]
#![no_std]
use async_embedded::task;
use core::cell::{Cell, RefCell};
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use panic_semihosting as _; use stm32f1xx_hal as _;
#[entry]
fn main() -> ! {
static mut CELL: Cell<u32> = Cell::new(0);
static mut REF_CELL: RefCell<Option<u32>> = RefCell::new(None);
let cell: &'static Cell<_> = CELL;
let ref_cell: &'static RefCell<_> = REF_CELL;
let a = async move {
hprintln!("Task `a`: cell = {:?}", cell).ok();
hprintln!("Task `a`: ref_cell = {:?}", ref_cell).ok();
loop {
hprintln!("Task `a` will yield now.").ok();
task::r#yield().await;
}
};
task::spawn(a);
let b = async {
hprintln!("Task `b` will set cell now.").ok();
cell.set(42);
hprintln!("Task `b` will set ref_cell now.").ok();
*ref_cell.borrow_mut() = Some(42);
hprintln!("Task `b` will yield now.").ok();
task::r#yield().await;
hprintln!("Task `b` will not yield again.").ok();
loop {}
};
task::block_on(b)
}