API referencestd/embedded

std/embedded/chip/esp_rtc

Public declarations, types, methods, and source contracts for std/embedded/chip/esp_rtc.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/embedded/chip/esp_rtc"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
hal std/embedded/hal esp_rtc.dodo

PERIOD_FRACTION

Constant · Source

Periods are microseconds per slow clock tick with this many fraction bits, as Espressif keeps them.

pub const PERIOD_FRACTION: u32 = 19

NOMINAL_PERIOD

Constant · Source

The nominal period of a 136 kHz RC_SLOW_CLK, before calibrating.

pub const NOMINAL_PERIOD: u32 = 3_855_059

ALARM_SOURCE

Constant · Source

The interrupt matrix source the alarm raises: esp32c6.LP_RTC_TIMER.

pub const ALARM_SOURCE: u32 = 15

RECORD_ADDRESS

Constant · Source

Where the chip keeps the record: the last 32 bytes of LP SRAM.

pub const RECORD_ADDRESS: usize = 0x5000_3FE0

CALIBRATION_CYCLES

Constant · Source

The slow clock cycles take() counts: about 7.5 ms.

pub const CALIBRATION_CYCLES: u32 = 1024

calibrate

Function · Source

Measure the RTC slow clock against the 40 MHz crystal with the timer group’s RTC calibration unit at registers, over cycles (1 to 32767) slow clock cycles, and return its period: microseconds per tick with PERIOD_FRACTION fraction bits. A periodic calibration left running is stopped first. Timeout if the unit never finishes, as when the slow clock does not run; InvalidInput for a cycle count out of range. SAFETY: only the caller may use the group’s calibration registers.

pub unsafe fn calibrate<R: hal.Registers>(registers: &mut R, cycles: u32) -> u32!hal.Error

Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.

ticks_to_us

Function · Source

The microseconds ticks slow clock ticks of period last, without overflowing for any 48-bit count.

pub fn ticks_to_us(ticks: u64, period: u32) -> u64

us_to_ticks

Function · Source

The ticks of period in microseconds, rounded down; microseconds is below 2^44, about six months.

pub fn us_to_ticks(microseconds: u64, period: u32) -> u64

Clock

Struct · Source

The LP timer over any hal.Registers, with its epoch in a record. Implements hal.Rtc and hal.RtcAlarm with a resolution of one millisecond.

pub struct Clock<R: hal.Registers>: hal.Rtc + hal.RtcAlarm {
    // Private implementation fields omitted.
}

Clock.new

Function · Source

Take the LP timer at timer, with its record in record, and the slow clock’s period period as calibrate measured it (0 to keep the period the record has, or NOMINAL_PERIOD without one). A clock set before a reset keeps its time: it is rebased on the new period from now on. The alarm is disarmed and its interrupt off. SAFETY: timer must be the LP timer’s registers and record eight words that survive resets, and nothing else may write either while the Clock exists.

pub unsafe fn new(timer: R, record: R, period: u32) -> Clock<R> from(timer, record)

Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.

Clock.period

Function · Source

The slow clock’s period the clock converts with: microseconds per tick with PERIOD_FRACTION fraction bits.

pub fn period(&self) -> u32

Clock.set_period

Function · Source

Convert with period from now on, keeping the time the clock shows now: after a new calibrate. InvalidInput for a period of 0.

pub fn set_period(&mut self, period: u32) -> void!hal.Error

Clock.ticks

Function · Source

The LP timer’s count: slow clock ticks since power-up.

pub fn ticks(&mut self) -> u64

Clock.is_set

Function · Source

pub fn is_set(&mut self) -> bool!hal.Error

Clock.resolution_ms

Function · Source

pub fn resolution_ms(&self) -> u32

Clock.now_ms

Function · Source

pub fn now_ms(&mut self) -> u64!hal.Error

Clock.set_ms

Function · Source

Set the time and start counting from it. The alarm stays armed at its tick; set it again for a time. InvalidInput past the year 584,000, where microseconds overflow.

pub fn set_ms(&mut self, time_ms: u64) -> void!hal.Error

Clock.set_alarm_ms

Function · Source

