Skip to content

Commit

Permalink
[opentitantool] Tolerate 1% deviation either way
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jesultra committed Feb 14, 2025
1 parent ab6d92c commit 40c4ca8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sw/host/opentitanlib/src/util/bitbang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn parse_delay(num: &str, time_unit: &str, clock: Duration) -> Result<u32> {
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)
Expand Down

0 comments on commit 40c4ca8

Please sign in to comment.