-
-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading 64 bit MMIO #2
Comments
This seems to be an interesting case. For this code: // Since it is MMIO, we must emit two separate 32 bit reads
let mut hi = self.SYSTMR_HI.get();
let mut lo = self.SYSTMR_LO.get();
// We have to repeat if high word changed during read.
if hi != self.SYSTMR_HI.get() {
hi = self.SYSTMR_HI.get();
lo = self.SYSTMR_LO.get();
} I get this clippy hint:
If you blindly follow that hint, like I did without thinking apparently, you lose the first MMIO read of Do I make sense? |
Filed an issue to get feedback from clippy people: rust-lang/rust-clippy#3043 |
Despite the Clippy lint being incorrect, reading the registers twice is not necessary.
|
Ah, nice catch, thanks. Will rectify it. |
Upon further review, I am not sure if your quoted documentation applies to the counter that is handled by the code here. The first source of uncertainty is that the QA sheet you quote is for the BCM2836, which is the 32-bit predecessor of the Raspi 3's 64-bit BCM2837. While we can assume that SoC peripherals stayed the same mostly while the processor was exchanged, we still cannot be 100% sure. The second issue the makes me wonder is that in the QA sheet, Section 3.1.1 talks about a pre-scaler, In the BCM2387 reference I use, A pre-scaler in timing context is only mentioned in All in all, very confusing and I tend to not change the code for now until I find further evidence about the Raspi 3's System Timer having the timer-read-hold functionality. Perhaps looking at Raspi3-related reference code that can be attributed to ARM employees in Linux or any other projects that use this timer will shed some light on it. |
ARMv8 supports reading core timer values architecturally. Maybe try reading CNTPCT_EL0? http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0500d/ch10s03s01.html |
The tutorial shows both ways for learning purposes: CNTPCT et al. registers and the MMIO timer. |
Ah. I didn’t read the code below. Sorry. |
Closing this for now because the failing pattern is not present in the rewrite anymore. |
I think there's an error in reading the 64 bit value in
delays::get_system_timer
. I would expect to read hi, read lo, read hi again and if different (because lo has wrapped since our first read) to read lo again (which can't now wrap because it is near zero).In your code, if lo wraps after the if but before the read of lo, you get a bogus result.
The text was updated successfully, but these errors were encountered: