From 2f08161251020af20db7939f1613506074ffd31d Mon Sep 17 00:00:00 2001 From: Jean THOMAS Date: Thu, 30 May 2024 09:30:22 +0200 Subject: [PATCH] devcon: Log reset/enable events --- Cargo.lock | 20 +++++++ clicky-core/Cargo.toml | 5 ++ clicky-core/src/devices/platform/pp/devcon.rs | 57 ++++++++++++++++++- 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6136454..9a6b525 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,6 +212,8 @@ dependencies = [ "pin-utils", "relativity", "static_assertions", + "strum", + "strum_macros", "thiserror", ] @@ -1071,6 +1073,24 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "strum" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "530efb820d53b712f4e347916c5e7ed20deb76a4f0457943b3182fb889b06d2c" + +[[package]] +name = "strum_macros" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6e163a520367c465f59e0a61a23cfae3b10b6546d78b6f672a382be79f7110" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "syn" version = "1.0.109" diff --git a/clicky-core/Cargo.toml b/clicky-core/Cargo.toml index 0778b71..d92f07e 100644 --- a/clicky-core/Cargo.toml +++ b/clicky-core/Cargo.toml @@ -32,6 +32,11 @@ async-channel = "1.4" blocking = "0.5" futures-executor = { version = "0.3", features = ["thread-pool"] } # TEMP pin-utils = "0.1" + +# enum +strum = "0.17.1" +strum_macros = "0.17.1" + [dependencies.futures] version = "0.3" default-features = false diff --git a/clicky-core/src/devices/platform/pp/devcon.rs b/clicky-core/src/devices/platform/pp/devcon.rs index 981c051..ada4677 100644 --- a/clicky-core/src/devices/platform/pp/devcon.rs +++ b/clicky-core/src/devices/platform/pp/devcon.rs @@ -1,4 +1,23 @@ use crate::devices::prelude::*; +use strum::IntoEnumIterator; +use strum_macros::EnumIter; + +#[derive(Debug, Copy, Clone, EnumIter)] +pub enum DevIdentifier { + EXTCLOCKS = 1, + SYS = 2, + USB0 = 3, + SER0 = 6, + SER1 = 7, + I2S = 11, + I2C = 12, + ATA = 14, + OPTO = 16, + USB1 = 22, + FIREWIRE = 23, + IDE0 = 25, + LCD = 26, +} /// PP5020 Device Controller. #[derive(Debug)] @@ -26,6 +45,8 @@ impl DevCon { mystery: [0; 1], } } + + } impl Device for DevCon { @@ -73,9 +94,41 @@ impl Memory for DevCon { fn w32(&mut self, offset: u32, val: u32) -> MemResult<()> { match offset { - 0x04 => Err(StubWrite(Error, self.reset[0] = val)), + 0x04 => Err(StubWrite(Error, { + let mut rising_edges = !self.reset[0] & val; + for device in DevIdentifier::iter() { + if rising_edges.get_bit(device as usize) { + println!("{:?} got reset", device); + rising_edges.set_bit(device as usize, false); + } + } + if rising_edges != 0 { + for i in 0..31 { + if rising_edges.get_bit(i) { + println!("Unknown device being reset (bit pos {})", i); + } + } + } + self.reset[0] = val; + })), 0x08 => Err(StubWrite(Error, self.reset[1] = val)), - 0x0c => Err(StubWrite(Info, self.enable[0] = val)), + 0x0c => Err(StubWrite(Info, { + let mut rising_edges = !self.enable[0] & val; + for device in DevIdentifier::iter() { + if rising_edges.get_bit(device as usize) { + println!("{:?} got enabled", device); + rising_edges.set_bit(device as usize, false); + } + } + if rising_edges != 0 { + for i in 0..31 { + if rising_edges.get_bit(i) { + println!("Unknown device being enabled (bit pos {})", i); + } + } + } + self.enable[0] = val; + })), 0x10 => Err(StubWrite(Info, self.enable[1] = val)), 0x20 => Err(StubWrite(Trace, self.clock_source = val)), 0x34 => Err(StubWrite(Trace, self.pll_control = val)),