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

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

commit bb0c01d05d9d631238a0d10237973787d7b2722d
Author: Parthiban Nallathambi <[email protected]>
AuthorDate: Fri Nov 6 16:08:16 2026 +0530

    arch/tricore: Program the system timer directly.
    
    tricore_systimer.c drives the STM through IfxStm, and the timer setup
    passes it the iLLD MODULE_STM0 and SRC names, which TC4xx aliases to
    MODULE_CPU0 and SRC_STMCPU0_SR2 on the command line.  Program the STM
    registers directly with the new STM definitions instead, the same way
    IfxStm did: hard suspend on halt, CMP0 on the timer bits [31:0] raising
    STMIR0.  Rename the local IFX_CFG_CPU_CLOCK_FREQUENCY, which redefined
    the iLLD one, and drop the TC4xx aliases.
    
    Signed-off-by: Parthiban Nallathambi <[email protected]>
---
 arch/tricore/src/common/tricore_internal.h |  2 +-
 arch/tricore/src/common/tricore_systimer.c | 74 ++++++++++++++++++++++--------
 arch/tricore/src/tc3xx/tc3xx_timerisr.c    |  6 +--
 arch/tricore/src/tc4xx/CMakeLists.txt      |  3 --
 arch/tricore/src/tc4xx/Make.defs           |  2 -
 arch/tricore/src/tc4xx/tc4xx_timerisr.c    |  6 +--
 6 files changed, 61 insertions(+), 32 deletions(-)

diff --git a/arch/tricore/src/common/tricore_internal.h 
b/arch/tricore/src/common/tricore_internal.h
index 8559036cd29..11149bfdc5f 100644
--- a/arch/tricore/src/common/tricore_internal.h
+++ b/arch/tricore/src/common/tricore_internal.h
@@ -237,7 +237,7 @@ int tricore_init_dbgmonitor(void);
 /* System Timer *************************************************************/
 
 struct oneshot_lowerhalf_s *
-tricore_systimer_initialize(volatile void *tbase, int irq, uint64_t freq);
+tricore_systimer_initialize(uintptr_t tbase, int irq, uint64_t freq);
 
 /* Debug ********************************************************************/
 
diff --git a/arch/tricore/src/common/tricore_systimer.c 
b/arch/tricore/src/common/tricore_systimer.c
index 5f1692494cc..62b61994c77 100644
--- a/arch/tricore/src/common/tricore_systimer.c
+++ b/arch/tricore/src/common/tricore_systimer.c
@@ -31,8 +31,7 @@
 #include <nuttx/timers/arch_alarm.h>
 
 #include "tricore_internal.h"
-
-#include "IfxStm.h"
+#include "tricore_stm.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -49,10 +48,14 @@
  * 40 CPU cycles (100ns at 400Mhz) ~ 10 timer cycles (for 100 Mhz timer).
  */
 
-#define IFX_CFG_CPU_CLOCK_FREQUENCY 100000000
+#define TRICORE_SYSTIMER_CPU_FREQUENCY 100000000
 
 #define TRICORE_SYSTIMER_MIN_DELAY \
-  (40ull * SCU_FREQUENCY / IFX_CFG_CPU_CLOCK_FREQUENCY)
+  (40ull * SCU_FREQUENCY / TRICORE_SYSTIMER_CPU_FREQUENCY)
+
+/* STM register of the timer */
+
+#define TRICORE_STM_REG(priv, offset)  ((priv)->tbase + (offset))
 
 /****************************************************************************
  * Private Types
@@ -66,7 +69,7 @@
 struct tricore_systimer_lowerhalf_s
 {
   struct oneshot_lowerhalf_s lower;
-  volatile void             *tbase;
+  uintptr_t                 tbase;
   spinlock_t                lock;
 };
 
@@ -82,7 +85,16 @@ tricore_systimer_get_time(struct 
tricore_systimer_lowerhalf_s *priv)
 
   flags = spin_lock_irqsave(&priv->lock);
 
-  ticks = IfxStm_get(priv->tbase);
+#ifdef TRICORE_STM_ABS_OFFSET
+  ticks = *(volatile uint64_t *)
+          TRICORE_STM_REG(priv, TRICORE_STM_ABS_OFFSET);
+#else
+  /* Reading TIM0 latches the upper 32 bits into CAP */
+
+  ticks  = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_TIM0_OFFSET));
+  ticks |= (uint64_t)getreg32(TRICORE_STM_REG(priv, TRICORE_STM_CAP_OFFSET))
+           << 32;
+#endif
 
   spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -97,7 +109,9 @@ tricore_systimer_set_timecmp(struct 
tricore_systimer_lowerhalf_s *priv,
 
   flags = spin_lock_irqsave(&priv->lock);
 
-  IfxStm_updateCompare(priv->tbase, IfxStm_Comparator_0, value);
+  /* CMP0 compares the timer bits [31:0] */
+
+  putreg32((uint32_t)value, TRICORE_STM_REG(priv, TRICORE_STM_CMP0_OFFSET));
 
   spin_unlock_irqrestore(&priv->lock, flags);
 }
