Skip to main content

Module rtc_cntl

Module rtc_cntl 

Source
Available on crate feature unstable only.
Expand description

§Real-Time Control and Low-power Management (RTC_CNTL)

§Overview

The RTC_CNTL peripheral is responsible for managing the low-power modes on the chip.

§Configuration

It also includes the necessary configurations and constants for clock sources and low-power management. The driver provides the following features and functionalities:

  • Clock Configuration
  • Calibration
  • Low-Power Management
  • Handling Watchdog Timers

§Examples

§Get time in ms from the RTC Timer


let rtc = Rtc::new(peripherals.RTC_TIMER);
let delay = Delay::new();

loop {
    // Print the current RTC time in milliseconds
    let time_ms = rtc.current_time_us() / 1000;
    delay.delay_millis(1000);

    // Set the time to half a second in the past
    let new_time = rtc.current_time_us() - 500_000;
    rtc.set_current_time_us(new_time);
}

§RWDT usage

static RWDT: Mutex<RefCell<Option<Rwdt>>> = Mutex::new(RefCell::new(None));

let mut delay = Delay::new();
let mut rtc = Rtc::new(peripherals.RTC_TIMER);

rtc.set_interrupt_handler(interrupt_handler);
rtc.rwdt
    .set_timeout(RwdtStage::Stage0, Duration::from_millis(2000));
rtc.rwdt.listen();

critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt));

// Where the `LP_WDT` interrupt handler is defined as:
static RWDT: Mutex<RefCell<Option<Rwdt>>> = Mutex::new(RefCell::new(None));

// Handle the corresponding interrupt
#[esp_hal::handler]
fn interrupt_handler() {
    critical_section::with(|cs| {
        println!("RWDT Interrupt");

        let mut rwdt = RWDT.borrow_ref_mut(cs);
        if let Some(rwdt) = rwdt.as_mut() {
            rwdt.clear_interrupt();

            println!("Restarting in 5 seconds...");

            rwdt.set_timeout(RwdtStage::Stage0, Duration::from_millis(5000));
            rwdt.unlisten();
        }
    });
}

§Get time in ms from the RTC Timer


let rtc = Rtc::new(peripherals.RTC_TIMER);
let delay = Delay::new();

loop {
    // Get the current RTC time in milliseconds
    let time_ms = rtc.current_time_us() / 1000;
    delay.delay_millis(1000);

    // Set the time to half a second in the past
    let new_time = rtc.current_time_us() - 500_000;
    rtc.set_current_time_us(new_time);
}

Modules§

sleep
RTC Control Sleep Module

Structs§

RetentionMemory
Memory that the hardware writes while a power domain has no power.
RetentionStorage
Storage for RetentionMemory.
Rtc
RTC clock.
Rwdt
RTC Watchdog Timer.
Swd
Super Watchdog
WakeLock
A guard that prevents the system from entering automatic light sleep.
WakeupReason
The source(s) that caused the most recent wakeup from sleep.

Enums§

RetentionMemoryError
The reason why a driver refused the retention memory.
RwdtStage
RWDT stages.
RwdtStageAction
Behavior of the RWDT stage if it times out.
SocResetReason
SOC Reset Reason.
WakeupSource
A source that can wake the chip from sleep.

Functions§

reset_reason
Returns reset reason.
wakeup_cause
Returns the cause(s) of the most recent wakeup.

Type Aliases§

CpuRetentionMemory
Memory that light sleep uses to retain the CPU domain.
CpuRetentionMemoryError
The reason why LowPower::install_cpu_retention_memory refused a buffer.
CpuRetentionStorage
Storage for CpuRetentionMemory.