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 425e410cb420f889e9fd70f3854eab729572e8ce
Author: zhangyu117 <[email protected]>
AuthorDate: Fri Apr 3 15:00:45 2026 +0800

    arch/tricore: use psw.is to determine interrupt context
    
    Use PSW.IS instead of g_interrupt_context to determine interrupt
    context. This method relies on independent interrupt stack; otherwise
    psw.is = 1 in thread context, which cannot distinguish between threads
    and interrupts.
    
    Signed-off-by: zhangyu117 <[email protected]>
---
 arch/tricore/include/irq.h                   | 37 +---------------------------
 arch/tricore/src/common/tricore_doirq.c      | 12 ---------
 arch/tricore/src/common/tricore_initialize.c |  8 ------
 arch/tricore/src/common/tricore_svcall.c     |  8 ------
 arch/tricore/src/common/tricore_trapcall.c   |  5 ----
 arch/tricore/src/tc3xx/Toolchain.defs        |  1 +
 arch/tricore/src/tc4xx/Toolchain.defs        |  1 +
 7 files changed, 3 insertions(+), 69 deletions(-)

diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h
index 49d40988483..16e0b058041 100644
--- a/arch/tricore/include/irq.h
+++ b/arch/tricore/include/irq.h
@@ -187,14 +187,6 @@ struct xcptcontext
   uintptr_t *regs;
 };
 
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/* g_interrupt_context store irq status */
-
-extern volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];
-
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/
@@ -281,24 +273,6 @@ void up_irq_restore(irqstate_t flags)
  * Inline Functions
  ****************************************************************************/
 
-/****************************************************************************
- * Name: up_set_interrupt_context
- *
- * Description:
- *   Set the interrupt handler context.
- *
- ****************************************************************************/
-
-noinstrument_function
-static inline_function void up_set_interrupt_context(bool flag)
-{
-#ifdef CONFIG_SMP
-  g_interrupt_context[up_this_cpu()] = flag;
-#else
-  g_interrupt_context[0] = flag;
-#endif
-}
-
 /****************************************************************************
  * Name: up_interrupt_context
  *
@@ -311,16 +285,7 @@ static inline_function void up_set_interrupt_context(bool 
flag)
 noinstrument_function
 static inline_function bool up_interrupt_context(void)
 {
-#ifdef CONFIG_SMP
-  irqstate_t flags = up_irq_save();
-  bool ret = g_interrupt_context[up_this_cpu()];
-
-  up_irq_restore(flags);
-
-  return ret;
-#else
-  return g_interrupt_context[0];
-#endif
+  return (tricore_mfcr(TRICORE_CPU_PSW) & PSW_IS) != 0;
 }
 
 /****************************************************************************
diff --git a/arch/tricore/src/common/tricore_doirq.c 
b/arch/tricore/src/common/tricore_doirq.c
index a834a4df734..bab1364a9d5 100644
--- a/arch/tricore/src/common/tricore_doirq.c
+++ b/arch/tricore/src/common/tricore_doirq.c
@@ -73,14 +73,6 @@ void tricore_doirq(void)
 
   board_autoled_on(LED_INIRQ);
 
-  /* Nested interrupts are not supported */
-
-  DEBUGASSERT(!up_interrupt_context());
-
-  /* Set irq flag */
-
-  up_set_interrupt_context(true);
-
   /* Deliver the IRQ */
 
   tricore_ack_irq(irq);
@@ -117,10 +109,6 @@ void tricore_doirq(void)
       UP_ISB();
     }
 
-  /* Set irq flag */
-
-  up_set_interrupt_context(false);
-
   /* running_task->xcp.regs is about to become invalid
    * and will be marked as NULL to avoid misusage.
    */