@@ -300,9 +314,10 @@ static struct tricore_systimer_lowerhalf_s 
g_tricore_oneshot_lowerhalf =
  ****************************************************************************/
 
 struct oneshot_lowerhalf_s *
-tricore_systimer_initialize(volatile void *tbase, int irq, uint64_t freq)
+tricore_systimer_initialize(uintptr_t tbase, int irq, uint64_t freq)
 {
   struct tricore_systimer_lowerhalf_s *priv = &g_tricore_oneshot_lowerhalf;
+  uint32_t regval;
 
   priv->tbase = tbase;
   spin_lock_init(&priv->lock);
@@ -311,17 +326,40 @@ tricore_systimer_initialize(volatile void *tbase, int 
irq, uint64_t freq)
 
   oneshot_count_init(&priv->lower, (uint32_t)freq);
 
-  IfxStm_setSuspendMode(priv->tbase, IfxStm_SuspendMode_hard);
-
-  IfxStm_setCompareControl(tbase,
-      IfxStm_Comparator_0,
-      IfxStm_ComparatorOffset_0,
-      IfxStm_ComparatorSize_32Bits,
-      IfxStm_ComparatorInterrupt_ir0);
-
-  IfxStm_clearCompareFlag(tbase, IfxStm_Comparator_0);
+  /* Stop the timer while the core is halted by the debugger */
+
+#ifdef TRICORE_CBS_OSTATE
+  if ((getreg32(TRICORE_CBS_OSTATE) & TRICORE_CBS_OSTATE_OEN) != 0)
+    {
+      putreg32(TRICORE_STM_OCS_SUS_P | TRICORE_STM_OCS_SUS_HARD,
+               TRICORE_STM_REG(priv, TRICORE_STM_OCS_OFFSET));
+      regval = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_OCS_OFFSET));
+      putreg32(regval & ~TRICORE_STM_OCS_SUS_P,
+               TRICORE_STM_REG(priv, TRICORE_STM_OCS_OFFSET));
+    }
+#else
+  putreg32(TRICORE_STM_OCS_SUS_P | TRICORE_STM_OCS_SUS_HARD,
+           TRICORE_STM_REG(priv, TRICORE_STM_OCS_OFFSET));
+#endif
+
+  /* CMP0 compares the timer bits [31:0] and raises STMIR0 */
+
+  regval  = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_CMCON_OFFSET));
+  regval &= ~(TRICORE_STM_CMCON_MSIZE0 | TRICORE_STM_CMCON_MSTART0);
+  regval |= 31 & TRICORE_STM_CMCON_MSIZE0;
+  putreg32(regval, TRICORE_STM_REG(priv, TRICORE_STM_CMCON_OFFSET));
+
+  regval  = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_ICR_OFFSET));
+  putreg32(regval & ~TRICORE_STM_ICR_CMP0OS,
+           TRICORE_STM_REG(priv, TRICORE_STM_ICR_OFFSET));
+
+  putreg32(TRICORE_STM_ISCR_CMP0IRR,
+           TRICORE_STM_REG(priv, TRICORE_STM_ISCR_OFFSET));
   tricore_systimer_set_timecmp(priv, UINT64_MAX);
-  IfxStm_enableComparatorInterrupt(tbase, IfxStm_Comparator_0);
+
+  regval = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_ICR_OFFSET));
+  putreg32(regval | TRICORE_STM_ICR_CMP0EN,
+           TRICORE_STM_REG(priv, TRICORE_STM_ICR_OFFSET));
 
   irq_attach(irq, tricore_systimer_interrupt, priv);
   up_enable_irq(irq);
