pub trait Counter<'a>: Time {
    fn set_overflow_client(&self, client: &'a dyn OverflowClient);
    fn start(&self) -> Result<(), ErrorCode>;
    fn stop(&self) -> Result<(), ErrorCode>;
    fn reset(&self) -> Result<(), ErrorCode>;
    fn is_running(&self) -> bool;
}
Expand description

Represents a free-running hardware counter that can be started and stopped.

Required Methods

Specify the callback for when the counter overflows its maximum value (defined by Ticks). If there was a previously registered callback this call replaces it.

Starts the free-running hardware counter. Valid Result<(), ErrorCode> values are:

  • Ok(()): the counter is now running
  • Err(ErrorCode::OFF): underlying clocks or other hardware resources are not on, such that the counter cannot start.
  • Err(ErrorCode::FAIL): unidentified failure, counter is not running. After a successful call to start, is_running MUST return true.

Stops the free-running hardware counter. Valid Result<(), ErrorCode> values are:

  • Ok(()): the counter is now stopped. No further overflow callbacks will be invoked.
  • Err(ErrorCode::BUSY): the counter is in use in a way that means it cannot be stopped and is busy.
  • Err(ErrorCode::FAIL): unidentified failure, counter is running. After a successful call to stop, is_running MUST return false.

Resets the counter to 0. This may introduce jitter on the counter. Resetting the counter has no effect on any pending overflow callbacks. If a client needs to reset and clear pending callbacks it should call stop before reset. Valid Result<(), ErrorCode> values are:

  • Ok(()): the counter was reset to 0.
  • Err(ErrorCode::FAIL): the counter was not reset to 0.

Returns whether the counter is currently running.

Implementors