forked from M-Labs/artiq
1
0
Fork 0

hmc7043: test GPO before using

Based on code by David.
This commit is contained in:
Sebastien Bourdeauducq 2018-07-12 11:30:24 +08:00
parent 141fcaaa8a
commit 773240bef4
1 changed files with 22 additions and 1 deletions

View File

@ -265,6 +265,10 @@ pub mod hmc7043 {
write(0x1, 0x48); // mute all outputs write(0x1, 0x48); // mute all outputs
} }
const GPO_MUX_CLK_OUT_PHASE: u8 = 3;
const GPO_MUX_FORCE1: u8 = 10;
const GPO_MUX_FORCE0: u8 = 11;
/* Read an HMC7043 internal status bit through the GPO interface. /* Read an HMC7043 internal status bit through the GPO interface.
* This method is required to work around bugs in the register interface. * This method is required to work around bugs in the register interface.
*/ */
@ -336,8 +340,24 @@ pub mod hmc7043 {
info!(" ...done"); info!(" ...done");
} }
pub fn test_gpo() -> Result<(), &'static str> {
info!("testing GPO...");
for trial in 0..10 {
if !gpo_indirect_read(GPO_MUX_FORCE1) {
info!(" ...failed. GPO I/O did not go high (#{})", trial + 1);
return Err("GPO is not functioning");
}
if gpo_indirect_read(GPO_MUX_FORCE0) {
info!(" ...failed. GPO I/O did not return low (#{})", trial + 1);
return Err("GPO is not functioning");
}
}
info!(" ...passed");
Ok(())
}
pub fn check_phased() -> Result<(), &'static str> { pub fn check_phased() -> Result<(), &'static str> {
if !gpo_indirect_read(3) { if !gpo_indirect_read(GPO_MUX_CLK_OUT_PHASE) {
return Err("GPO reported phases did not align"); return Err("GPO reported phases did not align");
} }
// Should be the same as the GPO read // Should be the same as the GPO read
@ -463,6 +483,7 @@ pub fn init() -> Result<(), &'static str> {
hmc7043::enable(); hmc7043::enable();
hmc7043::detect()?; hmc7043::detect()?;
hmc7043::init(); hmc7043::init();
hmc7043::test_gpo()?;
hmc7043::check_phased()?; hmc7043::check_phased()?;
Ok(()) Ok(())