Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenSK
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
koenigl2
OpenSK
Commits
a3885e25
Commit
a3885e25
authored
4 years ago
by
koenigl
Browse files
Options
Downloads
Patches
Plain Diff
port timer patch
parent
afe5bf97
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
patches/libtock-rs/03-timer.patch
+11
-11
11 additions, 11 deletions
patches/libtock-rs/03-timer.patch
with
11 additions
and
11 deletions
patches/libtock-rs/03-timer.patch
+
11
−
11
View file @
a3885e25
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
@@ -1
78
,7 +1
78
,7 @@
impl<'a> Timer<'a> {
@@ -1
36
,7 +1
36
,7 @@
impl<'a> Timer<'a> {
}
}
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, PartialEq)]
pub struct ClockFrequency {
hz: usize,
}
@@ -1
96
,21 +1
96
,53 @@
pub struct ClockValue {
@@ -1
54
,21 +1
54
,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 {
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment