Expand description
§System Timer (SYSTIMER)
§Overview
The System Timer is a 52-bit timer which can be used, for example, to generate tick interrupts for an operating system, or simply as a general-purpose timer.
§Configuration
The timer consists of two counters, UNIT0 and UNIT1. The counter values
can be monitored by 3 comparators, COMP0, COMP1, and COMP2.
Alarms can be configured in two modes: Target (one-shot) and Periodic.
§Examples
§Splitting up the System Timer into three alarms
Use the split method to create three alarms from the System Timer, contained in a SysTimerAlarms struct.
use esp_hal::timer::systimer::{
SystemTimer,
Periodic,
};
let systimer = SystemTimer::new(
peripherals.SYSTIMER,
).split::<Periodic>();
// Reconfigure a periodic alarm to be a target alarm
let target_alarm = systimer.alarm0.into_target();§General-purpose Timer
use esp_hal::timer::systimer::{
Alarm,
FrozenUnit,
SpecificUnit,
SystemTimer,
};
let mut systimer = SystemTimer::new(peripherals.SYSTIMER);
// Get the current tick count:
let now = SystemTimer::now();
let frozen_unit = FrozenUnit::new(&mut systimer.unit0);
let alarm0 = Alarm::new(systimer.comparator0, &frozen_unit);
alarm0.set_target(
SystemTimer::now() + SystemTimer::ticks_per_second() * 2
);
alarm0.enable_interrupt(true);
while !alarm0.is_interrupt_set() {
// Wait for the interrupt to be set
}
alarm0.clear_interrupt();Modules§
- Event Task Matrix Function
Structs§
- A single alarm.
- Any Comparator. Could be either comparator 0, comparator 1, etc.
- Any Unit. Could be either unit 0 or unit 1.
- A unit whose value cannot be updated.
- A marker for a Alarm in periodic mode.
- A specific Comparator. i.e. Either comparator 0, comparator 1, etc.
- A specific Unit. i.e. Either unit 0 or unit 1.
- Alarms created from the System Timer peripheral.
- System Timer driver.
- A marker for a Alarm in target mode.
Enums§
- The modes of a comparator.
- The configuration of a unit.
Traits§
- A comparator that can generate alarms/interrupts based on values of a unit.
- A 52-bit counter.