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 1d494c0e787cc510b122f0b9125add4800b86614 Author: zhangyu117 <[email protected]> AuthorDate: Tue Nov 17 21:30:24 2026 +0800 arch/tricore: Use the STM of the current core for the systimer Program the STM and the systimer IRQ of the core that calls up_timer_initialize() instead of always using STM0, and keep the compare value 32 bits wide to match CMP0. Write OCS only when OCDS is enabled and add the CBS_OSTATE address of TC4xx, so the check also runs there. Rename tricore_systimer.c/h to tricore_stm.c/h. Signed-off-by: zhangyu117 <[email protected]> --- arch/tricore/src/common/CMakeLists.txt | 2 +- arch/tricore/src/common/Make.defs | 2 +- arch/tricore/src/common/tricore_main.c | 4 +- .../common/{tricore_systimer.c => tricore_stm.c} | 39 +++++++------- arch/tricore/src/common/tricore_stm.h | 59 +++++++++++----------- arch/tricore/src/tc3xx/tc3xx_clockconfig.c | 2 +- arch/tricore/src/tc3xx/tc3xx_timerisr.c | 7 +-- arch/tricore/src/tc4xx/tc4xx_clockconfig.c | 2 +- arch/tricore/src/tc4xx/tc4xx_timerisr.c | 7 +-- 9 files changed, 60 insertions(+), 64 deletions(-) diff --git a/arch/tricore/src/common/CMakeLists.txt b/arch/tricore/src/common/CMakeLists.txt index 6d41423b004..2342d1bdadf 100644 --- a/arch/tricore/src/common/CMakeLists.txt +++ b/arch/tricore/src/common/CMakeLists.txt @@ -42,7 +42,7 @@ set(SRCS tricore_svcall.c tricore_tcbinfo.c tricore_trapcall.c - tricore_systimer.c + tricore_stm.c tricore_usestack.c tricore_fork.c) diff --git a/arch/tricore/src/common/Make.defs b/arch/tricore/src/common/Make.defs index c0f9a7f1066..f3612104f4f 100644 --- a/arch/tricore/src/common/Make.defs +++ b/arch/tricore/src/common/Make.defs @@ -43,7 +43,7 @@ CMN_CSRCS += tricore_stackframe.c CMN_CSRCS += tricore_svcall.c CMN_CSRCS += tricore_tcbinfo.c CMN_CSRCS += tricore_trapcall.c -CMN_CSRCS += tricore_systimer.c +CMN_CSRCS += tricore_stm.c CMN_CSRCS += tricore_usestack.c CMN_CSRCS += tricore_fork.c diff --git a/arch/tricore/src/common/tricore_main.c b/arch/tricore/src/common/tricore_main.c index 9fe44594d1e..54d9f086d1d 100644 --- a/arch/tricore/src/common/tricore_main.c +++ b/arch/tricore/src/common/tricore_main.c @@ -75,7 +75,7 @@ static void tricore_core_sync(volatile uint32_t *sync) { uint32_t core = tricore_core_id(); #if TRICORE_CORE_SYNC_TIMEOUT > 0 - uint32_t start = getreg32(TRICORE_STM0_BASE + TRICORE_STM_TIM0_OFFSET); + uint32_t start = getreg32(TRICORE_STM_BASE(0) + TRICORE_STM_TIM0_OFFSET); #endif #ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING @@ -91,7 +91,7 @@ static void tricore_core_sync(volatile uint32_t *sync) while ((*sync & TRICORE_CORE_SYNC_MASK) != TRICORE_CORE_SYNC_MASK) { #if TRICORE_CORE_SYNC_TIMEOUT > 0 - if (getreg32(TRICORE_STM0_BASE + TRICORE_STM_TIM0_OFFSET) - start >= + if (getreg32(TRICORE_STM_BASE(0) + TRICORE_STM_TIM0_OFFSET) - start >= TRICORE_CORE_SYNC_TIMEOUT) { break; diff --git a/arch/tricore/src/common/tricore_systimer.c b/arch/tricore/src/common/tricore_stm.c similarity index 91% rename from arch/tricore/src/common/tricore_systimer.c rename to arch/tricore/src/common/tricore_stm.c index de0ceee9b4e..282290577f2 100644 --- a/arch/tricore/src/common/tricore_systimer.c +++ b/arch/tricore/src/common/tricore_stm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/tricore/src/common/tricore_systimer.c + * arch/tricore/src/common/tricore_stm.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,8 +24,7 @@ * Included Files ****************************************************************************/ -#include <nuttx/kmalloc.h> - +#include <nuttx/irq.h> #include <nuttx/timers/oneshot.h> #include <nuttx/timers/arch_alarm.h> @@ -52,9 +51,9 @@ struct tricore_systimer_lowerhalf_s { struct oneshot_lowerhalf_s lower; - int irq; - uintptr_t tbase; - uintptr_t freerun_tbase; + int irq; + uintptr_t tbase; + uintptr_t freerun_tbase; }; /**************************************************************************** @@ -78,11 +77,11 @@ static uint64_t tricore_systimer_get_time(uintptr_t tbase) return ticks; } -static void tricore_systimer_set_timecmp(uintptr_t tbase, uint64_t value) +static void tricore_systimer_set_timecmp(uintptr_t tbase, uint32_t value) { /* CMP0 compares the timer bits [31:0] */ - putreg32((uint32_t)value, TRICORE_STM_REG(tbase, TRICORE_STM_CMP0_OFFSET)); + putreg32(value, TRICORE_STM_REG(tbase, TRICORE_STM_CMP0_OFFSET)); } /**************************************************************************** @@ -128,15 +127,15 @@ static void tricore_systimer_update(struct oneshot_lowerhalf_s *lower, if (priv->freerun_tbase) { - expected = expected + current - - tricore_systimer_get_time(priv->freerun_tbase); + expected += current - tricore_systimer_get_time(priv->freerun_tbase); } /* The comparator register is 32-bits. */ DEBUGASSERT(expected <= current + UINT32_MAX); - tricore_systimer_set_timecmp(priv->tbase, expected); + tricore_systimer_set_timecmp(priv->tbase, + (uint32_t)(expected & UINT32_MAX)); if (tricore_systimer_get_time(priv->tbase) > expected) { @@ -224,7 +223,7 @@ static void tricore_systimer_cancel(struct oneshot_lowerhalf_s *lower) struct tricore_systimer_lowerhalf_s *priv = (struct tricore_systimer_lowerhalf_s *)lower; - tricore_systimer_set_timecmp(priv->tbase, UINT64_MAX); + tricore_systimer_set_timecmp(priv->tbase, UINT32_MAX); } /**************************************************************************** @@ -326,34 +325,30 @@ tricore_systimer_initialize(uintptr_t tbase, uintptr_t fr_tbase, /* 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(tbase, TRICORE_STM_OCS_OFFSET)); - regval = getreg32(TRICORE_STM_REG(tbase, TRICORE_STM_OCS_OFFSET)); - putreg32(regval & ~TRICORE_STM_OCS_SUS_P, - TRICORE_STM_REG(tbase, TRICORE_STM_OCS_OFFSET)); } -#else - putreg32(TRICORE_STM_OCS_SUS_P | TRICORE_STM_OCS_SUS_HARD, - TRICORE_STM_REG(tbase, TRICORE_STM_OCS_OFFSET)); -#endif - /* CMP0 compares the timer bits [31:0] and raises STMIR0 */ + /* CMP0 compares the timer bits [31:0] */ regval = getreg32(TRICORE_STM_REG(tbase, TRICORE_STM_CMCON_OFFSET)); regval &= ~(TRICORE_STM_CMCON_MSIZE0 | TRICORE_STM_CMCON_MSTART0); regval |= 31 & TRICORE_STM_CMCON_MSIZE0; putreg32(regval, TRICORE_STM_REG(tbase, TRICORE_STM_CMCON_OFFSET)); + /* CMP0 match raises STMIR0 */ + regval = getreg32(TRICORE_STM_REG(tbase, TRICORE_STM_ICR_OFFSET)); putreg32(regval & ~TRICORE_STM_ICR_CMP0OS, TRICORE_STM_REG(tbase, TRICORE_STM_ICR_OFFSET)); + /* Drop any old request before enabling its interrupt */ + putreg32(TRICORE_STM_ISCR_CMP0IRR, TRICORE_STM_REG(tbase, TRICORE_STM_ISCR_OFFSET)); - tricore_systimer_set_timecmp(tbase, UINT64_MAX); + tricore_systimer_set_timecmp(tbase, UINT32_MAX); regval = getreg32(TRICORE_STM_REG(tbase, TRICORE_STM_ICR_OFFSET)); putreg32(regval | TRICORE_STM_ICR_CMP0EN, diff --git a/arch/tricore/src/common/tricore_stm.h b/arch/tricore/src/common/tricore_stm.h index 55ff5b444a7..66bfda87ca9 100644 --- a/arch/tricore/src/common/tricore_stm.h +++ b/arch/tricore/src/common/tricore_stm.h @@ -33,40 +33,31 @@ * Pre-processor Definitions ****************************************************************************/ -/* System timer (STM) of CPU0 and its interrupt. On TC4xx the STM is part - * of the CPU0 SFR space and has a single 64-bit timer register. - */ +/* System timer hardware registers. */ #ifdef CONFIG_ARCH_CHIP_TC4XX -# define TRICORE_STM0_BASE 0xf8800000 /* MODULE_CPU0 */ -# define TRICORE_STM0_IRQ 10 /* SRC_STMCPU0_SR2 */ +# define TRICORE_STM_BASE(n) (0xf8800000 + ((n) << 18)) /* STMn */ +# define TRICORE_STM_SRC(n) (0xf4432028 + (n) * 0x40) /* SR2 */ -# define TRICORE_STM_ABS_OFFSET 0x20 /* 64-bit timer */ -# define TRICORE_STM_CMP0_OFFSET 0x120 /* Compare register 0 */ -# define TRICORE_STM_CMCON_OFFSET 0x128 /* Compare match control */ -# define TRICORE_STM_ICR_OFFSET 0x12c /* Interrupt control */ -# define TRICORE_STM_ISCR_OFFSET 0x130 /* Interrupt set/clear */ -# define TRICORE_STM_OCS_OFFSET 0x4 /* OCDS control and status */ - -# define TRICORE_STM_ICR_CMP0OS (1 << 1) /* CMP0 output, 0: STMIR0 */ +# define TRICORE_STM_ABS_OFFSET 0x20 /* 64-bit timer */ +# define TRICORE_STM_CMP0_OFFSET 0x120 /* Compare register 0 */ +# define TRICORE_STM_CMCON_OFFSET 0x128 /* Compare match control */ +# define TRICORE_STM_ICR_OFFSET 0x12c /* Interrupt control */ +# define TRICORE_STM_ISCR_OFFSET 0x130 /* Interrupt set/clear */ +# define TRICORE_STM_OCS_OFFSET 0x4 /* OCDS control and status */ +# define TRICORE_STM_ICR_CMP0OS (1 << 1) /* CMP0 output, 0: STMIR0 */ #else -# define TRICORE_STM0_BASE 0xf0001000 /* MODULE_STM0 */ -# define TRICORE_STM0_IRQ 192 /* SRC_STM0SR0 */ - -# define TRICORE_STM_TIM0_OFFSET 0x10 /* Timer bits [31:0] */ -# define TRICORE_STM_CAP_OFFSET 0x2c /* Timer bits [63:32] */ -# define TRICORE_STM_CMP0_OFFSET 0x30 /* Compare register 0 */ -# define TRICORE_STM_CMCON_OFFSET 0x38 /* Compare match control */ -# define TRICORE_STM_ICR_OFFSET 0x3c /* Interrupt control */ -# define TRICORE_STM_ISCR_OFFSET 0x40 /* Interrupt set/clear */ -# define TRICORE_STM_OCS_OFFSET 0xe8 /* OCDS control and status */ - -# define TRICORE_STM_ICR_CMP0OS (1 << 2) /* CMP0 output, 0: STMIR0 */ +# define TRICORE_STM_BASE(n) (0xf0001000 + (n) * 0x100) /* STMn */ +# define TRICORE_STM_SRC(n) (0xf0038300 + (n) * 0x8) /* SR0 */ -/* OCS can only be written with OCDS enabled (CBS_OSTATE.OEN) */ - -# define TRICORE_CBS_OSTATE 0xf0000480 -# define TRICORE_CBS_OSTATE_OEN (1 << 0) +# define TRICORE_STM_TIM0_OFFSET 0x10 /* Timer bits [31:0] */ +# define TRICORE_STM_CAP_OFFSET 0x2c /* Timer bits [63:32] */ +# define TRICORE_STM_CMP0_OFFSET 0x30 /* Compare register 0 */ +# define TRICORE_STM_CMCON_OFFSET 0x38 /* Compare match control */ +# define TRICORE_STM_ICR_OFFSET 0x3c /* Interrupt control */ +# define TRICORE_STM_ISCR_OFFSET 0x40 /* Interrupt set/clear */ +# define TRICORE_STM_OCS_OFFSET 0xe8 /* OCDS control and status */ +# define TRICORE_STM_ICR_CMP0OS (1 << 2) /* CMP0 output, 0: STMIR0 */ #endif #define TRICORE_STM_CMCON_MSIZE0 (0x1f << 0) /* CMP0 compare size - 1 */ @@ -74,7 +65,15 @@ #define TRICORE_STM_ICR_CMP0EN (1 << 0) /* CMP0 interrupt enable */ #define TRICORE_STM_ISCR_CMP0IRR (1 << 0) /* Clear CMP0 request */ #define TRICORE_STM_OCS_SUS_HARD (1 << 24) /* Hard suspend on halt */ -#define TRICORE_STM_OCS_SUS_MASK (0xf << 24) #define TRICORE_STM_OCS_SUS_P (1 << 28) /* SUS write protection */ +/* OCS can only be written with OCDS enabled */ + +#ifdef CONFIG_ARCH_CHIP_TC4XX +# define TRICORE_CBS_OSTATE 0xfa18006c +#else +# define TRICORE_CBS_OSTATE 0xf0000480 +#endif +#define TRICORE_CBS_OSTATE_OEN (1 << 0) + #endif /* __ARCH_TRICORE_SRC_COMMON_TRICORE_STM_H */ diff --git a/arch/tricore/src/tc3xx/tc3xx_clockconfig.c b/arch/tricore/src/tc3xx/tc3xx_clockconfig.c index 3900d6c1ad6..3c88b7047e8 100644 --- a/arch/tricore/src/tc3xx/tc3xx_clockconfig.c +++ b/arch/tricore/src/tc3xx/tc3xx_clockconfig.c @@ -43,7 +43,7 @@ /* STM0 timer bits [31:0], for the waits of the PLL ramp up */ -#define TC3XX_STM0_TIM0 (TRICORE_STM0_BASE + TRICORE_STM_TIM0_OFFSET) +#define TC3XX_STM0_TIM0 (TRICORE_STM_BASE(0) + TRICORE_STM_TIM0_OFFSET) /* Loop counts before a wait gives up */ diff --git a/arch/tricore/src/tc3xx/tc3xx_timerisr.c b/arch/tricore/src/tc3xx/tc3xx_timerisr.c index 157bfe18365..df18c08586e 100644 --- a/arch/tricore/src/tc3xx/tc3xx_timerisr.c +++ b/arch/tricore/src/tc3xx/tc3xx_timerisr.c @@ -25,7 +25,6 @@ ****************************************************************************/ #include <nuttx/irq.h> -#include <nuttx/kmalloc.h> #include <nuttx/timers/oneshot.h> #include <nuttx/timers/arch_alarm.h> @@ -49,9 +48,11 @@ void up_timer_initialize(void) { struct oneshot_lowerhalf_s *lower; + int cpu = up_cpu_index(); - lower = tricore_systimer_initialize(TRICORE_STM0_BASE, 0, - TRICORE_STM0_IRQ, SCU_FREQUENCY); + lower = tricore_systimer_initialize(TRICORE_STM_BASE(cpu), 0, + TRICORE_SRC2IRQ(TRICORE_STM_SRC(cpu)), + SCU_FREQUENCY); DEBUGASSERT(lower != NULL); diff --git a/arch/tricore/src/tc4xx/tc4xx_clockconfig.c b/arch/tricore/src/tc4xx/tc4xx_clockconfig.c index cc6d9bd04e4..c0c082f0ca4 100644 --- a/arch/tricore/src/tc4xx/tc4xx_clockconfig.c +++ b/arch/tricore/src/tc4xx/tc4xx_clockconfig.c @@ -53,7 +53,7 @@ /* CPU0 STM timer, 100 MHz while the clocks are set up */ -#define TC4XX_STM0_ABS (TRICORE_STM0_BASE + TRICORE_STM_ABS_OFFSET) +#define TC4XX_STM0_ABS (TRICORE_STM_BASE(0) + TRICORE_STM_ABS_OFFSET) #define TC4XX_STM_TICKS_PER_US 100 /* Loop counts before a wait gives up */ diff --git a/arch/tricore/src/tc4xx/tc4xx_timerisr.c b/arch/tricore/src/tc4xx/tc4xx_timerisr.c index da3fc128a2c..c3eac284c92 100644 --- a/arch/tricore/src/tc4xx/tc4xx_timerisr.c +++ b/arch/tricore/src/tc4xx/tc4xx_timerisr.c @@ -25,7 +25,6 @@ ****************************************************************************/ #include <nuttx/irq.h> -#include <nuttx/kmalloc.h> #include <nuttx/timers/oneshot.h> #include <nuttx/timers/arch_alarm.h> @@ -49,9 +48,11 @@ void up_timer_initialize(void) { struct oneshot_lowerhalf_s *lower; + int cpu = up_cpu_index(); - lower = tricore_systimer_initialize(TRICORE_STM0_BASE, 0, - TRICORE_STM0_IRQ, SCU_FREQUENCY); + lower = tricore_systimer_initialize(TRICORE_STM_BASE(cpu), 0, + TRICORE_SRC2IRQ(TRICORE_STM_SRC(cpu)), + SCU_FREQUENCY); DEBUGASSERT(lower != NULL);
