Skip to content

Commit

Permalink
Fix overflow in timestamp calculation (esp-rs#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani authored and bjoernQ committed May 23, 2024
1 parent 8a580cd commit b95b23c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion esp-wifi/src/timer/xtensa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ pub fn get_systimer_count() -> u64 {
overflow = TIMER_OVERFLOWS.load(Ordering::Relaxed);
}

(((overflow as u64) << 32) + counter_after as u64) * 40_000_000 / 240_000_000
// We have to precompute the divider to avoid overflow when multiplying.
const DIVIDER: u64 = 240_000_000 / TICKS_PER_SECOND;
(((overflow as u64) << 32) + counter_after as u64) / DIVIDER
}

pub fn setup_timer(mut timer1: TimeBase) {
Expand Down

0 comments on commit b95b23c

Please sign in to comment.