implementation of stops and reorganization of the codebase
This commit is contained in:
@@ -7,6 +7,8 @@ use embassy_futures::yield_now;
|
||||
// UART HW init
|
||||
use crate::config::{BAUD, PIPE_HW_TX, PIPE_HW_RX};
|
||||
use crate::hw_uart_pc::driver::uart_task;
|
||||
use crate::sleep::StopEntry;
|
||||
use crate::sleep::handler::execute_low_power;
|
||||
use static_cell::StaticCell;
|
||||
use embassy_stm32::usart::BufferedInterruptHandler;
|
||||
use embassy_stm32::usart::{BufferedUart, Config as UsartConfig};
|
||||
@@ -21,67 +23,78 @@ bind_interrupts!(struct Irqs {
|
||||
USART1 => BufferedInterruptHandler<peripherals::USART1>;
|
||||
});
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
|
||||
pub enum LowPowerCmd {
|
||||
Standby8k, // 1
|
||||
StandbyFull, // 2
|
||||
Standby, // 3
|
||||
Shutdown, // 4
|
||||
Stop3Wfi,
|
||||
Stop3Wfe,
|
||||
Stop3WfeNoClear,
|
||||
StopMode(StopModeConfig),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
|
||||
pub struct StopModeConfig {
|
||||
pub mode: StopMode,
|
||||
pub entry: StopEntry,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
|
||||
pub enum StopMode {
|
||||
Stop1,
|
||||
Stop2,
|
||||
Stop3,
|
||||
}
|
||||
|
||||
pub static CMD_CH: Channel<CriticalSectionRawMutex, LowPowerCmd, 1> = Channel::new();
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn uart_cmd_task() {
|
||||
// Prompt once
|
||||
let _ = PIPE_HW_TX
|
||||
.write(b"Modes: 1=SB8, 2=SBfull, 3=SB, 4=SD, 5=STOP3(WFI), 6=STOP3(WFE), 7=STOP3(WFE no clear)\r\n")
|
||||
.await;
|
||||
let _ = PIPE_HW_TX.write(
|
||||
b"\r\n\
|
||||
Modes:\r\n\
|
||||
[1] Standby + 8 KB SRAM2 retention\r\n\
|
||||
[2] Standby + full SRAM2 retention\r\n\
|
||||
[3] Standby minimal\r\n\
|
||||
[4] Shutdown\r\n\
|
||||
[5] Stop mode (0-3)\r\n\
|
||||
"
|
||||
).await;
|
||||
|
||||
let mut b = [0u8; 1];
|
||||
let mut b = [0u8; 2];
|
||||
loop {
|
||||
let n = PIPE_HW_RX.read(&mut b).await;
|
||||
if n == 0 {
|
||||
continue;
|
||||
}
|
||||
if n == 0 { continue; }
|
||||
|
||||
match b[0] {
|
||||
b'1' => {
|
||||
let _ = PIPE_HW_TX.write(b"ACK 1: standby 8KB\r\n").await;
|
||||
CMD_CH.send(LowPowerCmd::Standby8k).await;
|
||||
}
|
||||
b'2' => {
|
||||
let _ = PIPE_HW_TX.write(b"ACK 2: standby full\r\n").await;
|
||||
CMD_CH.send(LowPowerCmd::StandbyFull).await;
|
||||
}
|
||||
b'3' => {
|
||||
let _ = PIPE_HW_TX.write(b"ACK 3: standby\r\n").await;
|
||||
CMD_CH.send(LowPowerCmd::Standby).await;
|
||||
}
|
||||
b'4' => {
|
||||
let _ = PIPE_HW_TX.write(b"ACK 4: shutdown\r\n").await;
|
||||
CMD_CH.send(LowPowerCmd::Shutdown).await;
|
||||
}
|
||||
b'1' => CMD_CH.send(LowPowerCmd::Standby8k).await,
|
||||
b'2' => CMD_CH.send(LowPowerCmd::StandbyFull).await,
|
||||
b'3' => CMD_CH.send(LowPowerCmd::Standby).await,
|
||||
b'4' => CMD_CH.send(LowPowerCmd::Shutdown).await,
|
||||
b'5' => {
|
||||
let _ = PIPE_HW_TX.write(b"ACK 5: STOP3 with WFI\r\n").await;
|
||||
CMD_CH.send(LowPowerCmd::Stop3Wfi).await;
|
||||
// Expect 2 digits: e.g. b'5' + '13' = Stop1 WfeNoEventClear
|
||||
let _ = PIPE_HW_TX.write(b"Enter Stop mode number (0-3): ").await;
|
||||
let _ = PIPE_HW_RX.read(&mut b[1..2]).await;
|
||||
let stop_mode = match b[1] {
|
||||
b'1' => StopMode::Stop1,
|
||||
b'2' => StopMode::Stop2,
|
||||
_ => StopMode::Stop3,
|
||||
};
|
||||
|
||||
let _ = PIPE_HW_TX.write(b"Enter entry method (1=WFI,2=WFE,3=WFE no clear): ").await;
|
||||
let n = PIPE_HW_RX.read(&mut b[1..2]).await;
|
||||
if n > 0 {
|
||||
let entry = match b[1] {
|
||||
b'1' => StopEntry::Wfi,
|
||||
b'2' => StopEntry::Wfe,
|
||||
_ => StopEntry::WfeNoEventClear,
|
||||
};
|
||||
CMD_CH.send(LowPowerCmd::StopMode(StopModeConfig { mode: stop_mode, entry })).await;
|
||||
}
|
||||
}
|
||||
b'6' => {
|
||||
let _ = PIPE_HW_TX.write(b"ACK 6: STOP3 with WFE\r\n").await;
|
||||
CMD_CH.send(LowPowerCmd::Stop3Wfe).await;
|
||||
}
|
||||
b'7' => {
|
||||
let _ = PIPE_HW_TX.write(b"ACK 7: STOP3 with WFE (no event clear)\r\n").await;
|
||||
CMD_CH.send(LowPowerCmd::Stop3WfeNoClear).await;
|
||||
}
|
||||
b'\r' | b'\n' | b' ' => {}
|
||||
_ => {
|
||||
let _ = PIPE_HW_TX.write(b"ERR: use 1|2|3|4|5|6|7\r\n").await;
|
||||
let _ = PIPE_HW_TX.write(b"Unknown command\r\n").await;
|
||||
}
|
||||
}
|
||||
yield_now().await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user