diff --git a/arch/tricore/src/tc3xx/tc3xx_timerisr.c 
b/arch/tricore/src/tc3xx/tc3xx_timerisr.c
index 44d03b34c3b..17b80b59d24 100644
--- a/arch/tricore/src/tc3xx/tc3xx_timerisr.c
+++ b/arch/tricore/src/tc3xx/tc3xx_timerisr.c
@@ -31,8 +31,7 @@
 #include <nuttx/timers/arch_alarm.h>
 
 #include "tricore_internal.h"
-
-#include "IfxStm.h"
+#include "tricore_stm.h"
 
 /****************************************************************************
  * Public Functions
@@ -51,8 +50,7 @@ void up_timer_initialize(void)
 {
   struct oneshot_lowerhalf_s *lower;
 
-  lower = tricore_systimer_initialize(&MODULE_STM0,
-                                      TRICORE_SRC2IRQ(&SRC_STM0SR0),
+  lower = tricore_systimer_initialize(TRICORE_STM0_BASE, TRICORE_STM0_IRQ,
                                       SCU_FREQUENCY);
 
   DEBUGASSERT(lower != NULL);
diff --git a/arch/tricore/src/tc4xx/CMakeLists.txt 
b/arch/tricore/src/tc4xx/CMakeLists.txt
index 10e9ba5d2f4..90b2fe750d7 100644
--- a/arch/tricore/src/tc4xx/CMakeLists.txt
+++ b/arch/tricore/src/tc4xx/CMakeLists.txt
@@ -178,6 +178,3 @@ if(NOT CONFIG_TRICORE_TOOLCHAIN_TASKING)
                                        -Wno-unused-but-set-parameter)
   target_compile_options(nuttx PRIVATE -Wno-implicit-fallthrough)
 endif()
-
-target_compile_definitions(arch PRIVATE -DMODULE_STM0=MODULE_CPU0
-                                        -DSRC_STM0SR0=SRC_STMCPU0_SR2)
diff --git a/arch/tricore/src/tc4xx/Make.defs b/arch/tricore/src/tc4xx/Make.defs
index 2f88c5bdec4..f6f79abf206 100644
--- a/arch/tricore/src/tc4xx/Make.defs
+++ b/arch/tricore/src/tc4xx/Make.defs
@@ -146,8 +146,6 @@ SDK_CSRCS += 
$(ILLD_DIR)/Libraries/Infra/Ssw/TC4xx/Tricore/Ifx_Ssw_Infra.c
 SDK_CSRCS += $(ILLD_DIR)/Libraries/Infra/Ssw/TC4xx/Tricore/Ifx_Ssw_Tc0.c
 
 CFLAGS += $(addprefix ${INCDIR_PREFIX},$(SDK_INCDIR))
-CFLAGS += -DMODULE_STM0=MODULE_CPU0
-CFLAGS += -DSRC_STM0SR0=SRC_STMCPU0_SR2
 
 VPATH += $(dir $(SDK_CSRCS))
 
diff --git a/arch/tricore/src/tc4xx/tc4xx_timerisr.c 
b/arch/tricore/src/tc4xx/tc4xx_timerisr.c
index 85625685a36..33bf29ef276 100644
--- a/arch/tricore/src/tc4xx/tc4xx_timerisr.c
+++ b/arch/tricore/src/tc4xx/tc4xx_timerisr.c
@@ -31,8 +31,7 @@
 #include <nuttx/timers/arch_alarm.h>
 
 #include "tricore_internal.h"
-
-#include "IfxStm.h"
+#include "tricore_stm.h"
 
 /****************************************************************************
  * Public Functions
@@ -51,8 +50,7 @@ void up_timer_initialize(void)
 {
   struct oneshot_lowerhalf_s *lower;
 
-  lower = tricore_systimer_initialize(&MODULE_CPU0,
-                                      TRICORE_SRC2IRQ(&SRC_STMCPU0_SR2),
+  lower = tricore_systimer_initialize(TRICORE_STM0_BASE, TRICORE_STM0_IRQ,
                                       SCU_FREQUENCY);
 
   DEBUGASSERT(lower != NULL);

Reply via email to