Skip to content

Commit 969704d

Browse files
committed
Use correct sequence of MMIO timer reads
As discussed in #2
1 parent 0bd363f commit 969704d

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

09_delays/kernel8.img

16 Bytes
Binary file not shown.

09_delays/src/delays.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ impl SysTmr {
6969
pub fn get_system_timer(&self) -> u64 {
7070
// Since it is MMIO, we must emit two separate 32 bit reads
7171
let mut hi = self.SYSTMR_HI.get();
72+
let mut lo = self.SYSTMR_LO.get();
7273

73-
// We have to repeat if high word changed during read. It
74-
// looks a bit odd, but clippy insists that this is idiomatic
75-
// Rust!
76-
let lo = if hi != self.SYSTMR_HI.get() {
74+
// We have to repeat if high word changed during read. This
75+
// will emit a clippy warning that needs be ignored, or you
76+
// lose an MMIO read.
77+
if hi != self.SYSTMR_HI.get() {
7778
hi = self.SYSTMR_HI.get();
78-
self.SYSTMR_LO.get()
79-
} else {
80-
self.SYSTMR_LO.get()
81-
};
79+
lo = self.SYSTMR_LO.get();
80+
}
8281

8382
// Compose long int value
8483
(u64::from(hi) << 32) | u64::from(lo)

0A_power/src/delays.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ impl SysTmr {
6969
pub fn get_system_timer(&self) -> u64 {
7070
// Since it is MMIO, we must emit two separate 32 bit reads
7171
let mut hi = self.SYSTMR_HI.get();
72+
let mut lo = self.SYSTMR_LO.get();
7273

73-
// We have to repeat if high word changed during read. It
74-
// looks a bit odd, but clippy insists that this is idiomatic
75-
// Rust!
76-
let lo = if hi != self.SYSTMR_HI.get() {
74+
// We have to repeat if high word changed during read. This
75+
// will emit a clippy warning that needs be ignored, or you
76+
// lose an MMIO read.
77+
if hi != self.SYSTMR_HI.get() {
7778
hi = self.SYSTMR_HI.get();
78-
self.SYSTMR_LO.get()
79-
} else {
80-
self.SYSTMR_LO.get()
81-
};
79+
lo = self.SYSTMR_LO.get();
80+
}
8281

8382
// Compose long int value
8483
(u64::from(hi) << 32) | u64::from(lo)

0 commit comments

Comments
 (0)