|
|
|
@ -175,7 +175,7 @@ diff -uNr 07_uart_chainloader/src/_arch/aarch64/cpu.rs 08_timestamps/src/_arch/a
|
|
|
|
|
diff -uNr 07_uart_chainloader/src/_arch/aarch64/time.rs 08_timestamps/src/_arch/aarch64/time.rs
|
|
|
|
|
--- 07_uart_chainloader/src/_arch/aarch64/time.rs
|
|
|
|
|
+++ 08_timestamps/src/_arch/aarch64/time.rs
|
|
|
|
|
@@ -0,0 +1,105 @@
|
|
|
|
|
@@ -0,0 +1,118 @@
|
|
|
|
|
+// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
|
+//
|
|
|
|
|
+// Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
|
|
|
|
@ -191,7 +191,7 @@ diff -uNr 07_uart_chainloader/src/_arch/aarch64/time.rs 08_timestamps/src/_arch/
|
|
|
|
|
+
|
|
|
|
|
+use crate::{time, warn};
|
|
|
|
|
+use core::time::Duration;
|
|
|
|
|
+use cortex_a::regs::*;
|
|
|
|
|
+use cortex_a::{barrier, regs::*};
|
|
|
|
|
+
|
|
|
|
|
+//--------------------------------------------------------------------------------------------------
|
|
|
|
|
+// Private Definitions
|
|
|
|
@ -209,6 +209,19 @@ diff -uNr 07_uart_chainloader/src/_arch/aarch64/time.rs 08_timestamps/src/_arch/
|
|
|
|
|
+static TIME_MANAGER: GenericTimer = GenericTimer;
|
|
|
|
|
+
|
|
|
|
|
+//--------------------------------------------------------------------------------------------------
|
|
|
|
|
+// Private Code
|
|
|
|
|
+//--------------------------------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+impl GenericTimer {
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
|
+ fn read_cntpct(&self) -> u64 {
|
|
|
|
|
+ // Prevent that the counter is read ahead of time due to out-of-order execution.
|
|
|
|
|
+ unsafe { barrier::isb(barrier::SY) };
|
|
|
|
|
+ CNTPCT_EL0.get()
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+//--------------------------------------------------------------------------------------------------
|
|
|
|
|
+// Public Code
|
|
|
|
|
+//--------------------------------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
@ -227,8 +240,8 @@ diff -uNr 07_uart_chainloader/src/_arch/aarch64/time.rs 08_timestamps/src/_arch/
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn uptime(&self) -> Duration {
|
|
|
|
|
+ let current_count: u64 = self.read_cntpct() * NS_PER_S;
|
|
|
|
|
+ let frq: u64 = CNTFRQ_EL0.get() as u64;
|
|
|
|
|
+ let current_count: u64 = CNTPCT_EL0.get() * NS_PER_S;
|
|
|
|
|
+
|
|
|
|
|
+ Duration::from_nanos(current_count / frq)
|
|
|
|
|
+ }
|
|
|
|
|