2020-09-24 19:59:20 +02: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 23:38:42 +02:00
|
|
|
use embassy::time::{Alarm, Clock};
|
2020-09-24 19:59:20 +02:00
|
|
|
use embassy_nrf::rtc;
|
|
|
|
use nrf52840_hal::clocks;
|
|
|
|
|
|
|
|
static mut RTC: MaybeUninit<rtc::RTC<embassy_nrf::pac::RTC1>> = MaybeUninit::uninit();
|
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
2020-11-01 17:17:24 +01:00
|
|
|
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
|
2020-09-24 19:59:20 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
ptr.write(rtc::RTC::new(p.RTC1));
|
|
|
|
&*ptr
|
|
|
|
};
|
|
|
|
|
2020-09-25 03:25:06 +02:00
|
|
|
let alarm = rtc.alarm0();
|
|
|
|
|
2020-09-24 19:59:20 +02:00
|
|
|
rtc.start();
|
2020-09-25 03:25:06 +02:00
|
|
|
|
2020-09-25 23:25:49 +02:00
|
|
|
alarm.set_callback(|| info!("ALARM TRIGGERED"));
|
|
|
|
alarm.set(53719);
|
2020-09-24 19:59:20 +02:00
|
|
|
|
|
|
|
info!("initialized!");
|
|
|
|
|
|
|
|
let mut val = 0;
|
|
|
|
let mut printval = 0;
|
|
|
|
loop {
|
|
|
|
let val2 = rtc.now();
|
|
|
|
if val2 < val {
|
|
|
|
info!(
|
|
|
|
"timer ran backwards! {:u32} -> {:u32}",
|
|
|
|
val as u32, val2 as u32
|
|
|
|
);
|
|
|
|
}
|
|
|
|
val = val2;
|
|
|
|
|
|
|
|
if val > printval + 32768 {
|
|
|
|
info!("tick {:u32}", val as u32);
|
|
|
|
printval = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|