From eef4e7bf7908d2a99c8d797d6f9d2ac3717e2b63 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 15 Oct 2019 18:44:49 -0500 Subject: more monotonic timer docs covers - initialization and configuration of the timer; this is now a responsibility of the application author - correctness of `Monotonic::now()` in `#[init]` - safety of `Monotonic::reset()` closes #251 --- examples/schedule.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'examples/schedule.rs') diff --git a/examples/schedule.rs b/examples/schedule.rs index 27d3bd1..97818e3 100644 --- a/examples/schedule.rs +++ b/examples/schedule.rs @@ -1,6 +1,5 @@ //! examples/schedule.rs -#![deny(unsafe_code)] #![deny(warnings)] #![no_main] #![no_std] @@ -13,8 +12,15 @@ use rtfm::cyccnt::{Instant, U32Ext as _}; #[rtfm::app(device = lm3s6965, monotonic = rtfm::cyccnt::CYCCNT)] const APP: () = { #[init(schedule = [foo, bar])] - fn init(cx: init::Context) { - let now = Instant::now(); + fn init(mut cx: init::Context) { + // Initialize (enable) the monotonic timer (CYCCNT) + cx.core.DCB.enable_trace(); + // required on devices that software lock the DWT (e.g. STM32F7) + unsafe { cx.core.DWT.lar.write(0xC5ACCE55) } + cx.core.DWT.enable_cycle_counter(); + + // semantically, the monotonic timer is frozen at time "zero" during `init` + let now = cx.start; // the start time of the system hprintln!("init @ {:?}", now).unwrap(); -- cgit v1.2.3