diff --git a/patches/libtock-rs/03-timer.patch b/patches/libtock-rs/03-timer.patch index 7b8a5d9780eada72aa9918a70d68dc9899d9118a..f986f9eff094ae39b0def2ed93ad02c59c3a68c3 100644 --- a/patches/libtock-rs/03-timer.patch +++ b/patches/libtock-rs/03-timer.patch @@ -1,19 +1,19 @@ diff --git a/src/timer.rs b/src/timer.rs -index ae60b07..2e7d544 100644 +index 946c6e5..90d44c9 100644 --- a/src/timer.rs +++ b/src/timer.rs -@@ -178,7 +178,7 @@ impl<'a> Timer<'a> { +@@ -136,7 +136,7 @@ impl<'a> Timer<'a> { } } - + -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq)] pub struct ClockFrequency { hz: usize, } -@@ -196,21 +196,53 @@ pub struct ClockValue { +@@ -154,21 +154,53 @@ pub struct ClockValue { } - + impl ClockValue { + pub const fn new(num_ticks: isize, clock_hz: usize) -> ClockValue { + ClockValue { @@ -22,10 +22,10 @@ index ae60b07..2e7d544 100644 + } + } + - pub fn num_ticks(&self) -> isize { + pub fn num_ticks(self) -> isize { self.num_ticks } - + + // Computes (value * factor) / divisor, even when value * factor >= isize::MAX. + fn scale_int(value: isize, factor: isize, divisor: isize) -> isize { + // As long as isize is not i64, this should be fine. If not, this is an alternative: @@ -33,7 +33,7 @@ index ae60b07..2e7d544 100644 + ((value as i64 * factor as i64) / divisor as i64) as isize + } + - pub fn ms(&self) -> isize { + pub fn ms(self) -> isize { - if self.num_ticks.abs() < isize::MAX / 1000 { - (1000 * self.num_ticks) / self.clock_frequency.hz() as isize - } else { @@ -41,8 +41,8 @@ index ae60b07..2e7d544 100644 - } + ClockValue::scale_int(self.num_ticks, 1000, self.clock_frequency.hz() as isize) } - - pub fn ms_f64(&self) -> f64 { + + pub fn ms_f64(self) -> f64 { 1000.0 * (self.num_ticks as f64) / (self.clock_frequency.hz() as f64) } + @@ -68,5 +68,5 @@ index ae60b07..2e7d544 100644 + } + } } - + pub struct Alarm {