Module rustkey::timer

source ·
Expand description

timer module provides access to the device’s countdown-timer.

The timer counts down from the initial value and the resolution is scaled using the prescaler. With a prescaler value of 0, every clock-cycle is a timer-tick. For a timer that ticks every second, set the prescaler to 18_000_000 and then initialize the timer with however many seconds count-down is needed.

Note: these functions require knowledge of the current state of the timer (running/stopped), because both initial timer value and prescaler can be modified, which completely alters the interpretation of timer values, therefore it is critical to be aware of the current configuration.

Constants§

Functions§

  • current gets the initial timer value if stopped, or the current timer value if running.
  • initialize sets the initial timer value. Only allowed if timer is not running.
  • running() indicates the current status of the timer: false if stopped, true if running.
  • set_prescaler sets the prescaler. A value is 18_000_000, i.e. gives one tick per second given that the processor operates at 18 MHz. The prescaler can be used to scale the timer from very high frequencies (microseconds) with low or zero prescaler, to low frequencies (seconds) with high prescaler.
  • sleep use timer to perform a timed sleep in amount of seconds. (Blocking until timer expires.)
  • start starts the timer if stopped.
  • stop stops the timer if started.
  • wait waits until the timer has stopped.
  • wait_for waits for a specified number of ticks of the timer to pass. The timer must be running.
  • wait_until waits until the timer count-down reaches or has passed the specified value. The timer must be running.