@@ -302,6 +302,15 @@ diff -uNr 06_uart_chainloader/src/_arch/aarch64/time.rs 07_timestamps/src/_arch/
302
302
+ // Private Code
303
303
+ //--------------------------------------------------------------------------------------------------
304
304
+
305
+ + fn arch_timer_counter_frequency() -> NonZeroU32 {
306
+ + // Read volatile is needed here to prevent the compiler from optimizing
307
+ + // ARCH_TIMER_COUNTER_FREQUENCY away.
308
+ + //
309
+ + // This is safe, because all the safety requirements as stated in read_volatile()'s
310
+ + // documentation are fulfilled.
311
+ + unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }
312
+ + }
313
+ +
305
314
+ impl GenericTimerCounterValue {
306
315
+ pub const MAX: Self = GenericTimerCounterValue(u64::MAX);
307
316
+ }
@@ -320,13 +329,7 @@ diff -uNr 06_uart_chainloader/src/_arch/aarch64/time.rs 07_timestamps/src/_arch/
320
329
+ return Duration::ZERO;
321
330
+ }
322
331
+
323
- + // Read volatile is needed here to prevent the compiler from optimizing
324
- + // ARCH_TIMER_COUNTER_FREQUENCY away.
325
- + //
326
- + // This is safe, because all the safety requirements as stated in read_volatile()'s
327
- + // documentation are fulfilled.
328
- + let frequency: NonZeroU64 =
329
- + unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }.into();
332
+ + let frequency: NonZeroU64 = arch_timer_counter_frequency().into();
330
333
+
331
334
+ // Div<NonZeroU64> implementation for u64 cannot panic.
332
335
+ let secs = counter_value.0.div(frequency);
@@ -361,10 +364,7 @@ diff -uNr 06_uart_chainloader/src/_arch/aarch64/time.rs 07_timestamps/src/_arch/
361
364
+ return Err("Conversion error. Duration too big");
362
365
+ }
363
366
+
364
- + // This is safe, because all the safety requirements as stated in read_volatile()'s
365
- + // documentation are fulfilled.
366
- + let frequency: u128 =
367
- + unsafe { u32::from(core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY)) as u128 };
367
+ + let frequency: u128 = u32::from(arch_timer_counter_frequency()) as u128;
368
368
+ let duration: u128 = duration.as_nanos();
369
369
+
370
370
+ // This is safe, because frequency can never be greater than u32::MAX, and
0 commit comments