Move Super Watchdog functions into RTC_CNTL common implementation (#125)
* esp32c3: Move SWD functions into RTC_CNTL common implementation Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com> * esp32s3: Extend SWD functions to ESP32-S3 Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
parent
83ac67be23
commit
224e84d9dc
@ -43,7 +43,6 @@ pub mod interrupt;
|
||||
pub mod prelude;
|
||||
pub mod pulse_control;
|
||||
pub mod rng;
|
||||
#[cfg(not(feature = "esp32c3"))]
|
||||
pub mod rtc_cntl;
|
||||
pub mod serial;
|
||||
pub mod spi;
|
||||
@ -58,7 +57,6 @@ pub use interrupt::*;
|
||||
pub use procmacros as macros;
|
||||
pub use pulse_control::PulseControl;
|
||||
pub use rng::Rng;
|
||||
#[cfg(not(feature = "esp32c3"))]
|
||||
pub use rtc_cntl::RtcCntl;
|
||||
pub use serial::Serial;
|
||||
pub use spi::Spi;
|
||||
|
||||
@ -23,4 +23,24 @@ impl RtcCntl {
|
||||
.modify(|_, w| w.wdt_en().bit(enable).wdt_flashboot_mod_en().clear_bit());
|
||||
self.set_wdt_write_protection(true);
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "esp32c3", feature = "esp32s3"))]
|
||||
pub fn set_super_wdt_enable(&mut self, enable: bool) {
|
||||
self.set_swd_write_protection(false);
|
||||
|
||||
self.rtc_cntl
|
||||
.swd_conf
|
||||
.write(|w| w.swd_auto_feed_en().bit(!enable));
|
||||
|
||||
self.set_swd_write_protection(true);
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "esp32c3", feature = "esp32s3"))]
|
||||
fn set_swd_write_protection(&mut self, enable: bool) {
|
||||
let wkey = if enable { 0u32 } else { 0x8F1D_312A };
|
||||
|
||||
self.rtc_cntl
|
||||
.swd_wprotect
|
||||
.write(|w| unsafe { w.swd_wkey().bits(wkey) });
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ fn main() -> ! {
|
||||
let mut wdt1 = timer_group1.wdt;
|
||||
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ fn main() -> ! {
|
||||
|
||||
// Disable watchdog timers
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ fn main() -> ! {
|
||||
let mut wdt1 = timer_group1.wdt;
|
||||
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ fn main() -> ! {
|
||||
let mut wdt1 = timer_group1.wdt;
|
||||
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ fn main() -> ! {
|
||||
|
||||
// Disable watchdogs
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
|
||||
// Configure RMT peripheral globally
|
||||
|
||||
@ -34,7 +34,7 @@ fn main() -> ! {
|
||||
|
||||
// Disable watchdog timers
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ fn main() -> ! {
|
||||
|
||||
// Disable watchdog timers
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ fn main() -> ! {
|
||||
|
||||
// Disable watchdog timers
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ fn main() -> ! {
|
||||
|
||||
// Disable watchdog timers
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ fn main() -> ! {
|
||||
let mut serial0 = Serial::new(peripherals.UART0);
|
||||
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ fn main() -> ! {
|
||||
let mut wdt1 = timer_group1.wdt;
|
||||
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ fn main() -> ! {
|
||||
let mut wdt1 = timer_group1.wdt;
|
||||
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ fn main() -> ! {
|
||||
|
||||
// Disable watchdog timers
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.disable();
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ fn main() -> ! {
|
||||
|
||||
// Disable watchdog timers
|
||||
rtc_cntl.set_super_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_enable(false);
|
||||
rtc_cntl.set_wdt_global_enable(false);
|
||||
wdt0.start(2u64.secs());
|
||||
wdt1.disable();
|
||||
|
||||
|
||||
@ -23,17 +23,17 @@ pub use esp_hal_common::{
|
||||
Delay,
|
||||
PulseControl,
|
||||
Rng,
|
||||
RtcCntl,
|
||||
Serial,
|
||||
UsbSerialJtag,
|
||||
};
|
||||
#[cfg(feature = "direct-boot")]
|
||||
use riscv_rt::pre_init;
|
||||
|
||||
pub use self::{gpio::IO, rtc_cntl::RtcCntl};
|
||||
pub use self::gpio::IO;
|
||||
|
||||
pub mod adc;
|
||||
pub mod gpio;
|
||||
pub mod rtc_cntl;
|
||||
|
||||
/// Common module for analog functions
|
||||
pub mod analog {
|
||||
|
||||
@ -1,49 +0,0 @@
|
||||
use crate::pac::RTC_CNTL;
|
||||
|
||||
pub struct RtcCntl {
|
||||
rtc_cntl: RTC_CNTL,
|
||||
}
|
||||
|
||||
impl RtcCntl {
|
||||
pub fn new(rtc_cntl: RTC_CNTL) -> Self {
|
||||
Self { rtc_cntl }
|
||||
}
|
||||
|
||||
pub fn set_super_wdt_enable(&mut self, enable: bool) {
|
||||
self.set_swd_write_protection(false);
|
||||
|
||||
self.rtc_cntl
|
||||
.swd_conf
|
||||
.write(|w| w.swd_auto_feed_en().bit(!enable));
|
||||
|
||||
self.set_swd_write_protection(true);
|
||||
}
|
||||
|
||||
fn set_swd_write_protection(&mut self, enable: bool) {
|
||||
let wkey = if enable { 0u32 } else { 0x8F1D_312A };
|
||||
|
||||
self.rtc_cntl
|
||||
.swd_wprotect
|
||||
.write(|w| unsafe { w.swd_wkey().bits(wkey) });
|
||||
}
|
||||
|
||||
pub fn set_wdt_enable(&mut self, enable: bool) {
|
||||
self.set_wdt_write_protection(false);
|
||||
|
||||
if !enable {
|
||||
self.rtc_cntl.wdtconfig0.write(|w| unsafe { w.bits(0) });
|
||||
} else {
|
||||
self.rtc_cntl.wdtconfig0.write(|w| w.wdt_en().bit(enable));
|
||||
}
|
||||
|
||||
self.set_wdt_write_protection(true);
|
||||
}
|
||||
|
||||
fn set_wdt_write_protection(&mut self, enable: bool) {
|
||||
let wkey = if enable { 0u32 } else { 0x50D8_3AA1 };
|
||||
|
||||
self.rtc_cntl
|
||||
.wdtwprotect
|
||||
.write(|w| unsafe { w.wdt_wkey().bits(wkey) });
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user