Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset functionalities #420

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esp-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub mod prelude;
pub mod pulse_control;
#[cfg(radio)]
pub mod radio;
pub mod reset;
pub mod rng;
pub mod rom;
pub mod rtc_cntl;
Expand Down
17 changes: 17 additions & 0 deletions esp-hal-common/src/reset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::rtc_cntl::SocResetReason;

pub fn software_reset() {
unsafe { crate::rtc_cntl::software_reset() }

}
pub fn software_reset_cpu() {
unsafe { crate::rtc_cntl::software_reset_cpu() }
}

pub fn get_reset_reason() -> Option<SocResetReason> {
crate::rtc_cntl::get_reset_reason(crate::get_core())
}

pub fn get_wakeup_cause() -> u32 {
crate::rtc_cntl::get_wakeup_cause()
}
10 changes: 9 additions & 1 deletion esp-hal-common/src/rtc_cntl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use embedded_hal::watchdog::{Watchdog, WatchdogDisable, WatchdogEnable};
use fugit::HertzU32;
use fugit::MicrosDurationU64;

use self::rtc::SocResetReason;
pub use self::rtc::SocResetReason;
#[cfg(not(esp32c6))]
use crate::clock::{Clock, XtalClock};
#[cfg(not(esp32))]
Expand Down Expand Up @@ -37,6 +37,9 @@ extern "C" {
#[allow(dead_code)]
fn ets_delay_us(us: u32);
fn rtc_get_reset_reason(cpu_num: u32) -> u32;
fn rtc_get_wakeup_cause() -> u32;
pub fn software_reset_cpu();
pub fn software_reset();
}

#[cfg(not(esp32c6))]
Expand Down Expand Up @@ -810,3 +813,8 @@ pub fn get_reset_reason(cpu: Cpu) -> Option<SocResetReason> {

reason
}

pub fn get_wakeup_cause() -> u32 {
let cause = unsafe { rtc_get_wakeup_cause() };
cause
}
3 changes: 3 additions & 0 deletions esp32-hal/ld/rom-functions.x
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ PROVIDE(ets_update_cpu_frequency_rom = 0x40008550);
PROVIDE(rom_i2c_writeReg = 0x400041a4);
PROVIDE(rom_i2c_writeReg_Mask = 0x400041fc);
PROVIDE(rtc_get_reset_reason = 0x400081d4);
PROVIDE(rtc_get_wakeup_cause = 0x400081f4);
PROVIDE(software_reset = 0x4000824c);
PROVIDE(software_reset_cpu = 0x40008264);
1 change: 1 addition & 0 deletions esp32-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub use esp_hal_common::{
peripherals,
prelude,
pulse_control,
reset,
sha,
spi,
system,
Expand Down
3 changes: 3 additions & 0 deletions esp32c2-hal/ld/rom-functions.x
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ PROVIDE(ets_update_cpu_frequency_rom = 0x40000774);
PROVIDE(rom_i2c_writeReg = 0x400022f4);
PROVIDE(rom_i2c_writeReg_Mask = 0x400022fc);
PROVIDE(rtc_get_reset_reason = 0x40000018);
PROVIDE(rtc_get_wakeup_cause = 0x40000020);
PROVIDE(software_reset = 0x40000088);
PROVIDE(software_reset_cpu = 0x4000008c);
1 change: 1 addition & 0 deletions esp32c2-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub use esp_hal_common::{
macros,
peripherals,
prelude,
reset,
riscv,
sha,
spi,
Expand Down
3 changes: 3 additions & 0 deletions esp32c3-hal/ld/rom-functions.x
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ PROVIDE(ets_update_cpu_frequency_rom = 0x40000588);
PROVIDE(rom_i2c_writeReg = 0x4000195c);
PROVIDE(rom_i2c_writeReg_Mask = 0x40001960);
PROVIDE(rtc_get_reset_reason = 0x40000018);
PROVIDE(rtc_get_wakeup_cause = 0x40000024);
PROVIDE(software_reset = 0x40000090);
PROVIDE(software_reset_cpu = 0x40000094);
1 change: 1 addition & 0 deletions esp32c3-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub use esp_hal_common::{
peripherals,
prelude,
pulse_control,
reset,
riscv,
sha,
spi,
Expand Down
3 changes: 3 additions & 0 deletions esp32c6-hal/ld/rom-functions.x
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ PROVIDE(cache_resume_icache = 0x4000069c);
PROVIDE(ets_delay_us = 0x40000040);
PROVIDE(ets_update_cpu_frequency_rom = 0x40000048);
PROVIDE(rtc_get_reset_reason = 0x40000018);
PROVIDE(rtc_get_wakeup_cause = 0x40000020);
ets_update_cpu_frequency = 0x40000048;
PROVIDE(software_reset = 0x40000090);
PROVIDE(software_reset_cpu = 0x40000094);
1 change: 1 addition & 0 deletions esp32c6-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub use esp_hal_common::{
peripherals,
prelude,
pulse_control,
reset,
riscv,
sha,
spi,
Expand Down
3 changes: 3 additions & 0 deletions esp32s2-hal/ld/rom-functions.x
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ PROVIDE(ets_update_cpu_frequency_rom = 0x4000d8a4);
PROVIDE(rom_i2c_writeReg = 0x4000a9a8);
PROVIDE(rom_i2c_writeReg_Mask = 0x4000aa00);
PROVIDE(rtc_get_reset_reason = 0x4000ff58);
PROVIDE(rtc_get_wakeup_cause = 0x4000ff7c);
PROVIDE(software_reset = 0x40010068);
PROVIDE(software_reset_cpu = 0x40010080);
1 change: 1 addition & 0 deletions esp32s2-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use esp_hal_common::{
peripherals,
prelude,
pulse_control,
reset,
sha,
spi,
system,
Expand Down
3 changes: 3 additions & 0 deletions esp32s3-hal/ld/rom-functions.x
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ PROVIDE(ets_update_cpu_frequency_rom = 0x40043164);
PROVIDE(rom_i2c_writeReg = 0x40005d60);
PROVIDE(rom_i2c_writeReg_Mask = 0x40005d6c);
PROVIDE(rtc_get_reset_reason = 0x4000057c);
PROVIDE(rtc_get_wakeup_cause = 0x400005a0);
PROVIDE(software_reset = 0x400006d8);
PROVIDE(software_reset_cpu = 0x400006e4);
1 change: 1 addition & 0 deletions esp32s3-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use esp_hal_common::{
peripherals,
prelude,
pulse_control,
reset,
sha,
spi,
system,
Expand Down