mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
docs: do not use Instant::now in #[init]
This commit is contained in:
parent
6b0a2df41c
commit
b04103f6df
2 changed files with 5 additions and 0 deletions
|
@ -20,6 +20,7 @@ const APP: () = {
|
||||||
cx.core.DWT.enable_cycle_counter();
|
cx.core.DWT.enable_cycle_counter();
|
||||||
|
|
||||||
// semantically, the monotonic timer is frozen at time "zero" during `init`
|
// semantically, the monotonic timer is frozen at time "zero" during `init`
|
||||||
|
// NOTE do *not* call `Instant::now` in this context; it will return a nonsense value
|
||||||
let now = cx.start; // the start time of the system
|
let now = cx.start; // the start time of the system
|
||||||
|
|
||||||
hprintln!("init @ {:?}", now).unwrap();
|
hprintln!("init @ {:?}", now).unwrap();
|
||||||
|
|
|
@ -30,6 +30,10 @@ pub struct Instant {
|
||||||
|
|
||||||
impl Instant {
|
impl Instant {
|
||||||
/// Returns an instant corresponding to "now"
|
/// Returns an instant corresponding to "now"
|
||||||
|
///
|
||||||
|
/// *HEADS UP* this function can, and will, return nonsensical values if called within `init`.
|
||||||
|
/// Only use it in `idle` and tasks. In `init`, use the `init::Context.start` field, or the
|
||||||
|
/// `CYCCNT::zero` function, instead of this function
|
||||||
pub fn now() -> Self {
|
pub fn now() -> Self {
|
||||||
Instant {
|
Instant {
|
||||||
inner: DWT::get_cycle_count() as i32,
|
inner: DWT::get_cycle_count() as i32,
|
||||||
|
|
Loading…
Reference in a new issue