This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 2f3953f7b6cb01cda01ad495a4f177d69cf0c660
Author: zhangyu117 <[email protected]>
AuthorDate: Mon Dec 8 20:05:43 2025 +0800

    arch/tricore: Share code between systimer_start and start_absolute
    
    Both paths now go through tricore_systimer_update, which also applies
    the freerun counter offset to relative starts.
    
    Signed-off-by: zhangyu117 <[email protected]>
---
 arch/tricore/src/common/tricore_systimer.c | 74 +++++++++++++++++-------------
 1 file changed, 42 insertions(+), 32 deletions(-)

diff --git a/arch/tricore/src/common/tricore_systimer.c 
b/arch/tricore/src/common/tricore_systimer.c
index 59adf3cfeec..3fa8878688f 100644
--- a/arch/tricore/src/common/tricore_systimer.c
+++ b/arch/tricore/src/common/tricore_systimer.c
@@ -121,6 +121,46 @@ static clkcnt_t tricore_systimer_max_delay(struct 
oneshot_lowerhalf_s *lower)
   return UINT32_MAX;
 }
 
+/****************************************************************************
+ * Name: tricore_systimer_update
+ ****************************************************************************/
+
+static void tricore_systimer_update(struct oneshot_lowerhalf_s *lower,
+                                    clkcnt_t clkcnt, bool relative)
+{
+  struct tricore_systimer_lowerhalf_s *priv =
+    (struct tricore_systimer_lowerhalf_s *)lower;
+  irqstate_t flags;
+  uint64_t   expected;
+  uint64_t   current;
+
+  flags = up_irq_save();
+
+  current = tricore_systimer_get_time(priv->tbase);
+  expected = relative ? clkcnt + current : clkcnt;
+
+  /* Time synchronization between cores */
+
+  if (priv->freerun_tbase)
+    {
+      expected = expected + current -
+                 tricore_systimer_get_time(priv->freerun_tbase);
+    }
+
+  /* Mini_delay time processing */
+
+  expected = expected < current + TRICORE_SYSTIMER_MIN_DELAY ?
+             current + TRICORE_SYSTIMER_MIN_DELAY : expected;
+
+  /* The comparator register is 32-bits. */
+
+  DEBUGASSERT(expected <= current + UINT32_MAX);
+
+  tricore_systimer_set_timecmp(priv->tbase, expected);
+
+  up_irq_restore(flags);
+}
+
 /****************************************************************************
  * Name: tricore_systimer_start
  *
@@ -143,19 +183,7 @@ static clkcnt_t tricore_systimer_max_delay(struct 
oneshot_lowerhalf_s *lower)
 static void tricore_systimer_start(struct oneshot_lowerhalf_s *lower,
                                    clkcnt_t delta)
 {
-  struct tricore_systimer_lowerhalf_s *priv =
-    (struct tricore_systimer_lowerhalf_s *)lower;
-  irqstate_t flags;
-  uint64_t   mtime;
-
-  delta = delta < TRICORE_SYSTIMER_MIN_DELAY ?
-                  TRICORE_SYSTIMER_MIN_DELAY : delta;
-  flags = up_irq_save();
-  mtime = tricore_systimer_get_time(priv->tbase);
-
-  tricore_systimer_set_timecmp(priv->tbase, mtime + delta);
-
-  up_irq_restore(flags);
+  tricore_systimer_update(lower, delta, true);
 }
 
 /****************************************************************************
@@ -181,25 +209,7 @@ static void
 tricore_systimer_start_absolute(struct oneshot_lowerhalf_s *lower,
                                 clkcnt_t expected)
 {
-  struct tricore_systimer_lowerhalf_s *priv =
-    (struct tricore_systimer_lowerhalf_s *)lower;
-  irqstate_t flags;
-  uint64_t   current;
-  uint64_t   min_expected;
-
-  flags = up_irq_save();
-  current = tricore_systimer_get_time(priv->tbase);
-  if (priv->freerun_tbase)
-    {
-      expected = expected + current -
-                 tricore_systimer_get_time(priv->freerun_tbase);
-    }
-
-  min_expected = current + TRICORE_SYSTIMER_MIN_DELAY;
-  expected = expected < min_expected ? min_expected : expected;
-  tricore_systimer_set_timecmp(priv->tbase, expected);
-
-  up_irq_restore(flags);
+  tricore_systimer_update(lower, expected, false);
 }
 
 /****************************************************************************

Reply via email to