2020-09-24 20:46:00 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
use example_common::*;
|
|
|
|
|
|
|
|
use core::mem::MaybeUninit;
|
|
|
|
use cortex_m_rt::entry;
|
2020-09-25 01:25:06 +00:00
|
|
|
use embassy::executor::{task, Executor, WfeModel};
|
|
|
|
use embassy::time::{Duration, Instant, Timer};
|
|
|
|
use embassy_nrf::pac;
|
2020-09-24 20:46:00 +00:00
|
|
|
use embassy_nrf::rtc;
|
|
|
|
use nrf52840_hal::clocks;
|
|
|
|
|
|
|
|
#[task]
|
2020-09-25 01:25:06 +00:00
|
|
|
async fn run1() {
|
2020-09-24 20:46:00 +00:00
|
|
|
loop {
|
2020-09-25 01:25:06 +00:00
|
|
|
info!("BIG INFREQUENT TICK");
|
|
|
|
Timer::after(Duration::from_ticks(64000)).await;
|
2020-09-24 20:46:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[task]
|
2020-09-25 01:25:06 +00:00
|
|
|
async fn run2() {
|
2020-09-24 20:46:00 +00:00
|
|
|
loop {
|
2020-09-25 01:25:06 +00:00
|
|
|
info!("tick");
|
|
|
|
Timer::after(Duration::from_ticks(13000)).await;
|
2020-09-24 20:46:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 01:25:06 +00:00
|
|
|
static mut RTC: MaybeUninit<rtc::RTC<pac::RTC1>> = MaybeUninit::uninit();
|
|
|
|
static mut EXECUTOR: MaybeUninit<Executor<WfeModel, rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit();
|
2020-09-24 20:46:00 +00:00
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let p = embassy_nrf::pac::Peripherals::take().dewrap();
|
|
|
|
|
|
|
|
clocks::Clocks::new(p.CLOCK)
|
|
|
|
.enable_ext_hfosc()
|
|
|
|
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
|
|
|
|
.start_lfclk();
|
|
|
|
|
|
|
|
let rtc: &'static _ = unsafe {
|
|
|
|
let ptr = RTC.as_mut_ptr();
|
2020-09-25 01:25:06 +00:00
|
|
|
ptr.write(rtc::RTC::new(p.RTC1));
|
2020-09-24 20:46:00 +00:00
|
|
|
&*ptr
|
|
|
|
};
|
|
|
|
|
2020-09-25 01:25:06 +00:00
|
|
|
rtc.start();
|
|
|
|
unsafe { embassy::time::set_clock(|| RTC.as_ptr().as_ref().unwrap().now()) };
|
2020-09-24 20:46:00 +00:00
|
|
|
|
2020-09-25 01:25:06 +00:00
|
|
|
let executor: &'static _ = unsafe {
|
|
|
|
let ptr = EXECUTOR.as_mut_ptr();
|
|
|
|
ptr.write(Executor::new(rtc.alarm0()));
|
2020-09-24 20:46:00 +00:00
|
|
|
&*ptr
|
|
|
|
};
|
|
|
|
|
|
|
|
unsafe {
|
2020-09-25 01:25:06 +00:00
|
|
|
executor.spawn(run1()).dewrap();
|
|
|
|
executor.spawn(run2()).dewrap();
|
2020-09-24 20:46:00 +00:00
|
|
|
|
2020-09-25 01:25:06 +00:00
|
|
|
executor.run()
|
2020-09-24 20:46:00 +00:00
|
|
|
}
|
|
|
|
}
|