Fire when the clock reaches time_ms. Busy if the clock is not set; InvalidInput more than six months ahead.

pub fn set_alarm_ms(&mut self, time_ms: u64) -> void!hal.Error

Clock.alarm_fired

Function · Source

pub fn alarm_fired(&mut self) -> bool!hal.Error

Clock.clear_alarm

Function · Source

Disarm the alarm and acknowledge it.

pub fn clear_alarm(&mut self) -> void!hal.Error

Clock.listen

Function · Source

Raise the LP timer’s interrupt when the alarm fires.

pub fn listen(&mut self)

Clock.ignore

Function · Source

Stop raising the interrupt; alarm_fired still reports.

pub fn ignore(&mut self)

Clock.is_listening

Function · Source

pub fn is_listening(&mut self) -> bool

Clock.unset

Function · Source

Forget the time: the clock reads as not set until set_ms.

pub fn unset(&mut self)

Clock.release

Function · Source

Disarm the alarm and stop its interrupt, and give back the registers. The timer keeps counting, and the record its time.

pub fn release(self) -> (R, R) from(self)

Rtc

Struct · Source

The LP timer on the chip as a real-time clock, which the chip package hands out: a Clock over the LP timer’s registers and the record in LP SRAM. Implements hal.Rtc and hal.RtcAlarm.

pub struct Rtc: hal.Rtc + hal.RtcAlarm {
    // Private implementation fields omitted.
}

Rtc.at

Function · Source

The clock over the LP timer at timer_base and the record at record_base, calibrated with the RTC calibration unit of the timer group at calibration_base. Timeout if the slow clock does not run. SAFETY: as for Clock.new and calibrate.

pub unsafe fn at(timer_base: usize, record_base: usize, calibration_base: usize) -> Rtc!hal.Error

Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.

Rtc.is_set

Function · Source

pub fn is_set(&mut self) -> bool!hal.Error

Rtc.now_ms

Function · Source

pub fn now_ms(&mut self) -> u64!hal.Error

Rtc.set_ms

Function · Source

pub fn set_ms(&mut self, time_ms: u64) -> void!hal.Error

Rtc.resolution_ms

Function · Source

1: the clock counts milliseconds, from ticks of about 7.4 us.

pub fn resolution_ms(&self) -> u32

Rtc.set_alarm_ms

Function · Source

pub fn set_alarm_ms(&mut self, time_ms: u64) -> void!hal.Error

Rtc.alarm_fired

Function · Source

pub fn alarm_fired(&mut self) -> bool!hal.Error

Rtc.clear_alarm

Function · Source

pub fn clear_alarm(&mut self) -> void!hal.Error

Rtc.calibrate

Function · Source

Measure the slow clock against the crystal again, about 7.5 ms, and convert with the new period from now on; the time shown does not jump. Timeout if the slow clock does not run.

pub fn calibrate(&mut self) -> void!hal.Error

Rtc.period

Function · Source

The slow clock’s period: microseconds per tick with PERIOD_FRACTION fraction bits; 1_000_000 << PERIOD_FRACTION over it is its frequency.

pub fn period(&self) -> u32

Rtc.slow_clock_hz

Function · Source

The slow clock’s frequency in hertz, as last calibrated.

pub fn slow_clock_hz(&self) -> u32

Rtc.ticks

Function · Source

The LP timer’s count: slow clock ticks since power-up.

pub fn ticks(&mut self) -> u64

Rtc.unset

Function · Source

Forget the time: the clock reads as not set until set_ms.

pub fn unset(&mut self)

Rtc.irq

Function · Source

The alarm’s interrupt: its source number for esp32c6.enable, and its vector name, LP_RTC_TIMER, for @interrupt.

pub fn irq(&self) -> u32

Rtc.listen

Function · Source

Raise LP_RTC_TIMER when the alarm fires. Route the source too: esp32c6.enable(rtc.irq()).

pub fn listen(&mut self)

Rtc.ignore

Function · Source

Stop raising the interrupt; alarm_fired still reports.

pub fn ignore(&mut self)

Rtc.is_listening

Function · Source

pub fn is_listening(&mut self) -> bool

Search every guide, reference page, and API declaration.