Struct imxrt_hal::gpt::GPT [−][src]
pub struct GPT { /* fields omitted */ }
Expand description
A general purpose timer
The timers support three output compare registers. When a compare register matches the value of the counter, the GPT may trigger an interrupt.
By default, the timer runs in wait mode.
Implementations
Set the GPT mode
Refer to the module level documentation for more information on the GPT modes.
Set the reset on enable behavior
See the module level docs for more information.
Returns true
if the GPT counter will reset the next time it is enabled
Enable or disable the GPT
When enabled, the counter starts counting. When disabled, the counter will stop counting.
Allow the GPT to run in wait mode; or, prevent the GPT from running in wait mode.
Indicates if the GPT runs while in wait mode
Enable the GPT interrupt when the output compares
Returns true
if a comparison triggers an interrupt
Set an output compare register to trigger on the next count
value of the
counter.
Returns the current output compare count for the specified register
pub fn set_output_compare_duration(
&mut self,
output: OutputCompareRegister,
duration: Duration
)
pub fn set_output_compare_duration(
&mut self,
output: OutputCompareRegister,
duration: Duration
)
Set an output compare register to trigger when the specified duration elapses
This is a convenience for an operation that resembles
- compute the number of counts represented in the duration, based on the clock frequency
- acquire the current GPT count
- add the number of counts from 1 to the count of 2, accounting for wrap-around
- set the value for the OCR
pub fn output_compare_status(
&mut self,
output: OutputCompareRegister
) -> OutputCompareStatus<'_>
pub fn output_compare_status(
&mut self,
output: OutputCompareRegister
) -> OutputCompareStatus<'_>
Returns a handle that can query and modify the output compare status for the provided output
Returns the clock period as a duration
This represents the resolution of the clock. The maximum measurement
interval is clock_period() * u32::max_value()
.
Measure the execution time of an action act
using the GPT. Returns
the result of the action, along with how long it took to execute the
action.
User must ensure that the timer is enabled. Otherwise, the resulting duration is zero.
User must ensure that the action takes less time than it takes for the
timer to wrap around. We cannot distinguish a wrapped-around counter
from an incrementing counter with this implementation. Consider using
time_no_overflow
if you need a better guarantee.
pub fn time_no_overflow<F: FnOnce() -> R, R>(
&mut self,
output: OutputCompareRegister,
act: F
) -> (R, Option<Duration>)
pub fn time_no_overflow<F: FnOnce() -> R, R>(
&mut self,
output: OutputCompareRegister,
act: F
) -> (R, Option<Duration>)
Time an operation, returning the result, and the amount of time the operation took.
Unlike time()
, time_no_overflow()
uses an output compare register to check if the
counter overflowed. It requires a mutable GPT, since we need to
disable the timer and modify compare registers to properly measure the interval.
If the timer wrapped around, the return is None
.
When time_no_overflow()
returns,
- the GPT is disabled
- the interrupt on compare for the output is disabled
- the compare value in the specified output compare register is undefined
Users are responsible for resetting the state of the GPT as needed.
Users are responsible for enabling the GPT before using time_no_overflow()
.
Otherwise, the returned duration is non-None
, but zero.
If you know that you’re measuring short intervals that will not overflow the
counter, consider using time()
.
Returns an adapter that implements the count down trait
Assumes that the timer is already enabled. Otherwise, the count down adapter will block forever. The adapter will never disable the counter, so the borrowed GPT may still track other times while it is borrowed.
The adapter assumes the current GPT’s mode. User is responsible for making sure that this mode is sensible for the qualities of the timer.
Returns an adapter that implements the periodic trait
Assumes that the timer is already enabled. Otherwise, the periodic adapter will block forever. The adapter will never disable the counter. so the borrowed GPT may still track other times while it is borrowed.
The adapter assumes the current GPT’s mode. User is responsible for making sure this mode is sensible for the qualities of the timer.
Enable / disable an interrupt when the GPT counter rolls over from u32::max_value()
to
0
The GPT triggers a rollover regardless of the GPT mode.
Returns true
if a rollover generates an interrupt
Returns true
if the rollover flag is set
A rollover occurs when the counter rolls over from u32::max_value()
to 0
. Rollover
may occur regardless of the GPT mode.
Clear the rollover status flag
Users must clear the rollover flag if a rollover triggered an interrupt.