pub trait Counter<'a>: Time {
// Required methods
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§
sourcefn set_overflow_client(&self, client: &'a dyn OverflowClient)
fn set_overflow_client(&self, client: &'a dyn OverflowClient)
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.
sourcefn start(&self) -> Result<(), ErrorCode>
fn start(&self) -> Result<(), ErrorCode>
Starts the free-running hardware counter. Valid Result<(), ErrorCode>
values are:
Ok(())
: the counter is now runningErr(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 tostart
,is_running
MUST return true.
sourcefn stop(&self) -> Result<(), ErrorCode>
fn stop(&self) -> Result<(), ErrorCode>
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 tostop
,is_running
MUST return false.
sourcefn reset(&self) -> Result<(), ErrorCode>
fn reset(&self) -> Result<(), ErrorCode>
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.
sourcefn is_running(&self) -> bool
fn is_running(&self) -> bool
Returns whether the counter is currently running.