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 b1bb8375455b1c35d0113e6d3412e9af45c063da
Author: zhangyu117 <[email protected]>
AuthorDate: Fri Oct 30 22:00:30 2026 +0800

    arch/tricore: support sw-managed single-entry IRQ dispatch
    
    When CONFIG_ARCH_IRQPRIO is disabled, all IRQs go through
    tricore_irq_sched, which does ack, dispatch and context switch.
    No interrupt nesting and no scheduling GPSR are used.
    
    When CONFIG_ARCH_IRQPRIO is enabled, keep the two paths: SRPN 1 for
    the scheduling GPSR and SRPN 2~255 for the nestable direct path.
    
    Signed-off-by: zhangyu117 <[email protected]>
---
 arch/tricore/include/irq.h                         |  7 ++++--
 arch/tricore/src/common/gnu/tricore_vectors.S      | 10 +++++++--
 .../tricore/src/common/tasking/tricore_vectors.asm | 12 ++++++++--
 arch/tricore/src/common/tricore_doirq.c            | 26 +++++++++++++++++-----
 arch/tricore/src/common/tricore_irq.c              |  6 +++++
 .../tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld      | 16 ++++++++++---
 .../tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl     | 16 ++++++++++---
 .../tc4xx/triboard_tc4x9_com/scripts/tricore.ld    | 16 ++++++++++---
 .../tc4xx/triboard_tc4x9_com/scripts/tricore.lsl   | 16 ++++++++++---
 9 files changed, 101 insertions(+), 24 deletions(-)

diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h
index ff569169920..65fac5f8360 100644
--- a/arch/tricore/include/irq.h
+++ b/arch/tricore/include/irq.h
@@ -172,8 +172,11 @@
 #define TRICORE_GPSR_IRQNUM(src_cpu, dest_cpu)  \
   TRICORE_SRC2IRQ(TRICORE_SRC_GPSR_BASE + \
                   ((src_cpu) * TRICORE_SRCNUM_PER_GPSR + (dest_cpu)) * 4)
-#define TRICORE_SCHEDIRQ \
-  TRICORE_GPSR_IRQNUM(up_cpu_index(), up_cpu_index())
+
+#ifdef CONFIG_ARCH_IRQPRIO
+#  define TRICORE_SCHEDIRQ \
+     TRICORE_GPSR_IRQNUM(up_cpu_index(), up_cpu_index())
+#endif
 
 /* TriCore interrupt priority range, higher value means higher priority. */
 
diff --git a/arch/tricore/src/common/gnu/tricore_vectors.S 
b/arch/tricore/src/common/gnu/tricore_vectors.S
index 3a93f9f074c..6c18f495567 100644
--- a/arch/tricore/src/common/gnu/tricore_vectors.S
+++ b/arch/tricore/src/common/gnu/tricore_vectors.S
@@ -135,8 +135,12 @@ tricore_traptab:
 /****************************************************************************
  * Interrupt vector table
  *
- *   SRPN 1 -> tricore_irq_sched (lowest priority, task switch only),
- *   SRPN 2~MAX -> tricore_irq_direct (fast dispatch, nestable).
+ *   CONFIG_ARCH_IRQPRIO=y (Hardware-managed, Full BIV table):
+ *     SRPN 1 -> tricore_irq_sched (lowest priority, task switch only),
+ *     SRPN 2~MAX -> tricore_irq_direct (fast dispatch, nestable).
+ *   CONFIG_ARCH_IRQPRIO=n (Software-managed, One-entry BIV table):
+ *     Only the SRPN 255 entry exists, all IRQs vector to
+ *     tricore_irq_sched. No nesting support. Saves BIV flash (~8KB).
  ****************************************************************************/
 
        .section .inttab, "ax", @progbits
@@ -145,7 +149,9 @@ tricore_traptab:
        .type   tricore_inttab, @function
 tricore_inttab:
        INTSLOT tricore_irq_sched
+#ifdef CONFIG_ARCH_IRQPRIO
        .rept   TRICORE_IRQ_MAX_PRIORITY - 1
        INTSLOT tricore_irq_direct
        .endr
+#endif
        .size   tricore_inttab, . - tricore_inttab
