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 3d176a6c15836b76586da1e407f2727c2492910a Author: zhangyu117 <[email protected]> AuthorDate: Mon Apr 27 15:44:56 2026 +0800 arch/tricore: Trigger the systimer IRQ by software when CMP0 is missed CMP0 raises the interrupt only when the counter equals the compare value, so the minimum delay was used to avoid setting a value that has already passed. Drop the minimum delay; when the compare value is already in the past, clear the CMP0 flag and set the request bit in the SRC register of the systimer IRQ, so the interrupt fires at once. Using the SRC register of the systimer itself avoids taking a GPSR service request for this. Signed-off-by: zhangyu117 <[email protected]> --- arch/tricore/include/tc3xx/irq.h | 1 + arch/tricore/include/tc4xx/irq.h | 1 + arch/tricore/src/common/tricore_systimer.c | 31 ++++++++++-------------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/arch/tricore/include/tc3xx/irq.h b/arch/tricore/include/tc3xx/irq.h index 633ec1442ef..387b332f9b3 100644 --- a/arch/tricore/include/tc3xx/irq.h +++ b/arch/tricore/include/tc3xx/irq.h @@ -50,6 +50,7 @@ #define TRICORE_SRC_TOS_SHIFT 11 /* Type of service (core) */ #define TRICORE_SRC_TOS_MASK (0x7 << TRICORE_SRC_TOS_SHIFT) #define TRICORE_SRC_CLRR (1 << 25) /* Clear request */ +#define TRICORE_SRC_SETR (1 << 26) /* Set request */ /* TOS of a core: 0 is CPU0, 1 is the DMA, 2 to 6 are CPU1 to CPU5 */ diff --git a/arch/tricore/include/tc4xx/irq.h b/arch/tricore/include/tc4xx/irq.h index 1545ea1273c..7a5e51e4ef2 100644 --- a/arch/tricore/include/tc4xx/irq.h +++ b/arch/tricore/include/tc4xx/irq.h @@ -52,6 +52,7 @@ #define TRICORE_SRC_TOS_MASK (0xf << TRICORE_SRC_TOS_SHIFT) #define TRICORE_SRC_SRE (1 << 23) /* Service request enable */ #define TRICORE_SRC_CLRR (1 << 25) /* Clear request */ +#define TRICORE_SRC_SETR (1 << 26) /* Set request */ /* TOS of a core: 0 to 5 are CPU0 to CPU5, 6 is the CSRM core */ diff --git a/arch/tricore/src/common/tricore_systimer.c b/arch/tricore/src/common/tricore_systimer.c index 3fa8878688f..de0ceee9b4e 100644 --- a/arch/tricore/src/common/tricore_systimer.c +++ b/arch/tricore/src/common/tricore_systimer.c @@ -36,22 +36,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* Since the tricore hardware timer triggers an interrupt only when the - * compare value is equal to the counter, setting a compare value that has - * already timed out will not trigger an interrupt. To avoid missing - * interrupts when setting the timer, we should set a minimum delay. - * The minimum delay is calculated based on the CPU frequency and the timer - * frequency. We assume that the worst-case execution time for setting the - * timer does not exceed 40 CPU cycles, and calculate the minimum timer - * delay accordingly. - * 40 CPU cycles (100ns at 400Mhz) ~ 10 timer cycles (for 100 Mhz timer). - */ - -#define TRICORE_SYSTIMER_CPU_FREQUENCY 100000000 - -#define TRICORE_SYSTIMER_MIN_DELAY \ - (40ull * SCU_FREQUENCY / TRICORE_SYSTIMER_CPU_FREQUENCY) - /* STM register of the timer */ #define TRICORE_STM_REG(tbase, offset) ((tbase) + (offset)) @@ -68,6 +52,7 @@ struct tricore_systimer_lowerhalf_s { struct oneshot_lowerhalf_s lower; + int irq; uintptr_t tbase; uintptr_t freerun_tbase; }; @@ -147,17 +132,20 @@ static void tricore_systimer_update(struct oneshot_lowerhalf_s *lower, 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); + if (tricore_systimer_get_time(priv->tbase) > expected) + { + putreg32(TRICORE_STM_ISCR_CMP0IRR, + TRICORE_STM_REG(priv->tbase, TRICORE_STM_ISCR_OFFSET)); + putreg32(getreg32(TRICORE_IRQ2SRC(priv->irq)) | TRICORE_SRC_SETR, + TRICORE_IRQ2SRC(priv->irq)); + } + up_irq_restore(flags); } @@ -330,6 +318,7 @@ tricore_systimer_initialize(uintptr_t tbase, uintptr_t fr_tbase, priv->tbase = tbase; priv->freerun_tbase = fr_tbase; + priv->irq = irq; ASSERT(freq <= UINT32_MAX);
