Skip to content

Commit 9252a02

Browse files
parthitcessekar15
authored andcommitted
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 <parthiban@linumiz.com>
1 parent 8a116e4 commit 9252a02

6 files changed

Lines changed: 64 additions & 32 deletions

File tree

‎arch/tricore/src/common/tricore_internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ int tricore_init_dbgmonitor(void);
237237
/* System Timer *************************************************************/
238238

239239
struct oneshot_lowerhalf_s *
240-
tricore_systimer_initialize(volatile void *tbase, int irq, uint64_t freq);
240+
tricore_systimer_initialize(uintptr_t tbase, int irq, uint64_t freq);
241241

242242
/* Debug ********************************************************************/
243243

‎arch/tricore/src/common/tricore_systimer.c‎

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#include <nuttx/timers/oneshot.h>
3131
#include <nuttx/timers/arch_alarm.h>
3232

33-
#include "tricore_internal.h"
33+
#include <arch/chip/chip.h>
3434

35-
#include "IfxStm.h"
35+
#include "tricore_internal.h"
3636

3737
/****************************************************************************
3838
* Pre-processor Definitions
@@ -49,10 +49,14 @@
4949
* 40 CPU cycles (100ns at 400Mhz) ~ 10 timer cycles (for 100 Mhz timer).
5050
*/
5151

52-
#define IFX_CFG_CPU_CLOCK_FREQUENCY 100000000
52+
#define TRICORE_SYSTIMER_CPU_FREQUENCY 100000000
5353

5454
#define TRICORE_SYSTIMER_MIN_DELAY \
55-
(40ull * SCU_FREQUENCY / IFX_CFG_CPU_CLOCK_FREQUENCY)
55+
(40ull * SCU_FREQUENCY / TRICORE_SYSTIMER_CPU_FREQUENCY)
56+
57+
/* STM register of the timer */
58+
59+
#define TRICORE_STM_REG(priv, offset) ((priv)->tbase + (offset))
5660

5761
/****************************************************************************
5862
* Private Types
@@ -66,7 +70,7 @@
6670
struct tricore_systimer_lowerhalf_s
6771
{
6872
struct oneshot_lowerhalf_s lower;
69-
volatile void *tbase;
73+
uintptr_t tbase;
7074
spinlock_t lock;
7175
};
7276

@@ -82,7 +86,16 @@ tricore_systimer_get_time(struct tricore_systimer_lowerhalf_s *priv)
8286

8387
flags = spin_lock_irqsave(&priv->lock);
8488

85-
ticks = IfxStm_get(priv->tbase);
89+
#ifdef TRICORE_STM_ABS_OFFSET
90+
ticks = *(volatile uint64_t *)
91+
TRICORE_STM_REG(priv, TRICORE_STM_ABS_OFFSET);
92+
#else
93+
/* Reading TIM0 latches the upper 32 bits into CAP */
94+
95+
ticks = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_TIM0_OFFSET));
96+
ticks |= (uint64_t)getreg32(TRICORE_STM_REG(priv, TRICORE_STM_CAP_OFFSET))
97+
<< 32;
98+
#endif
8699

87100
spin_unlock_irqrestore(&priv->lock, flags);
88101

@@ -97,7 +110,9 @@ tricore_systimer_set_timecmp(struct tricore_systimer_lowerhalf_s *priv,
97110

98111
flags = spin_lock_irqsave(&priv->lock);
99112

100-
IfxStm_updateCompare(priv->tbase, IfxStm_Comparator_0, value);
113+
/* CMP0 compares the timer bits [31:0] */
114+
115+
putreg32((uint32_t)value, TRICORE_STM_REG(priv, TRICORE_STM_CMP0_OFFSET));
101116

102117
spin_unlock_irqrestore(&priv->lock, flags);
103118
}
@@ -300,9 +315,10 @@ static struct tricore_systimer_lowerhalf_s g_tricore_oneshot_lowerhalf =
300315
****************************************************************************/
301316

302317
struct oneshot_lowerhalf_s *
303-
tricore_systimer_initialize(volatile void *tbase, int irq, uint64_t freq)
318+
tricore_systimer_initialize(uintptr_t tbase, int irq, uint64_t freq)
304319
{
305320
struct tricore_systimer_lowerhalf_s *priv = &g_tricore_oneshot_lowerhalf;
321+
uint32_t regval;
306322

307323
priv->tbase = tbase;
308324
spin_lock_init(&priv->lock);
@@ -311,17 +327,40 @@ tricore_systimer_initialize(volatile void *tbase, int irq, uint64_t freq)
311327

312328
oneshot_count_init(&priv->lower, (uint32_t)freq);
313329

314-
IfxStm_setSuspendMode(priv->tbase, IfxStm_SuspendMode_hard);
315-
316-
IfxStm_setCompareControl(tbase,
317-
IfxStm_Comparator_0,
318-
IfxStm_ComparatorOffset_0,
319-
IfxStm_ComparatorSize_32Bits,
320-
IfxStm_ComparatorInterrupt_ir0);
321-
322-
IfxStm_clearCompareFlag(tbase, IfxStm_Comparator_0);
330+
/* Stop the timer while the core is halted by the debugger */
331+
332+
#ifdef TRICORE_CBS_OSTATE
333+
if ((getreg32(TRICORE_CBS_OSTATE) & TRICORE_CBS_OSTATE_OEN) != 0)
334+
{
335+
putreg32(TRICORE_STM_OCS_SUS_P | TRICORE_STM_OCS_SUS_HARD,
336+
TRICORE_STM_REG(priv, TRICORE_STM_OCS_OFFSET));
337+
regval = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_OCS_OFFSET));
338+
putreg32(regval & ~TRICORE_STM_OCS_SUS_P,
339+
TRICORE_STM_REG(priv, TRICORE_STM_OCS_OFFSET));
340+
}
341+
#else
342+
putreg32(TRICORE_STM_OCS_SUS_P | TRICORE_STM_OCS_SUS_HARD,
343+
TRICORE_STM_REG(priv, TRICORE_STM_OCS_OFFSET));
344+
#endif
345+
346+
/* CMP0 compares the timer bits [31:0] and raises STMIR0 */
347+
348+
regval = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_CMCON_OFFSET));
349+
regval &= ~(TRICORE_STM_CMCON_MSIZE0 | TRICORE_STM_CMCON_MSTART0);
350+
regval |= 31 & TRICORE_STM_CMCON_MSIZE0;
351+
putreg32(regval, TRICORE_STM_REG(priv, TRICORE_STM_CMCON_OFFSET));
352+
353+
regval = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_ICR_OFFSET));
354+
putreg32(regval & ~TRICORE_STM_ICR_CMP0OS,
355+
TRICORE_STM_REG(priv, TRICORE_STM_ICR_OFFSET));
356+
357+
putreg32(TRICORE_STM_ISCR_CMP0IRR,
358+
TRICORE_STM_REG(priv, TRICORE_STM_ISCR_OFFSET));
323359
tricore_systimer_set_timecmp(priv, UINT64_MAX);
324-
IfxStm_enableComparatorInterrupt(tbase, IfxStm_Comparator_0);
360+
361+
regval = getreg32(TRICORE_STM_REG(priv, TRICORE_STM_ICR_OFFSET));
362+
putreg32(regval | TRICORE_STM_ICR_CMP0EN,
363+
TRICORE_STM_REG(priv, TRICORE_STM_ICR_OFFSET));
325364

326365
irq_attach(irq, tricore_systimer_interrupt, priv);
327366
up_enable_irq(irq);

‎arch/tricore/src/tc3xx/tc3xx_timerisr.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#include <nuttx/timers/oneshot.h>
3131
#include <nuttx/timers/arch_alarm.h>
3232

33-
#include "tricore_internal.h"
33+
#include <arch/chip/chip.h>
3434

35-
#include "IfxStm.h"
35+
#include "tricore_internal.h"
3636

3737
/****************************************************************************
3838
* Public Functions
@@ -51,8 +51,7 @@ void up_timer_initialize(void)
5151
{
5252
struct oneshot_lowerhalf_s *lower;
5353

54-
lower = tricore_systimer_initialize(&MODULE_STM0,
55-
TRICORE_SRC2IRQ(&SRC_STM0SR0),
54+
lower = tricore_systimer_initialize(TRICORE_STM0_BASE, TRICORE_STM0_IRQ,
5655
SCU_FREQUENCY);
5756

5857
DEBUGASSERT(lower != NULL);

‎arch/tricore/src/tc4xx/CMakeLists.txt‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,3 @@ if(NOT CONFIG_TRICORE_TOOLCHAIN_TASKING)
178178
-Wno-unused-but-set-parameter)
179179
target_compile_options(nuttx PRIVATE -Wno-implicit-fallthrough)
180180
endif()
181-
182-
target_compile_definitions(arch PRIVATE -DMODULE_STM0=MODULE_CPU0
183-
-DSRC_STM0SR0=SRC_STMCPU0_SR2)

‎arch/tricore/src/tc4xx/Make.defs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ SDK_CSRCS += $(ILLD_DIR)/Libraries/Infra/Ssw/TC4xx/Tricore/Ifx_Ssw_Infra.c
146146
SDK_CSRCS += $(ILLD_DIR)/Libraries/Infra/Ssw/TC4xx/Tricore/Ifx_Ssw_Tc0.c
147147

148148
CFLAGS += $(addprefix ${INCDIR_PREFIX},$(SDK_INCDIR))
149-
CFLAGS += -DMODULE_STM0=MODULE_CPU0
150-
CFLAGS += -DSRC_STM0SR0=SRC_STMCPU0_SR2
151149

152150
VPATH += $(dir $(SDK_CSRCS))
153151

‎arch/tricore/src/tc4xx/tc4xx_timerisr.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#include <nuttx/timers/oneshot.h>
3131
#include <nuttx/timers/arch_alarm.h>
3232

33-
#include "tricore_internal.h"
33+
#include <arch/chip/chip.h>
3434

35-
#include "IfxStm.h"
35+
#include "tricore_internal.h"
3636

3737
/****************************************************************************
3838
* Public Functions
@@ -51,8 +51,7 @@ void up_timer_initialize(void)
5151
{
5252
struct oneshot_lowerhalf_s *lower;
5353

54-
lower = tricore_systimer_initialize(&MODULE_CPU0,
55-
TRICORE_SRC2IRQ(&SRC_STMCPU0_SR2),
54+
lower = tricore_systimer_initialize(TRICORE_STM0_BASE, TRICORE_STM0_IRQ,
5655
SCU_FREQUENCY);
5756

5857
DEBUGASSERT(lower != NULL);

0 commit comments

Comments
 (0)