diff --git a/arch/tricore/src/common/tasking/tricore_vectors.asm 
b/arch/tricore/src/common/tasking/tricore_vectors.asm
index 1937f3fa1ea..56695a66a45 100644
--- a/arch/tricore/src/common/tasking/tricore_vectors.asm
+++ b/arch/tricore/src/common/tasking/tricore_vectors.asm
@@ -41,7 +41,9 @@
        .extern tricore_fcutrap_recover
        .extern g_fcu_csa_base
        .extern tricore_irq_sched
+#ifdef CONFIG_ARCH_IRQPRIO
        .extern tricore_irq_direct
+#endif
 
 TRAPSLOT       .macro  cls, entry
        svlcx
@@ -140,8 +142,12 @@ ctx_notfcu:
 ;****************************************************************************
 ; Interrupt vector table
 ;
-;   SRPN 1 -> tricore_irq_sched (lowest priority, task switch only),
-;   SRPN 2~MAX -> tricore_irq_direct (fast dispatch, nestable).
+;   CONFIG_ARCH_IRQPRIO=y (Hardware-managed, Full BIV table):
+;     SRPN 1 -> tricore_irq_sched (lowest priority, task switch only),
+;     SRPN 2~MAX -> tricore_irq_direct (fast dispatch, nestable).
+;   CONFIG_ARCH_IRQPRIO=n (Software-managed, One-entry BIV table):
+;     Only the SRPN 255 entry exists, all IRQs vector to
+;     tricore_irq_sched. No nesting support. Saves BIV flash (~8KB).
 ;****************************************************************************
 
        .sdecl  ".text.inttab",code,protect
@@ -150,9 +156,11 @@ ctx_notfcu:
        .global tricore_inttab
 tricore_inttab:        .type   func
        INTSLOT tricore_irq_sched
+#ifdef CONFIG_ARCH_IRQPRIO
        .dup    TRICORE_IRQ_MAX_PRIORITY - 1
        INTSLOT tricore_irq_direct
        .endm
+#endif
        .size   tricore_inttab, * - tricore_inttab
 
        .end
diff --git a/arch/tricore/src/common/tricore_doirq.c 
b/arch/tricore/src/common/tricore_doirq.c
index 97a486c1665..8be1e7e94c2 100644
--- a/arch/tricore/src/common/tricore_doirq.c
+++ b/arch/tricore/src/common/tricore_doirq.c
@@ -45,6 +45,8 @@
  * Public Functions
  ****************************************************************************/
 
+#ifdef CONFIG_ARCH_IRQPRIO
+
 /****************************************************************************
  * Name: tricore_irq_direct
  *
@@ -79,17 +81,21 @@ void tricore_irq_direct(void)
   tricore_jump_backto_link();
 }
 
+#endif /* CONFIG_ARCH_IRQPRIO */
+
 /****************************************************************************
  * Name: tricore_irq_sched
  *
  * Description:
- *   Scheduling GPSR path for context switch (analogous to arm_doirq).
- *   This is triggered by tricore_irq_direct when it detects that a
- *   context switch is needed.
+ *   Context-switch interrupt path. Two dispatch schemes share this path
+ *   with different roles, selected by CONFIG_ARCH_IRQPRIO.
  *
- *   Because the GPSR SRPN is the lowest priority, this only executes
- *   after all normal interrupts have completed, guaranteeing safe
- *   context switch without race conditions.
+ *   CONFIG_ARCH_IRQPRIO=y:
+ *     SRPN 1 -> tricore_irq_sched (lowest priority, task switch only),
+ *     SRPN 2~MAX -> tricore_irq_direct (fast dispatch, nestable).
+ *   CONFIG_ARCH_IRQPRIO=n:
+ *     tricore_irq_sched does dispatch and task switch for all IRQs.
+ *     No nesting support and no scheduling GPSR.
  *
  ****************************************************************************/
 
@@ -98,6 +104,9 @@ void tricore_irq_sched(void)
   struct tcb_s **running_task = &g_running_tasks[this_cpu()];
   uintptr_t *regs = tricore_csa2addr(tricore_mfcr(TRICORE_CPU_PCXI));
   struct tcb_s *tcb;
