From 1a42e23fb4916401032d01bcd0079ed5589bf11a Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 28 Jan 2019 18:39:16 +0800 Subject: [PATCH] jesd204sync: print DDMTD SYSREF final alignment delta --- artiq/firmware/libboard_artiq/jesd204sync.rs | 21 +++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/artiq/firmware/libboard_artiq/jesd204sync.rs b/artiq/firmware/libboard_artiq/jesd204sync.rs index 3959e7ccd..79659b736 100644 --- a/artiq/firmware/libboard_artiq/jesd204sync.rs +++ b/artiq/firmware/libboard_artiq/jesd204sync.rs @@ -172,18 +172,15 @@ fn max_phase_deviation(average: i32, phases: &[i32]) -> i32 { return ret; } -fn reach_sysref_ddmtd_target(target: i32, tolerance: i32) -> Result<(), &'static str> { - let mut phase = measure_ddmdt_phase(); - let mut nslips = 0; - while (phase - target).abs() > tolerance { - hmc7043::sysref_slip(); - nslips += 1; - if nslips > 1024 { - return Err("failed to reach SYSREF DDMTD phase target"); +fn reach_sysref_ddmtd_target(target: i32, tolerance: i32) -> Result { + for _ in 0..1024 { + let delta = (measure_ddmdt_phase() - target + DDMTD_N) % DDMTD_N; + if delta <= tolerance { + return Ok(delta) } - phase = measure_ddmdt_phase(); + hmc7043::sysref_slip(); } - Ok(()) + Err("failed to reach SYSREF DDMTD phase target") } fn calibrate_sysref_target(rising_average: i32, falling_average: i32) -> Result { @@ -275,11 +272,11 @@ pub fn sysref_auto_rtio_align() -> Result<(), &'static str> { }; info!("aligning SYSREF with RTIO clock..."); - reach_sysref_ddmtd_target(target_phase, 3)?; + let delta = reach_sysref_ddmtd_target(target_phase, 3)?; if sysref_sh_error() { return Err("SYSREF does not meet S/H timing at DDMTD phase target"); } - info!(" ...done"); + info!(" ...done, delta={}", delta); sysref_rtio_align()?;