// SPDX-License-Identifier: MIT //! Power-down modes: SLEEP, standby, and the module-stop bits (SBYCR). //! //! sh2-python's `power.py`. HM chapter 14 (U18). ``SLEEP`` stops the CPU until an //! interrupt or a reset; with SBYCR.SBY = 1 it enters standby instead, which stops the //! clock and the modules until NMI or a reset. SBYCR.HIZ keeps pins high-impedance in //! standby; MSTP4-MSTP0 halt the clock of the DMAC, the multiplier, the DIVU, the FRT //! and the SCI (HM 14.2.1). //! //! Rungs 0-2 implement sleep (the chip's ``sleeping`` state, left by an accepted //! interrupt) and hold SBYCR; standby and module stop are a later rung's work and are //! treated as sleep / ignored for now. use crate::module::{reg, value_of, ModuleState, Register}; pub const REGISTERS: [Register; 1] = [reg(0xFFFFFE91, "SBYCR", 8, Some(0x00))]; #[derive(Clone, Debug, Default)] pub struct Power { pub sbycr: u32, } impl Power { pub fn new() -> Power { Power { sbycr: 0 } } pub fn reset(&mut self) { self.sbycr = 0; } pub fn read8(&mut self, address: u32) -> u32 { if address == 0xFFFFFE91 { self.sbycr } else { 0 } } pub fn write8(&mut self, address: u32, value: u32) { if address == 0xFFFFFE91 { self.sbycr = value & 0xDF; // bit 5 is reserved (HM 14.2.1) } } pub fn state(&self) -> ModuleState { vec![("SBYCR", self.sbycr as i64)] } pub fn load_state(&mut self, values: &ModuleState) { self.sbycr = value_of(values, "SBYCR") as u32; } }