2021-03-18 00:43:19 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
2021-03-29 00:42:08 +02:00
|
|
|
use core::mem;
|
2022-06-12 22:15:44 +02:00
|
|
|
|
2021-03-18 00:43:19 +01:00
|
|
|
use cortex_m_rt::entry;
|
2022-04-02 04:35:06 +02:00
|
|
|
use defmt::{info, unwrap};
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::raw::TaskStorage;
|
|
|
|
use embassy_executor::Executor;
|
|
|
|
use embassy_time::{Duration, Timer};
|
2022-08-22 15:51:44 +02:00
|
|
|
use static_cell::StaticCell;
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-04-02 04:35:06 +02:00
|
|
|
|
2021-03-18 00:43:19 +01:00
|
|
|
async fn run1() {
|
|
|
|
loop {
|
|
|
|
info!("BIG INFREQUENT TICK");
|
|
|
|
Timer::after(Duration::from_ticks(64000)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn run2() {
|
|
|
|
loop {
|
|
|
|
info!("tick");
|
|
|
|
Timer::after(Duration::from_ticks(13000)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-22 15:51:44 +02:00
|
|
|
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
|
2021-03-18 00:43:19 +01:00
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
2021-08-03 22:08:13 +02:00
|
|
|
let _p = embassy_nrf::init(Default::default());
|
2022-08-22 15:51:44 +02:00
|
|
|
let executor = EXECUTOR.init(Executor::new());
|
2021-03-18 00:43:19 +01:00
|
|
|
|
2021-08-26 00:20:52 +02:00
|
|
|
let run1_task = TaskStorage::new();
|
|
|
|
let run2_task = TaskStorage::new();
|
2021-03-18 00:43:19 +01:00
|
|
|
|
|
|
|
// Safety: these variables do live forever if main never returns.
|
|
|
|
let run1_task = unsafe { make_static(&run1_task) };
|
|
|
|
let run2_task = unsafe { make_static(&run2_task) };
|
|
|
|
|
|
|
|
executor.run(|spawner| {
|
|
|
|
unwrap!(spawner.spawn(run1_task.spawn(|| run1())));
|
|
|
|
unwrap!(spawner.spawn(run2_task.spawn(|| run2())));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn make_static<T>(t: &T) -> &'static T {
|
|
|
|
mem::transmute(t)
|
|
|
|
}
|