sayma: properly determine SYSREF coarse calibration target

This commit is contained in:
Sebastien Bourdeauducq 2019-01-27 16:00:36 +08:00
parent 214394e3b0
commit 8254560577
1 changed files with 6 additions and 1 deletions

View File

@ -135,7 +135,12 @@ fn reach_sysref_ddmtd_target(target: i32, tolerance: i32) -> Result<(), &'static
}
fn calibrate_sysref_target(rising_average: i32, falling_average: i32) -> Result<i32, &'static str> {
let coarse_target = (falling_average - 16 + DDMTD_N) % DDMTD_N; // HACK
let coarse_target =
if rising_average < falling_average {
(rising_average + falling_average)/2
} else {
((falling_average - (DDMTD_N - rising_average))/2 + DDMTD_N) % DDMTD_N
};
info!("SYSREF calibration coarse target: {}", coarse_target);
reach_sysref_ddmtd_target(coarse_target, 2)?;
let target = measure_ddmdt_phase();