From a3885e257736e07f18d54dd8f8e278549a82d375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20K=C3=B6nig?= <leonard.koenig@fu-berlin.de> Date: Thu, 11 Jun 2020 23:29:31 +0200 Subject: [PATCH] port timer patch --- patches/libtock-rs/03-timer.patch | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/patches/libtock-rs/03-timer.patch b/patches/libtock-rs/03-timer.patch index 7b8a5d9..f986f9e 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 { -- GitLab