From ccd6a1faf97cc8daa64a9a251d72a2108bb25e97 Mon Sep 17 00:00:00 2001 From: occheung Date: Wed, 12 Aug 2020 12:26:15 +0800 Subject: [PATCH] cfg_reg: add status getter --- .cargo/config | 2 +- migen/fpga_config.py | 2 +- src/config_register.rs | 27 ++++++++++++++++++++++++++- src/main.rs | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.cargo/config b/.cargo/config index 6c91033..c0ce242 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,5 +1,5 @@ [target.thumbv7em-none-eabihf] -runner = "gdb -q -x gdb_config/debug.gdb" +runner = "gdb -q -x gdb_config/fpga_config.gdb" rustflags = [ "-C", "link-arg=-Tlink.x", ] diff --git a/migen/fpga_config.py b/migen/fpga_config.py index c48f7cf..0f613a2 100644 --- a/migen/fpga_config.py +++ b/migen/fpga_config.py @@ -29,7 +29,7 @@ class UrukulConnector(Module): ] # Debug purposes: Tie EEM MISO to EEM MOSI - self.comb += eem.p[2].eq(eem.n[1]) + self.comb += eem.p[2].eq(eem.p[1]) if __name__ == "__main__": diff --git a/src/config_register.rs b/src/config_register.rs index e987583..5b40b3e 100644 --- a/src/config_register.rs +++ b/src/config_register.rs @@ -82,17 +82,29 @@ where } } + /* + * Set configuration bits according to data field + * Return status + */ fn set_all_configurations(&mut self) -> Result> { match self.spi.transfer(&mut [ ((self.data & 0x00FF0000) >> 16) as u8, ((self.data & 0x0000FF00) >> 8) as u8, ((self.data & 0x000000FF) >> 0) as u8, ]).map_err(Error::SPI) { - Ok(arr) => Ok(self.data), + Ok(arr) => Ok( + ((arr[0] as u32) << 16) | + ((arr[1] as u32) << 8) | + arr[2] as u32 + ), Err(e) => Err(e), } } + /* + * Set configuration bits according to supplied configs + * Return status + */ pub fn set_configurations(&mut self, configs: &mut[(CFGMask, u32)]) -> Result> { for config in configs.into_iter() { // Erase the bits in the configuration region @@ -107,9 +119,22 @@ where self.set_all_configurations() } + /* + * Return selected configuration field + */ pub fn get_configuration(&mut self, config_type: CFGMask) -> u8 { ((self.data & config_type.get_bitmask()) >> config_type.get_shift()) as u8 } + + /* + * Return status + */ + pub fn get_status(&mut self, status_type: CFGMask) -> Result> { + match self.set_all_configurations() { + Ok(val) => Ok(((val & status_type.get_bitmask()) >> status_type.get_shift()) as u8), + Err(e) => Err(e), + } + } } impl Transfer for ConfigRegister diff --git a/src/main.rs b/src/main.rs index 3581a00..26c24ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ fn main() -> ! { let mut config = ConfigRegister::new(parts.spi1); // Target configuration: 0x000FF1CE - hprintln!("{}", config.set_configurations(&mut [ + hprintln!("{:#06X}", config.set_configurations(&mut [ (CFGMask::RF_SW, 0xE), (CFGMask::LED, 0xC), (CFGMask::PROFILE, 0x1),