+#ifndef CONFIG_ARCH_IRQPRIO
+  int irq = tricore_irq_from_lasr();
+#endif
 
   if (*running_task != NULL)
     {
@@ -119,6 +128,11 @@ void tricore_irq_sched(void)
 
   board_autoled_on(LED_INIRQ);
 
+#ifndef CONFIG_ARCH_IRQPRIO
+  tricore_ack_irq(irq);
+  irq_dispatch(irq, regs);
+#endif
+
   tcb = this_task();
 
   /* Check for a context switch. */
diff --git a/arch/tricore/src/common/tricore_irq.c 
b/arch/tricore/src/common/tricore_irq.c
index 51a11dd3668..1144d33ce57 100644
--- a/arch/tricore/src/common/tricore_irq.c
+++ b/arch/tricore/src/common/tricore_irq.c
@@ -164,6 +164,7 @@ int tricore_irq_to_srpn(int irq)
 
   /* Scheduling GPSR always gets the lowest priority */
 
+#ifdef CONFIG_ARCH_IRQPRIO
   if (irq == TRICORE_SCHEDIRQ)
     {
       g_srpn_to_irq[TRICORE_IRQ_MIN_PRIORITY] = irq;
@@ -171,6 +172,7 @@ int tricore_irq_to_srpn(int irq)
 
       return TRICORE_IRQ_MIN_PRIORITY;
     }
+#endif
 
   /* Lookup: search the full SRPN range [MIN + 1, MAX] */
 
@@ -255,7 +257,11 @@ void up_irqinitialize(void)
 #endif
 
   tricore_color_intstack();
+
+#ifdef CONFIG_ARCH_IRQPRIO
   up_enable_irq(TRICORE_SCHEDIRQ);
+#endif
+
   up_irq_enable();
 }
 
diff --git a/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld 
b/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld
index 58d9a8991b8..09d7c91c06a 100644
--- a/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld
+++ b/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.ld
@@ -74,10 +74,16 @@ PROVIDE(__start3 = 0x80900000);
 PROVIDE(__start4 = 0x80c00000);
 PROVIDE(__start5 = 0x80f00000);
 
+#ifdef CONFIG_ARCH_IRQPRIO
+#  define INTTAB_OFFSET 0x20
+#else
+#  define INTTAB_OFFSET 0x1fe0
+#endif
+
 SECTIONS
 {
-  /* Reset entry at +0, full BIV table at +0x20, trap table at +0x2000,
-   * and text at +0x2100.
+  /* Reset entry at +0, full BIV table at +0x20, single-entry BIV at
+   * +0x1fe0, trap table at +0x2000, and text at +0x2100.
    */
 
   .start ORIGIN(pfls) :
@@ -91,9 +97,13 @@ SECTIONS
     KEEP(*(.traptab))
   } > pfls
 
-  .intvec ORIGIN(pfls) + 0x20 :
+  .intvec ORIGIN(pfls) + INTTAB_OFFSET :
   {
+#ifdef CONFIG_ARCH_IRQPRIO
     __INTTAB_CPU0 = ORIGIN(pfls);
+#else
+    __INTTAB_CPU0 = ORIGIN(pfls) + INTTAB_OFFSET;
+#endif
     KEEP(*(.inttab))
   } > pfls
 
diff --git a/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl 
b/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl
index f233e81024e..a6488317ccb 100644
--- a/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl
+++ b/boards/tricore/tc3xx/a2g-tc397-5v-tft/scripts/tricore.lsl
@@ -58,6 +58,12 @@
 #define USTACK0         ISTACK0_END
 #define USTACK0_END     (USTACK0 - USTACK_SIZE)
 
+#ifdef CONFIG_ARCH_IRQPRIO
+#  define INTTAB_OFFSET 0x20
+#else
+#  define INTTAB_OFFSET 0x1fe0
+#endif
+
 derivative nuttx_tc3xx
 {
   core tc0
@@ -100,8 +106,8 @@ section_setup mpe:tc0:linear
 
 section_layout mpe:tc0:linear
 {
-  /* Reset entry at +0, full BIV table at +0x20, trap table at +0x2000,
-   * and text at +0x2100.
+  /* Reset entry at +0, full BIV table at +0x20, single-entry BIV at
+   * +0x1fe0, trap table at +0x2000, and text at +0x2100.
    */
 
   group start (ordered, run_addr = PFLS_BASE)
@@ -114,7 +120,7 @@ section_layout mpe:tc0:linear
     select ".text.traptab";
   }
 
-  group intvec (ordered, run_addr = PFLS_BASE + 0x20)
+  group intvec (ordered, run_addr = PFLS_BASE + INTTAB_OFFSET)
   {
     select ".text.inttab";
   }
@@ -171,7 +177,11 @@ section_layout mpe:tc0:linear
   }
 
   "__TRAPTAB_CPU0" := PFLS_BASE + 0x2000;
