[PATCH] bsps/aarch64/raspberrypi: Add system timer support

Ning Yang yangn0 at qq.com
Fri Apr 12 14:33:10 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, otherwise use the ARM Timer.
---
 bsps/aarch64/raspberrypi/include/bsp/irq.h    | 15 ++++++---
 .../raspberrypi/include/bsp/raspberrypi.h     | 28 +++++++++--------
 spec/build/bsps/aarch64/grp.yml               |  3 --
 .../aarch64/raspberrypi/bspraspberrypi4.yml   |  7 +++--
 .../bsps/aarch64/raspberrypi/objclock.yml     | 31 +++++++++++++++++++
 .../aarch64/raspberrypi/objsystemtimer.yml    | 23 ++++++++++++++
 .../aarch64/raspberrypi/optsystemtimer.yml    | 24 ++++++++++++++
 7 files changed, 107 insertions(+), 24 deletions(-)
 create mode 100644 spec/build/bsps/aarch64/raspberrypi/objclock.yml
 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/irq.h b/bsps/aarch64/raspberrypi/include/bsp/irq.h
index 1ff6ae80de..f2dd2f6c14 100644
--- a/bsps/aarch64/raspberrypi/include/bsp/irq.h
+++ b/bsps/aarch64/raspberrypi/include/bsp/irq.h
@@ -9,6 +9,7 @@
 /**
  * Copyright (c) 2013 Alan Cudmore
  * Copyright (c) 2022 Mohd Noor Aman
+ * Copyright (c) 2024 Ning Yang
  *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
@@ -24,6 +25,7 @@
 
 #include <rtems.h>
 #include <dev/irq/arm-gic-irq.h>
+#include <rtems/irq.h>
 
 /**
  * @defgroup raspberrypi_interrupt Interrrupt Support
@@ -33,15 +35,18 @@
  * @brief Interrupt support.
  */
 
-#define BCM2835_INTC_TOTAL_IRQ       (64 + 8)
+#define BCM2835_INTC_TOTAL_IRQ       216
 
 #define BCM2835_IRQ_SET1_MIN         0
 #define BCM2835_IRQ_SET2_MIN         32
 
-#define BCM2835_IRQ_ID_GPU_TIMER_M0  0
-#define BCM2835_IRQ_ID_GPU_TIMER_M1  1
-#define BCM2835_IRQ_ID_GPU_TIMER_M2  2
-#define BCM2835_IRQ_ID_GPU_TIMER_M3  3
+#define BCM2711_IRQ_VC_PERIPHERAL_BASE 96
+
+/* 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)
 
 #define BCM2835_IRQ_ID_USB           9
 #define BCM2835_IRQ_ID_AUX           29
diff --git a/bsps/aarch64/raspberrypi/include/bsp/raspberrypi.h b/bsps/aarch64/raspberrypi/include/bsp/raspberrypi.h
index 55dd9ed1e9..3d6a03c715 100644
--- a/bsps/aarch64/raspberrypi/include/bsp/raspberrypi.h
+++ b/bsps/aarch64/raspberrypi/include/bsp/raspberrypi.h
@@ -8,6 +8,7 @@
 
 /*
  *  Copyright (c) 2022 Mohd Noor Aman
+ *  Copyright (c) 2024 Ning Yang
  *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
@@ -44,6 +45,7 @@
 
 #define BCM2711_REG(x)           (*(volatile uint64_t *)(x))
 #define BCM2711_BIT(n)           (1 << (n))
+#define BCM2835_REG(addr)        (*(volatile uint32_t*)(addr))
 
 /** @} */
 
@@ -184,19 +186,19 @@
  *       it's own RTOS. 1 and 3 are available for use in
  *       RTEMS.
  */
-#define BCM2711_GPU_TIMER_BASE       (RPI_PERIPHERAL_BASE + 0x3000)
-
-#define BCM2711_GPU_TIMER_CS         (BCM2711_GPU_TIMER_BASE + 0x00)
-#define BCM2711_GPU_TIMER_CS_M0      0x00000001
-#define BCM2711_GPU_TIMER_CS_M1      0x00000002
-#define BCM2711_GPU_TIMER_CS_M2      0x00000004
-#define BCM2711_GPU_TIMER_CS_M3      0x00000008
-#define BCM2711_GPU_TIMER_CLO        (BCM2711_GPU_TIMER_BASE + 0x04)
-#define BCM2711_GPU_TIMER_CHI        (BCM2711_GPU_TIMER_BASE + 0x08)
-#define BCM2711_GPU_TIMER_C0         (BCM2711_GPU_TIMER_BASE + 0x0C)
-#define BCM2711_GPU_TIMER_C1         (BCM2711_GPU_TIMER_BASE + 0x10)
-#define BCM2711_GPU_TIMER_C2         (BCM2711_GPU_TIMER_BASE + 0x14)
-#define BCM2711_GPU_TIMER_C3         (BCM2711_GPU_TIMER_BASE + 0x18)
+#define BCM2835_GPU_TIMER_BASE       (RPI_PERIPHERAL_BASE + 0x3000)
+
+#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)
 
 /** @} */
 
