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§

Rtc
RTC clock.
Rwdt
RTC Watchdog Timer.
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§

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
Return reset reason.
wakeup_cause
Return the cause(s) of the most recent wakeup.