forked from M-Labs/humpback-dds
cfg_reg: add status getter
This commit is contained in:
parent
8f4a97c97e
commit
ccd6a1faf9
@ -1,5 +1,5 @@
|
|||||||
[target.thumbv7em-none-eabihf]
|
[target.thumbv7em-none-eabihf]
|
||||||
runner = "gdb -q -x gdb_config/debug.gdb"
|
runner = "gdb -q -x gdb_config/fpga_config.gdb"
|
||||||
rustflags = [
|
rustflags = [
|
||||||
"-C", "link-arg=-Tlink.x",
|
"-C", "link-arg=-Tlink.x",
|
||||||
]
|
]
|
||||||
|
@ -29,7 +29,7 @@ class UrukulConnector(Module):
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Debug purposes: Tie EEM MISO to EEM MOSI
|
# 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__":
|
if __name__ == "__main__":
|
||||||
|
@ -82,17 +82,29 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set configuration bits according to data field
|
||||||
|
* Return status
|
||||||
|
*/
|
||||||
fn set_all_configurations(&mut self) -> Result<u32, Error<E>> {
|
fn set_all_configurations(&mut self) -> Result<u32, Error<E>> {
|
||||||
match self.spi.transfer(&mut [
|
match self.spi.transfer(&mut [
|
||||||
((self.data & 0x00FF0000) >> 16) as u8,
|
((self.data & 0x00FF0000) >> 16) as u8,
|
||||||
((self.data & 0x0000FF00) >> 8) as u8,
|
((self.data & 0x0000FF00) >> 8) as u8,
|
||||||
((self.data & 0x000000FF) >> 0) as u8,
|
((self.data & 0x000000FF) >> 0) as u8,
|
||||||
]).map_err(Error::SPI) {
|
]).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),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set configuration bits according to supplied configs
|
||||||
|
* Return status
|
||||||
|
*/
|
||||||
pub fn set_configurations(&mut self, configs: &mut[(CFGMask, u32)]) -> Result<u32, Error<E>> {
|
pub fn set_configurations(&mut self, configs: &mut[(CFGMask, u32)]) -> Result<u32, Error<E>> {
|
||||||
for config in configs.into_iter() {
|
for config in configs.into_iter() {
|
||||||
// Erase the bits in the configuration region
|
// Erase the bits in the configuration region
|
||||||
@ -107,9 +119,22 @@ where
|
|||||||
self.set_all_configurations()
|
self.set_all_configurations()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return selected configuration field
|
||||||
|
*/
|
||||||
pub fn get_configuration(&mut self, config_type: CFGMask) -> u8 {
|
pub fn get_configuration(&mut self, config_type: CFGMask) -> u8 {
|
||||||
((self.data & config_type.get_bitmask()) >> config_type.get_shift()) as 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<u8, Error<E>> {
|
||||||
|
match self.set_all_configurations() {
|
||||||
|
Ok(val) => Ok(((val & status_type.get_bitmask()) >> status_type.get_shift()) as u8),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SPI, E> Transfer<u8> for ConfigRegister<SPI>
|
impl<SPI, E> Transfer<u8> for ConfigRegister<SPI>
|
||||||
|
@ -96,7 +96,7 @@ fn main() -> ! {
|
|||||||
|
|
||||||
let mut config = ConfigRegister::new(parts.spi1);
|
let mut config = ConfigRegister::new(parts.spi1);
|
||||||
// Target configuration: 0x000FF1CE
|
// Target configuration: 0x000FF1CE
|
||||||
hprintln!("{}", config.set_configurations(&mut [
|
hprintln!("{:#06X}", config.set_configurations(&mut [
|
||||||
(CFGMask::RF_SW, 0xE),
|
(CFGMask::RF_SW, 0xE),
|
||||||
(CFGMask::LED, 0xC),
|
(CFGMask::LED, 0xC),
|
||||||
(CFGMask::PROFILE, 0x1),
|
(CFGMask::PROFILE, 0x1),
|
||||||
|
Loading…
Reference in New Issue
Block a user