diff --git a/spec/build/bsps/aarch64/grp.yml b/spec/build/bsps/aarch64/grp.yml
index 9428fb9435..8f40a9952e 100644
--- a/spec/build/bsps/aarch64/grp.yml
+++ b/spec/build/bsps/aarch64/grp.yml
@@ -12,9 +12,6 @@ install:
   source:
   - bsps/aarch64/include/bsp/linker-symbols.h
   - bsps/aarch64/include/bsp/start.h
-- destination: ${BSP_INCLUDEDIR}/dev/clock
-  source:
-  - bsps/include/dev/clock/arm-generic-timer.h
 - destination: ${BSP_INCLUDEDIR}/dev/irq
   source:
   - bsps/aarch64/include/dev/irq/arm-gic-arch.h
diff --git a/spec/build/bsps/aarch64/raspberrypi/bspraspberrypi4.yml b/spec/build/bsps/aarch64/raspberrypi/bspraspberrypi4.yml
index a579c094ba..53677c85d5 100644
--- a/spec/build/bsps/aarch64/raspberrypi/bspraspberrypi4.yml
+++ b/spec/build/bsps/aarch64/raspberrypi/bspraspberrypi4.yml
@@ -19,6 +19,10 @@ install:
   - bsps/aarch64/raspberrypi/include/bsp/irq.h
   - bsps/aarch64/raspberrypi/include/bsp/raspberrypi.h
 links:
+- role: build-dependency
+  uid: objclock
+- role: build-dependency
+  uid: objsystemtimer
 - role: build-dependency
   uid: ../grp
 - role: build-dependency
@@ -50,16 +54,13 @@ source:
 - bsps/aarch64/raspberrypi/start/bspstart.c
 - bsps/aarch64/raspberrypi/start/bspstarthooks.c
 - bsps/aarch64/raspberrypi/start/bspstartmmu.c
-- bsps/aarch64/shared/clock/arm-generic-timer-aarch64.c
 - bsps/aarch64/shared/cache/cache.c
 - bsps/aarch64/shared/mmu/vmsav8-64.c
-- bsps/shared/dev/clock/arm-generic-timer.c
 - bsps/shared/dev/irq/arm-gicv2.c
 - bsps/shared/dev/irq/arm-gicv2-get-attributes.c
 - bsps/shared/dev/serial/console-termios-init.c
 - bsps/shared/dev/serial/console-termios.c
 - bsps/shared/dev/serial/arm-pl011.c
-- bsps/shared/dev/getentropy/getentropy-cpucounter.c
 - bsps/shared/dev/btimer/btimer-cpucounter.c
 - bsps/shared/irq/irq-default-handler.c
 - bsps/shared/start/bspfatal-default.c
diff --git a/spec/build/bsps/aarch64/raspberrypi/objclock.yml b/spec/build/bsps/aarch64/raspberrypi/objclock.yml
new file mode 100644
index 0000000000..c4a8227bc9
--- /dev/null
+++ b/spec/build/bsps/aarch64/raspberrypi/objclock.yml
@@ -0,0 +1,31 @@
+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:
+  not: BSP_CLOCK_USE_SYSTEMTIMER
+
+build-type: objects
+cflags: []
+cppflags: []
+cxxflags: []
+includes: []
+install: 
+- destination: ${BSP_INCLUDEDIR}/dev/clock
+  source:
+  - bsps/include/dev/clock/arm-generic-timer.h
+
+source:
+  - bsps/aarch64/shared/clock/arm-generic-timer-aarch64.c
+  - bsps/shared/dev/clock/arm-generic-timer.c
+
+links:
+  - role: build-dependency
+    uid: ../optgtusevirt
+  - role: build-dependency
+    uid: ../optgtuseps
+  - role: build-dependency
+    uid: optsystemtimer
\ No newline at end of file
diff --git a/spec/build/bsps/aarch64/raspberrypi/objsystemtimer.yml b/spec/build/bsps/aarch64/raspberrypi/objsystemtimer.yml
new file mode 100644
index 0000000000..8a91a0555a
--- /dev/null
+++ b/spec/build/bsps/aarch64/raspberrypi/objsystemtimer.yml
@@ -0,0 +1,23 @@
+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
+
+links:
+  - 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..1cceebf22b
--- /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) 2024 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