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.LPWR);
let delay = Delay::new();

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

    // Set the time to half a second in the past
    let new_time = rtc.current_time() - Duration::from_millis(500);
    rtc.set_current_time(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.LPWR);

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
#[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.LPWR);
let delay = Delay::new();

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

    // Set the time to half a second in the past
    let new_time = rtc.current_time() - Duration::from_millis(500);
    rtc.set_current_time(new_time);
}

Modules§

sleep
RTC Control Sleep Module

Structs§

Rtc
Low-power Management
RtcClock
RTC Watchdog Timer.
Rwdt
RTC Watchdog Timer.
Swd
Super Watchdog

Enums§

RwdtStage
RWDT stages.
RwdtStageAction
Behavior of the RWDT stage if it times out.
SocResetReason
SOC Reset Reason.

Functions§

reset_reason
Return reset reason.
wakeup_cause
Return wakeup reason.