diff --git a/arch/tricore/src/common/tricore_initialize.c 
b/arch/tricore/src/common/tricore_initialize.c
index 53edb23aa78..ce72f530e85 100644
--- a/arch/tricore/src/common/tricore_initialize.c
+++ b/arch/tricore/src/common/tricore_initialize.c
@@ -31,14 +31,6 @@
 
 #include "tricore_internal.h"
 
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/* g_interrupt_context store irq status */
-
-volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
diff --git a/arch/tricore/src/common/tricore_svcall.c 
b/arch/tricore/src/common/tricore_svcall.c
index aca3c516edf..6f062f0dd29 100644
--- a/arch/tricore/src/common/tricore_svcall.c
+++ b/arch/tricore/src/common/tricore_svcall.c
@@ -70,10 +70,6 @@ void tricore_svcall(volatile void *trap)
   plregs = tricore_csa2addr(tricore_mfcr(TRICORE_CPU_PCXI));
   puregs = tricore_csa2addr(plregs[REG_LPCXI]);
 
-  /* Set irq flag */
-
-  up_set_interrupt_context(true);
-
   cmd = puregs[REG_D8];
 
   if (cmd != SYS_restore_context)
@@ -103,10 +99,6 @@ void tricore_svcall(volatile void *trap)
         break;
     }
 
-  /* Set irq flag */
-
-  up_set_interrupt_context(false);
-
   /* Return to the caller, tricore_svcall is entered by a jump */
 
   tricore_jump_backto_link();
diff --git a/arch/tricore/src/common/tricore_trapcall.c 
b/arch/tricore/src/common/tricore_trapcall.c
index f9380931f99..a0b336218ed 100644
--- a/arch/tricore/src/common/tricore_trapcall.c
+++ b/arch/tricore/src/common/tricore_trapcall.c
@@ -319,8 +319,6 @@ void tricore_trapcall(volatile void *trap)
   was_interrupt_context = up_interrupt_context();
   if (!was_interrupt_context)
     {
-      up_set_interrupt_context(true);
-
       /* Update the current task's regs */
 
       g_running_tasks[this_cpu()]->xcp.regs = regs;
@@ -329,7 +327,6 @@ void tricore_trapcall(volatile void *trap)
   if (tclass == TRICORE_TRAP_CLASS_NMI)
     {
       tricore_nmitrap(tid, regs, NULL);
-      up_set_interrupt_context(false);
       tricore_jump_backto_link();
     }
 
@@ -342,8 +339,6 @@ void tricore_trapcall(volatile void *trap)
     {
       if (!was_interrupt_context)
         {
-          up_set_interrupt_context(false);
-
           /* g_running_tasks[]->xcp.regs is about to become invalid
            * and will be marked as NULL to avoid misusage.
            */
diff --git a/arch/tricore/src/tc3xx/Toolchain.defs 
b/arch/tricore/src/tc3xx/Toolchain.defs
index a3feae38a3e..7e9bee7a345 100644
--- a/arch/tricore/src/tc3xx/Toolchain.defs
+++ b/arch/tricore/src/tc3xx/Toolchain.defs
@@ -32,6 +32,7 @@ ifeq ($(CONFIG_ARCH_CHIP_TC39X),y)
 
   ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc3xx/Libraries/src/Libraries/iLLD/TC3xx/Tricore/Cpu/Std
   ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc3xx/Libraries/src/Libraries/Infra/Platform
+  ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc3xx/Libraries/src/Libraries/Infra/Sfr/TC39xB
   ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc3xx/Configurations
 endif
 
diff --git a/arch/tricore/src/tc4xx/Toolchain.defs 
b/arch/tricore/src/tc4xx/Toolchain.defs
index 9eff515a243..44b3c1a7302 100644
--- a/arch/tricore/src/tc4xx/Toolchain.defs
+++ b/arch/tricore/src/tc4xx/Toolchain.defs
@@ -33,6 +33,7 @@ endif
   ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc4xx/Libraries/src/Libraries/iLLD/TC4xx/Tricore/Cpu/Std
   ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc4xx/Libraries/src/Libraries/Infra/Platform
   ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc4xx/Libraries/src/Libraries/Infra/Platform/Compilers
+  ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc4xx/Libraries/src/Libraries/Infra/Sfr/TC4Dx
   ARCHINCLUDES += 
${INCDIR_PREFIX}$(TOPDIR)/arch/tricore/src/illd/tc4xx/Configurations
 endif
 

Reply via email to