[PATCH 2/2] bsps/aarch64/raspberrypi: Add system timer support
Ning Yang
yangn0 at qq.com
Sun Apr 7 14:35:26 UTC 2024
The clock from the ARM timer is derived from the system clock. This clock can change dynamically e.g. if the system goes into reduced power or in low power mode. Thus the clock speed adapts to the overall system performance capabilities. For accurate timing it is recommended to use the system timers.
if BSP_CLOCK_USE_SYSTEMTIMER =1, use the System Timer.
else use the ARM Timer
---
.../aarch64/raspberrypi/include/bsp/bcm2711.h | 28 +++++++++++++++++
bsps/aarch64/raspberrypi/start/bspstartmmu.c | 7 +++++
spec/build/bsps/aarch64/raspberrypi/obj.yml | 2 ++
.../bsps/aarch64/raspberrypi/objclock.yml | 6 +++-
.../aarch64/raspberrypi/objsystemtimer.yml | 30 +++++++++++++++++++
.../aarch64/raspberrypi/optsystemtimer.yml | 24 +++++++++++++++
6 files changed, 96 insertions(+), 1 deletion(-)
create mode 100644 spec/build/bsps/aarch64/raspberrypi/objsystemtimer.yml
create mode 100644 spec/build/bsps/aarch64/raspberrypi/optsystemtimer.yml
diff --git a/bsps/aarch64/raspberrypi/include/bsp/bcm2711.h b/bsps/aarch64/raspberrypi/include/bsp/bcm2711.h
index e6c77fa025..13be411e8f 100644
--- a/bsps/aarch64/raspberrypi/include/bsp/bcm2711.h
+++ b/bsps/aarch64/raspberrypi/include/bsp/bcm2711.h
@@ -91,6 +91,28 @@
#define BCM2711_UART5_BASE (BCM2711_PL011_BASE + 0xa00)
#define BCM2711_UART5_SIZE BCM2711_PL011_DEVICE_SIZE
+/* System Timer */
+/**
+ * NOTE: The GPU uses Compare registers 0 and 2 for
+ * it's own RTOS. 1 and 3 are available for use in
+ * RTEMS.
+ */
+#define BCM2835_GPU_TIMER_BASE (BCM2711_PERIPHERAL_BASE + 0x2000000+ 0x3000)
+#define BCM2835_GPU_TIMER_SIZE 0x1C
+
+#define BCM2835_GPU_TIMER_CS (BCM2835_GPU_TIMER_BASE + 0x00)
+#define BCM2835_GPU_TIMER_CS_M0 0x00000001
+#define BCM2835_GPU_TIMER_CS_M1 0x00000002
+#define BCM2835_GPU_TIMER_CS_M2 0x00000004
+#define BCM2835_GPU_TIMER_CS_M3 0x00000008
+#define BCM2835_GPU_TIMER_CLO (BCM2835_GPU_TIMER_BASE + 0x04)
+#define BCM2835_GPU_TIMER_CHI (BCM2835_GPU_TIMER_BASE + 0x08)
+#define BCM2835_GPU_TIMER_C0 (BCM2835_GPU_TIMER_BASE + 0x0C)
+#define BCM2835_GPU_TIMER_C1 (BCM2835_GPU_TIMER_BASE + 0x10)
+#define BCM2835_GPU_TIMER_C2 (BCM2835_GPU_TIMER_BASE + 0x14)
+#define BCM2835_GPU_TIMER_C3 (BCM2835_GPU_TIMER_BASE + 0x18)
+
+
/* ARM Local */
#define BCM2711_ARM_LOCAL_BASE 0xff800000LL
#define BCM2711_ARM_LOCAL_SIZE 0x800000
@@ -114,4 +136,10 @@
#define BCM2711_IRQ_AUX (BCM2711_IRQ_VC_PERIPHERAL_BASE + 29)
#define BCM2711_IRQ_PL011_UART (BCM2711_IRQ_VC_PERIPHERAL_BASE + 57)
+/* Interrupt Vectors: System Timer */
+#define BCM2835_IRQ_ID_GPU_TIMER_M0 (BCM2711_IRQ_VC_PERIPHERAL_BASE + 0)
+#define BCM2835_IRQ_ID_GPU_TIMER_M1 (BCM2711_IRQ_VC_PERIPHERAL_BASE + 1)
+#define BCM2835_IRQ_ID_GPU_TIMER_M2 (BCM2711_IRQ_VC_PERIPHERAL_BASE + 2)
+#define BCM2835_IRQ_ID_GPU_TIMER_M3 (BCM2711_IRQ_VC_PERIPHERAL_BASE + 3)
+
#endif /* LIBBSP_AARCH64_RASPBERRYPI_BSP_BCM2711_H */
diff --git a/bsps/aarch64/raspberrypi/start/bspstartmmu.c b/bsps/aarch64/raspberrypi/start/bspstartmmu.c
index d5d1381357..4128e76c65 100644
--- a/bsps/aarch64/raspberrypi/start/bspstartmmu.c
+++ b/bsps/aarch64/raspberrypi/start/bspstartmmu.c
@@ -45,6 +45,7 @@
#include "bsp/irq.h"
#include "bsp/mbox.h"
#include "bsp/rpi-gpio.h"
+#include "bsp/bcm2711.h"
#define CONSOLE_DEVICE_MMU_CONFIG(_port, _file, base, size, ...) \
{.begin = base, .end = base + size, .flags = AARCH64_MMU_DEVICE},
@@ -52,6 +53,12 @@
BSP_START_DATA_SECTION static const aarch64_mmu_config_entry
bsp_mmu_config_table[] = {
AARCH64_MMU_DEFAULT_SECTIONS,
+ {
+ /* System Timer */
+ .begin = BCM2835_GPU_TIMER_BASE,
+ .end = BCM2835_GPU_TIMER_BASE + BCM2835_GPU_TIMER_SIZE,
+ .flags = AARCH64_MMU_DEVICE,
+ },
/* clang-format off */
CONSOLE_DEVICES(CONSOLE_DEVICE_MMU_CONFIG)
diff --git a/spec/build/bsps/aarch64/raspberrypi/obj.yml b/spec/build/bsps/aarch64/raspberrypi/obj.yml
index 4a320336b7..07b287e9e7 100644
--- a/spec/build/bsps/aarch64/raspberrypi/obj.yml
+++ b/spec/build/bsps/aarch64/raspberrypi/obj.yml
@@ -31,6 +31,8 @@ links:
uid: objcache
- role: build-dependency
uid: objclock
+ - role: build-dependency
+ uid: objsystemtimer
- role: build-dependency
uid: objconsole
- role: build-dependency
diff --git a/spec/build/bsps/aarch64/raspberrypi/objclock.yml b/spec/build/bsps/aarch64/raspberrypi/objclock.yml
index 550df8029a..b7832236f3 100644
--- a/spec/build/bsps/aarch64/raspberrypi/objclock.yml
+++ b/spec/build/bsps/aarch64/raspberrypi/objclock.yml
@@ -2,9 +2,11 @@ SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2022 Mohd Noor Aman
- Copyright (C) 2023 Utkarsh Verma
+ - Copyright (C) 2024 Ning Yang
type: build
-enabled-by: true
+enabled-by:
+ not: BSP_CLOCK_USE_SYSTEMTIMER
build-type: objects
cflags: []
@@ -24,3 +26,5 @@ links:
uid: ../optgtuseps
- role: build-dependency
uid: objirq
+ - role: build-dependency
+ uid: optsystemtimer
diff --git a/spec/build/bsps/aarch64/raspberrypi/objsystemtimer.yml b/spec/build/bsps/aarch64/raspberrypi/objsystemtimer.yml
new file mode 100644
index 0000000000..5f19ea5619
--- /dev/null
+++ b/spec/build/bsps/aarch64/raspberrypi/objsystemtimer.yml
@@ -0,0 +1,30 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+ - Copyright (C) 2024 Ning Yang
+
+type: build
+enabled-by:
+- BSP_CLOCK_USE_SYSTEMTIMER
+
+build-type: objects
+cflags: []
+cppflags: []
+cxxflags: []
+includes: []
+install: []
+
+source:
+ - bsps/shared/dev/clock/bcm2835-system-timer.c
+ - bsps/shared/dev/cpucounter/cpucounterfrequency.c
+ - bsps/shared/dev/cpucounter/cpucounterread.c
+ - bsps/shared/dev/getentropy/getentropy-cpucounter.c
+
+links:
+ - role: build-dependency
+ uid: ../optgtusevirt
+ - role: build-dependency
+ uid: ../optgtuseps
+ - role: build-dependency
+ uid: objirq
+ - role: build-dependency
+ uid: optsystemtimer
\ No newline at end of file
diff --git a/spec/build/bsps/aarch64/raspberrypi/optsystemtimer.yml b/spec/build/bsps/aarch64/raspberrypi/optsystemtimer.yml
new file mode 100644
index 0000000000..2af58e1fd7
--- /dev/null
+++ b/spec/build/bsps/aarch64/raspberrypi/optsystemtimer.yml
@@ -0,0 +1,24 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+ - Copyright (C) 2023 Ning Yang
+
+type: build
+build-type: option
+
+enabled-by: true
+name: BSP_CLOCK_USE_SYSTEMTIMER
+description: |
+ The clock from the ARM timer is derived from the system clock. This clock can change dynamically e.g. if the system
+ goes into reduced power or in low power mode. Thus the clock speed adapts to the overall system performance
+ capabilities. For accurate timing it is recommended to use the system timers.
+
+actions:
+ - get-boolean: null
+ - define-condition: null
+ - env-enable: null
+default:
+ - enabled-by:
+ - aarch64/raspberrypi4b
+ value: false
+
+links: []
\ No newline at end of file
--
2.34.1
More information about the devel
mailing list