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
This commit is contained in:
Jorge Aparicio 2019-10-15 18:44:49 -05:00
parent 6196984d6d
commit eef4e7bf79
6 changed files with 33 additions and 5 deletions

View file

@ -14,6 +14,8 @@ use panic_semihosting as _;
const APP: () = {
#[init(spawn = [foo])]
fn init(cx: init::Context) {
// omitted: initialization of `CYCCNT`
hprintln!("init(baseline = {:?})", cx.start).unwrap();
// `foo` inherits the baseline of `init`: `Instant(0)`

View file

@ -16,6 +16,8 @@ const PERIOD: u32 = 8_000_000;
const APP: () = {
#[init(schedule = [foo])]
fn init(cx: init::Context) {
// omitted: initialization of `CYCCNT`
cx.schedule.foo(Instant::now() + PERIOD.cycles()).unwrap();
}

View file

@ -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();