aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin/rtc_async.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2020-10-31 22:37:24 +0100
committerDario Nieuwenhuis <[email protected]>2020-10-31 22:37:24 +0100
commitb3858441f76c43981ba13c13aafbd3bdfec3280f (patch)
tree9604dc82740b0367b159873e49af84c4c37829f7 /examples/src/bin/rtc_async.rs
parent76196c424a762ac053c89a9e25652fe975f4d458 (diff)
Update examples.
Diffstat (limited to 'examples/src/bin/rtc_async.rs')
-rw-r--r--examples/src/bin/rtc_async.rs36
1 files changed, 14 insertions, 22 deletions
diff --git a/examples/src/bin/rtc_async.rs b/examples/src/bin/rtc_async.rs
index 30b181a93..5126a2cc8 100644
--- a/examples/src/bin/rtc_async.rs
+++ b/examples/src/bin/rtc_async.rs
@@ -8,11 +8,13 @@ use example_common::*;
8 8
9use core::mem::MaybeUninit; 9use core::mem::MaybeUninit;
10use cortex_m_rt::entry; 10use cortex_m_rt::entry;
11use embassy::executor::{task, Executor}; 11use nrf52840_hal::clocks;
12
13use embassy::executor::{task, TimerExecutor};
12use embassy::time::{Clock, Duration, Timer}; 14use embassy::time::{Clock, Duration, Timer};
15use embassy::util::Forever;
13use embassy_nrf::pac; 16use embassy_nrf::pac;
14use embassy_nrf::rtc; 17use embassy_nrf::rtc;
15use nrf52840_hal::clocks;
16 18
17#[task] 19#[task]
18async fn run1() { 20async fn run1() {
@@ -30,8 +32,8 @@ async fn run2() {
30 } 32 }
31} 33}
32 34
33static mut RTC: MaybeUninit<rtc::RTC<pac::RTC1>> = MaybeUninit::uninit(); 35static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
34static mut EXECUTOR: MaybeUninit<Executor<rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit(); 36static EXECUTOR: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new();
35 37
36#[entry] 38#[entry]
37fn main() -> ! { 39fn main() -> ! {
@@ -44,28 +46,18 @@ fn main() -> ! {
44 .set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass) 46 .set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
45 .start_lfclk(); 47 .start_lfclk();
46 48
47 let rtc: &'static _ = unsafe { 49 let rtc = RTC.put(rtc::RTC::new(p.RTC1));
48 let ptr = RTC.as_mut_ptr();
49 ptr.write(rtc::RTC::new(p.RTC1));
50 &*ptr
51 };
52
53 rtc.start(); 50 rtc.start();
51
54 unsafe { embassy::time::set_clock(rtc) }; 52 unsafe { embassy::time::set_clock(rtc) };
55 53
56 let executor: &'static _ = unsafe { 54 let executor = EXECUTOR.put(TimerExecutor::new(rtc.alarm0(), cortex_m::asm::sev));
57 let ptr = EXECUTOR.as_mut_ptr();
58 ptr.write(Executor::new(rtc.alarm0(), cortex_m::asm::sev));
59 &*ptr
60 };
61 55
62 unsafe { 56 executor.spawn(run1()).dewrap();
63 executor.spawn(run1()).dewrap(); 57 executor.spawn(run2()).dewrap();
64 executor.spawn(run2()).dewrap();
65 58
66 loop { 59 loop {
67 executor.run(); 60 executor.run();
68 cortex_m::asm::wfe(); 61 cortex_m::asm::wfe();
69 }
70 } 62 }
71} 63}