+#ifdef CONFIG_ARCH_IRQPRIO
   "__INTTAB_CPU0" := PFLS_BASE;
+#else
+  "__INTTAB_CPU0" := PFLS_BASE + INTTAB_OFFSET;
+#endif
 
   "__a0_mem" := sizeof(group:a0) > 0 ? addressof(group:a0) + 0x8000 : 0;
   "__a1_mem" := sizeof(group:a1) > 0 ? addressof(group:a1) + 0x8000 : 0;
diff --git a/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.ld 
b/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.ld
index 4155608965a..372a87768cd 100644
--- a/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.ld
+++ b/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.ld
@@ -80,10 +80,16 @@ PROVIDE(__start3 = 0x80680000);
 PROVIDE(__start4 = 0x807e0000);
 PROVIDE(__start5 = 0x8092c000);
 
+#ifdef CONFIG_ARCH_IRQPRIO
+#  define INTTAB_OFFSET 0x20
+#else
+#  define INTTAB_OFFSET 0x1fe0
+#endif
+
 SECTIONS
 {
-  /* Reset entry at +0, full BIV table at +0x20, trap table at +0x2000,
-   * and text at +0x2100.
+  /* Reset entry at +0, full BIV table at +0x20, single-entry BIV at
+   * +0x1fe0, trap table at +0x2000, and text at +0x2100.
    */
 
   .start ORIGIN(pfls) :
@@ -97,9 +103,13 @@ SECTIONS
     KEEP(*(.traptab))
   } > pfls
 
-  .intvec ORIGIN(pfls) + 0x20 :
+  .intvec ORIGIN(pfls) + INTTAB_OFFSET :
   {
+#ifdef CONFIG_ARCH_IRQPRIO
     __INTTAB_CPU0 = ORIGIN(pfls);
+#else
+    __INTTAB_CPU0 = ORIGIN(pfls) + INTTAB_OFFSET;
+#endif
     KEEP(*(.inttab))
   } > pfls
 
diff --git a/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.lsl 
b/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.lsl
index 076c5961641..75f1703a267 100644
--- a/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.lsl
+++ b/boards/tricore/tc4xx/triboard_tc4x9_com/scripts/tricore.lsl
@@ -62,6 +62,12 @@
 #define USTACK0         ISTACK0_END
 #define USTACK0_END     (USTACK0 - USTACK_SIZE)
 
+#ifdef CONFIG_ARCH_IRQPRIO
+#  define INTTAB_OFFSET 0x20
+#else
+#  define INTTAB_OFFSET 0x1fe0
+#endif
+
 derivative nuttx_tc4xx
 {
   core tc0
@@ -112,8 +118,8 @@ section_setup mpe:tc0:linear
 
 section_layout mpe:tc0:linear
 {
-  /* Reset entry at +0, full BIV table at +0x20, trap table at +0x2000,
-   * and text at +0x2100.
+  /* Reset entry at +0, full BIV table at +0x20, single-entry BIV at
+   * +0x1fe0, trap table at +0x2000, and text at +0x2100.
    */
 
   group start (ordered, run_addr = PFLS_BASE)
@@ -126,7 +132,7 @@ section_layout mpe:tc0:linear
     select ".text.traptab";
   }
 
-  group intvec (ordered, run_addr = PFLS_BASE + 0x20)
+  group intvec (ordered, run_addr = PFLS_BASE + INTTAB_OFFSET)
   {
     select ".text.inttab";
   }
@@ -181,7 +187,11 @@ section_layout mpe:tc0:linear
   }
 
   "__TRAPTAB_CPU0" := PFLS_BASE + 0x2000;
+#ifdef CONFIG_ARCH_IRQPRIO
   "__INTTAB_CPU0" := PFLS_BASE;
+#else
+  "__INTTAB_CPU0" := PFLS_BASE + INTTAB_OFFSET;
+#endif
 
   "__a0_mem" := sizeof(group:a0) > 0 ? addressof(group:a0) + 0x8000 : 0;
   "__a1_mem" := sizeof(group:a1) > 0 ? addressof(group:a1) + 0x8000 : 0;

Reply via email to