implementation of stops and reorganization of the codebase
This commit is contained in:
35
semestralka_2_uart/src/sleep/handler.rs
Normal file
35
semestralka_2_uart/src/sleep/handler.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use crate::sleep::stop::StopEntry;
|
||||
use crate::sleep::stop::*;
|
||||
use crate::hw_uart_pc::init::{LowPowerCmd, StopMode, StopModeConfig};
|
||||
|
||||
use defmt::info;
|
||||
|
||||
pub fn execute_low_power(cmd: LowPowerCmd) -> ! {
|
||||
match cmd {
|
||||
LowPowerCmd::Standby8k => {
|
||||
info!("Entering Standby with 8KB SRAM2 retention");
|
||||
// call your existing standby function here
|
||||
super::standby::enter_standby_with_sram2_8kb();
|
||||
}
|
||||
LowPowerCmd::StandbyFull => {
|
||||
info!("Entering Standby with full SRAM2 retention");
|
||||
super::standby::enter_standby_with_sram2_full();
|
||||
}
|
||||
LowPowerCmd::Standby => {
|
||||
info!("Entering minimal Standby");
|
||||
super::standby::enter_standby();
|
||||
}
|
||||
LowPowerCmd::Shutdown => {
|
||||
info!("Entering Shutdown mode");
|
||||
super::shutdown::enter_shutdown();
|
||||
}
|
||||
LowPowerCmd::StopMode(StopModeConfig { mode, entry }) => {
|
||||
info!("Entering {:?} with {:?}", mode, entry);
|
||||
match mode {
|
||||
StopMode::Stop1 => enter_stop1(entry),
|
||||
StopMode::Stop2 => enter_stop2(entry),
|
||||
StopMode::Stop3 => enter_stop3(entry),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,7 @@
|
||||
|
||||
pub mod standby;
|
||||
pub mod shutdown;
|
||||
pub mod stop3;
|
||||
pub mod stop;
|
||||
pub mod handler;
|
||||
|
||||
pub use stop::StopEntry;
|
||||
|
||||
55
semestralka_2_uart/src/sleep/stop.rs
Normal file
55
semestralka_2_uart/src/sleep/stop.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// src/sleep/stop.rs
|
||||
|
||||
/// How to enter STOPx mode (STOP0–STOP3)
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
|
||||
pub enum StopEntry {
|
||||
Wfi,
|
||||
Wfe,
|
||||
WfeNoEventClear,
|
||||
}
|
||||
|
||||
impl From<StopEntry> for u8 {
|
||||
fn from(value: StopEntry) -> Self {
|
||||
match value {
|
||||
StopEntry::Wfi => 0x01,
|
||||
StopEntry::Wfe => 0x02,
|
||||
StopEntry::WfeNoEventClear => 0x03,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter_stop1(entry: StopEntry) -> ! {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP1Mode(entry: u8);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP1Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
pub fn enter_stop2(entry: StopEntry) -> ! {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP2Mode(entry: u8);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP2Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
pub fn enter_stop3(entry: StopEntry) -> ! {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP3Mode(entry: u8);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP3Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// src/sleep/stop3.rs
|
||||
|
||||
// #define PWR_STOPENTRY_WFI (0x01U) //*!< Wait For Interruption instruction to enter Stop mode */
|
||||
// #define PWR_STOPENTRY_WFE (0x02U) //*!< Wait For Event instruction to enter Stop mode */
|
||||
// #define PWR_STOPENTRY_WFE_NO_EVT_CLEAR (0x03U)
|
||||
|
||||
/// How to enter STOP3 mode
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum StopEntry {
|
||||
Wfi,
|
||||
Wfe,
|
||||
WfeNoEventClear,
|
||||
}
|
||||
|
||||
impl From<StopEntry> for u8 {
|
||||
fn from(value: StopEntry) -> Self {
|
||||
match value {
|
||||
StopEntry::Wfi => 0x01,
|
||||
StopEntry::Wfe => 0x02,
|
||||
StopEntry::WfeNoEventClear => 0x03,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn enter_stop3(stop_entry: StopEntry) -> ! {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP3Mode(stop_entry: u8);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP3Mode(stop_entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf(); //panic
|
||||
}
|
||||
|
||||
// Example usage:
|
||||
// enter_stop3(StopEntry::Wfi);
|
||||
// enter_stop3(StopEntry::Wfe);
|
||||
// enter_stop3(StopEntry::WfeNoEventClear);
|
||||
Reference in New Issue
Block a user