<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr"><div>Hi Ning,</div><div></div><div>This patch set creates a duplication of the rpi3 system clock driver.</div><div><br></div><div>Instead, I'd suggest a different organization of the patch set:</div><div>Patch 1: Move the existing implementation to shared space and adjust BSPs that use it as necessary.</div><div>Patch 2: Add support for the now-shared clock driver to the rpi4 BSP.</div><div><br></div><div>Kinsey<br></div></div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Apr 7, 2024 at 9:35 AM Ning Yang <<a href="mailto:yangn0@qq.com" target="_blank">yangn0@qq.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This patch ports the bcm2835 system timer driver in the arm/raspberrypi directory to the shared directory.<br>
<br>
Made some changes in the include section to adapt to rpi4 BSP.<br>
---<br>
bsps/shared/dev/clock/bcm2835-system-timer.c | 114 +++++++++++++++++++<br>
1 file changed, 114 insertions(+)<br>
create mode 100644 bsps/shared/dev/clock/bcm2835-system-timer.c<br>
<br>
diff --git a/bsps/shared/dev/clock/bcm2835-system-timer.c b/bsps/shared/dev/clock/bcm2835-system-timer.c<br>
new file mode 100644<br>
index 0000000000..f59c9e5424<br>
--- /dev/null<br>
+++ b/bsps/shared/dev/clock/bcm2835-system-timer.c<br>
@@ -0,0 +1,114 @@<br>
+/**<br>
+ * @file<br>
+ *<br>
+ * @ingroup RTEMSDriverClockImpl<br>
+ *<br>
+ * @brief This source file contains the implementation of the BCM2835 Clock<br>
+ * Driver.<br>
+ */<br>
+<br>
+/*<br>
+ * Copyright (c) 2013 Alan Cudmore<br>
+ * Copyright (c) 2016 Pavel Pisa<br>
+ *<br>
+ * The license and distribution terms for this file may be<br>
+ * found in the file LICENSE in this distribution or at<br>
+ *<br>
+ * <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/LICENSE</a><br>
+ *<br>
+*/<br>
+<br>
+#include <rtems.h><br>
+#include <bsp.h><br>
+#include <bsp/irq.h><br>
+#include <bsp/irq-generic.h><br>
+<br>
+#if RTEMS_BSP == raspberrypi4b<br>
+#include <bsp/bcm2711.h><br>
+#else<br>
+#include <bsp/raspberrypi.h><br>
+#endif /* RTEMS_BSP */<br>
+<br>
+#include <rtems/timecounter.h><br>
+<br>
+#define BCM2835_REG(addr) *(volatile uint32_t*)(addr)<br>
+<br>
+/* This is defined in ../../../shared/dev/clock/clockimpl.h */<br>
+void Clock_isr(rtems_irq_hdl_param arg);<br>
+<br>
+static struct timecounter raspberrypi_tc;<br>
+<br>
+static uint32_t raspberrypi_clock_get_timecount(struct timecounter *tc)<br>
+{<br>
+ return BCM2835_REG(BCM2835_GPU_TIMER_CLO);<br>
+}<br>
+<br>
+static void raspberrypi_clock_at_tick(void)<br>
+{<br>
+ uint32_t act_val;<br>
+ uint32_t next_cmp = BCM2835_REG(BCM2835_GPU_TIMER_C3);<br>
+ next_cmp += rtems_configuration_get_microseconds_per_tick();<br>
+ BCM2835_REG(BCM2835_GPU_TIMER_C3) = next_cmp;<br>
+ act_val = BCM2835_REG(BCM2835_GPU_TIMER_CLO);<br>
+<br>
+ /*<br>
+ * Clear interrupt only if there is time left to the next tick.<br>
+ * If time of the next tick has already passed then interrupt<br>
+ * request stays active and fires immediately after current tick<br>
+ * processing is finished.<br>
+ */<br>
+ if ((int32_t)(next_cmp - act_val) > 0)<br>
+ BCM2835_REG(BCM2835_GPU_TIMER_CS) = BCM2835_GPU_TIMER_CS_M3;<br>
+}<br>
+<br>
+static void raspberrypi_clock_handler_install_isr(<br>
+ rtems_isr_entry clock_isr<br>
+)<br>
+{<br>
+ rtems_status_code sc = RTEMS_SUCCESSFUL;<br>
+<br>
+ if (clock_isr != NULL) {<br>
+ sc = rtems_interrupt_handler_install(<br>
+ BCM2835_IRQ_ID_GPU_TIMER_M3,<br>
+ "Clock",<br>
+ RTEMS_INTERRUPT_UNIQUE,<br>
+ (rtems_interrupt_handler) clock_isr,<br>
+ NULL<br>
+ );<br>
+ } else {<br>
+ /* Remove interrupt handler */<br>
+ sc = rtems_interrupt_handler_remove(<br>
+ BCM2835_IRQ_ID_GPU_TIMER_M3,<br>
+ (rtems_interrupt_handler) Clock_isr,<br>
+ NULL<br>
+ );<br>
+ }<br>
+ if ( sc != RTEMS_SUCCESSFUL ) {<br>
+ rtems_fatal_error_occurred(0xdeadbeef);<br>
+ }<br>
+}<br>
+<br>
+static void raspberrypi_clock_initialize_hardware(void)<br>
+{<br>
+ uint32_t next_cmp = BCM2835_REG(BCM2835_GPU_TIMER_CLO);<br>
+ next_cmp += rtems_configuration_get_microseconds_per_tick();<br>
+ BCM2835_REG(BCM2835_GPU_TIMER_C3) = next_cmp;<br>
+ BCM2835_REG(BCM2835_GPU_TIMER_CS) = BCM2835_GPU_TIMER_CS_M3;<br>
+<br>
+ raspberrypi_tc.tc_get_timecount = raspberrypi_clock_get_timecount;<br>
+ raspberrypi_tc.tc_counter_mask = 0xffffffff;<br>
+ raspberrypi_tc.tc_frequency = 1000000; /* 1 MHz */<br>
+ raspberrypi_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;<br>
+ rtems_timecounter_install(&raspberrypi_tc);<br>
+}<br>
+<br>
+#define Clock_driver_support_at_tick() raspberrypi_clock_at_tick()<br>
+<br>
+#define Clock_driver_support_initialize_hardware() raspberrypi_clock_initialize_hardware()<br>
+<br>
+#define Clock_driver_support_install_isr(clock_isr) \<br>
+ raspberrypi_clock_handler_install_isr(clock_isr)<br>
+<br>
+#define CLOCK_DRIVER_USE_ONLY_BOOT_PROCESSOR 1<br>
+<br>
+#include "../../../shared/dev/clock/clockimpl.h"<br>
-- <br>
2.34.1<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>