Skip to content

Commit

Permalink
Set wakeup and sleep reject masks
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 13, 2023
1 parent 7371f6f commit ee2ec17
Showing 1 changed file with 35 additions and 38 deletions.
73 changes: 35 additions & 38 deletions esp-hal-common/src/rtc_cntl/sleep/esp32c6.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
use crate::{rtc_cntl::sleep::WakeTriggers, system::RadioPeripherals, Rtc};

bitfield::bitfield! {
#[derive(Clone, Copy)]
pub struct RtcConfig(u32);
impl Debug;
// TODO
}

impl Default for RtcConfig {
fn default() -> Self {
let mut cfg = Self(Default::default());
// TODO
cfg
}
}

bitfield::bitfield! {
#[derive(Clone, Copy)]
pub struct RtcInitConfig(u128);
impl Debug;

// TODO
}

impl Default for RtcInitConfig {
fn default() -> Self {
let mut cfg = Self(Default::default());

cfg
}
}

bitfield::bitfield! {
#[derive(Clone, Copy)]
// pmu_hp_analog_t.0
Expand Down Expand Up @@ -1026,8 +995,6 @@ impl RtcSleepConfig {
pub(crate) fn apply(&self) {
// like esp-idf pmu_sleep_init()

// TODO apply sleep flags?

self.power.apply();
if !self.deep {
self.digital.apply();
Expand All @@ -1037,6 +1004,41 @@ impl RtcSleepConfig {
}

pub(crate) fn start_sleep(&self, wakeup_triggers: WakeTriggers) {
const PMU_GPIO_WAKEUP_EN: u32 = 1 << 2;
const PMU_LP_TIMER_WAKEUP_EN: u32 = 1 << 4;
const PMU_WIFI_SOC_WAKEUP_EN: u32 = 1 << 5;
const PMU_UART0_WAKEUP_EN: u32 = 1 << 6;
const PMU_UART1_WAKEUP_EN: u32 = 1 << 7;
const PMU_BLE_SOC_WAKEUP_EN: u32 = 1 << 10;
const PMU_USB_WAKEUP_EN: u32 = 1 << 14;
const MODEM_REJECT: u32 = 1 << 16;

const RTC_SLEEP_REJECT_MASK: u32 = PMU_GPIO_WAKEUP_EN
| PMU_LP_TIMER_WAKEUP_EN
| PMU_WIFI_SOC_WAKEUP_EN
| PMU_UART0_WAKEUP_EN
| PMU_UART1_WAKEUP_EN
| PMU_BLE_SOC_WAKEUP_EN
| PMU_USB_WAKEUP_EN
| MODEM_REJECT // < if s_sleep_modem.wifi.phy_link != NULL
;

let wakeup_mask = wakeup_triggers.0 as u32;
let reject_mask = wakeup_mask & RTC_SLEEP_REJECT_MASK;

unsafe {
pmu()
.slp_wakeup_cntl2
.modify(|r, w| w.bits(r.bits() | wakeup_mask));

pmu().slp_wakeup_cntl1.modify(|r, w| {
w.sleep_reject_ena()
.bits(r.sleep_reject_ena().bits() | reject_mask)
.slp_reject_en()
.set_bit()
});
}

// like esp-idf pmu_sleep_start()

unsafe {
Expand All @@ -1046,11 +1048,6 @@ impl RtcSleepConfig {
.modify(|r, w| w.bits(r.bits() & !0x01 | self.deep as u32));
}

// TODO:
// pmu_ll_hp_set_wakeup_enable(PMU_instance()->hal->dev, wakeup_opt);
// pmu_ll_hp_set_reject_enable(PMU_instance()->hal->dev, reject_opt);
// TODO end

unsafe {
// pmu_ll_hp_clear_reject_cause
pmu()
Expand Down

0 comments on commit ee2ec17

Please sign in to comment.