From 40c4ca878d7f55f7929682b0c22aaca126ec158b Mon Sep 17 00:00:00 2001 From: "Jes B. Klinke" Date: Fri, 31 Jan 2025 15:25:53 -0800 Subject: [PATCH] [opentitantool] Tolerate 1% deviation either way If doing bitbanging and specifying a pause between segments of the waveform, the delay may not be an exact multiple of the base bitbanging sample frequency, as in this example: ``` opentitantool gpio bitbang --clock 115200Hz -s "0100001001 1ms 0100001001" CN9_6 ``` The code was intended to round off to a whole number of samples, as long as the actual time is within 1% of what was requested (115 sample times in the case above). However the original code had a bug meaning that it would accept only 99%-100% of the requested period, rather than 99%-101%. Change-Id: I79fd67926fedd7fb6dbae27d6314a28bc0b7f2e1 Signed-off-by: Jes B. Klinke --- sw/host/opentitanlib/src/util/bitbang.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw/host/opentitanlib/src/util/bitbang.rs b/sw/host/opentitanlib/src/util/bitbang.rs index 2207f43859248..6cf5124839dae 100644 --- a/sw/host/opentitanlib/src/util/bitbang.rs +++ b/sw/host/opentitanlib/src/util/bitbang.rs @@ -171,7 +171,7 @@ pub fn parse_delay(num: &str, time_unit: &str, clock: Duration) -> Result { let actual_duration = clock.mul(closest_ticks); let ratio = actual_duration.as_secs_f64() / duration; ensure!( - (0.99..=1.00).contains(&ratio), + (0.99..=1.01).contains(&ratio), "Requested delay cannot be approximated to within 1%, try increasing clock frequency", ); Ok(closest_ticks)