Skip to content

arch/tricore: support interrupt nesting - #21308

Open
zhangyu981027 wants to merge 6 commits into
apache:masterfrom
zhangyu981027:tricore_irq_pr3
Open

zhangyu981027 wants to merge 6 commits into
apache:masterfrom
zhangyu981027:tricore_irq_pr3

Conversation

@zhangyu981027

@zhangyu981027 zhangyu981027 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add priority-based interrupt nesting support for TriCore while preserving
the existing non-nesting configuration:

  • Split the single interrupt entry into:
    • tricore_irq_direct: fast, nestable dispatch. It triggers a
      low-priority GPSR when a context switch is required.
    • tricore_irq_sched: deferred context-switch and signal-delivery
      handling at the lowest SRPN, running after nested interrupts complete.
  • Defer signal delivery for the running task to the scheduling GPSR so
    up_schedule_sigaction() always has a saved context. Save and restore
    PPRS around this path to preserve the protection register set.
  • With CONFIG_ARCH_IRQPRIO=y, SRPN 1 is used for scheduling and
    SRPNs 2-255 use the nestable direct-interrupt path.
  • With CONFIG_ARCH_IRQPRIO=n, all interrupts use the software-managed
    single-entry tricore_irq_sched path without nesting.
  • Use __INTTAB_CPU0 as the final BIV value. The full vector-table
    configuration keeps BIV 8 KB-aligned, while the single-entry
    configuration places the entry at offset 0x1fe0.
  • Add ordered to the absolute-address TASKING text groups so that both
    TC3 and TC4 LSL files link correctly.
  • Return 0 from up_getusrsp() when regs is NULL because the fast
    interrupt path does not save a register frame.
  • Read the interrupt number from the current core's ICU LASR register
    instead of translating the SRPN through g_srpn_to_irq.

Commits

This PR is based directly on Apache NuttX master and contains six commits:

  • arch/tricore: add srpn_to_irq map vector
  • arch/tricore: remove up_irq_to_ndx implementation
  • arch/tricore: use lasr register to get irq number
  • arch/tricore: support interrupt nested
  • arch/tricore: support sw-managed single-entry IRQ dispatch
  • arch/tricore: return 0 in up_getusrsp when regs is NULL

Impact

TriCore architecture only. Interrupt nesting remains controlled by
CONFIG_ARCH_IRQPRIO; the non-nesting configuration retains its
single-entry dispatch behavior.

The TASKING LSL change only declares the required ordering for an
absolute-address group. It does not change the resulting section
addresses. No other architecture is affected.

Testing

Validation was performed after rebasing onto Apache NuttX master
e0a754b0bee56bd8803122f963ca4ebebed438df.

Build: All eight TC397/TC4x9 GCC and TASKING configurations passed build
and static layout verification. After the signal-delivery review fix, the
TC397 GCC CONFIG_ARCH_IRQPRIO=y configuration was rebuilt successfully.

Test: The updated TC397 GCC CONFIG_ARCH_IRQPRIO=y image passed complete
ostest, and the instrumented SRPN 2-to-3 test reached nesting depth 2.
The final source tree is byte-identical to the snapshots used for the
20261124 on-target tests below.

Board configurations:

  • TC397: a2g-tc397-5v-tft:nsh
  • TC4x9: triboard_tc4x9_com:nsh

Build and static layout verification

ELF symbols, section sizes, and startup disassembly were checked for every
configuration in this table.

Board / SoC Toolchain CONFIG_ARCH_IRQPRIO Result
TC397 GCC 11.3.1 n Build and static checks passed
TC397 GCC 11.3.1 y Build and static checks passed
TC397 TASKING VX v6.3r1 n Build and static checks passed
TC397 TASKING VX v6.3r1 y Build and static checks passed
TC4x9 GCC 11.3.1 n Build and static checks passed
TC4x9 GCC 11.3.1 y Build and static checks passed
TC4x9 TASKING SmartCode v10.4r1 n Build and static checks passed
TC4x9 TASKING SmartCode v10.4r1 y Build and static checks passed

Common static-verification results:

  • CONFIG_ARCH_IRQPRIO=n:
    __INTTAB_CPU0 = tricore_inttab = 0x80001fe0,
    .intvec size is 0x20.
  • CONFIG_ARCH_IRQPRIO=y:
    __INTTAB_CPU0 = 0x80000000,
    tricore_inttab = 0x80000020,
    .intvec size is 0x1fe0.
  • In both configurations, the trap table is at 0x80002000,
    text starts at 0x80002100, and startup disassembly confirms that
    the expected __INTTAB_CPU0 value is written to BIV.

The TC397 TASKING images and all TC4x9 images were built and checked
statically only; they were not flashed or run in this validation round.

TC397 on-target verification

Target: Infineon Application Kit TC397 V2.0, serial number AK8MNLZR.
Each image contained a unique hello marker to confirm that the intended
image was running.

Configuration Hello marker Test coverage Result
CONFIG_ARCH_IRQPRIO=n IRQNEST_20261123_OFF_E0A754 hello, uname -a, complete ostest, including vfork ostest exited with status 0
CONFIG_ARCH_IRQPRIO=y IRQNEST_20261124_DEV_SIG_PS6 hello, uname -a, complete ostest, including vfork ostest exited with status 0
IRQ nesting instrumentation IRQNEST_20261124_DEV_SIG_PS6_NEST High-priority GPSR triggered inside low-priority ISR max=2 low=1 high=2 nested=1

The CONFIG_ARCH_IRQPRIO=n run was the regression test before the latest
signal-delivery update. Both CONFIG_ARCH_IRQPRIO=y runs used the final
signal-delivery implementation. Complete ostest finished without
assertions, TriCore traps, or panics, and vfork reported that the child
ran and exited before the parent resumed.

For the nesting test, a high-priority SRPN 3 GPSR interrupt was
triggered from the low-priority SRPN 2 GPSR ISR. The high-priority ISR
ran before the low-priority ISR returned, proving an actual nesting
depth greater than one.

The nesting instrumentation was temporary and is not included in this
PR.

@github-actions github-actions Bot added Area: Build system Arch: tricore Issues related to the TriCore architecture from Infineon Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: tricore labels Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

acassis
acassis previously approved these changes Nov 1, 2026
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@zhangyu-duck please fix the conflict.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@zhangyu-duck please fix the conflict.

@casaroli casaroli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body says "Depends on #21307", which is closed without merge, and "only the last 4 commits belong to this PR", but the PR carries 20 commits. Three of them are also in #21355.

Fix: rebase on master, keep only the commits of this PR, and update the body.

The logs in the Testing section do not say that CONFIG_ARCH_IRQPRIO is on, and no defconfig sets it, so they may run only the non-nesting path.

Fix: add an ostest log with CONFIG_ARCH_IRQPRIO=y.

Comment thread arch/tricore/src/common/tricore_doirq.c Resolved
Comment thread arch/tricore/src/common/tricore_irq.c Resolved
@github-actions github-actions Bot added Size: M The size of the change in this PR is medium and removed Area: OS Components OS Components issues Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Nov 23, 2026
Decouple interrupt priority (SRPN) from the IRQ index used by
up_irq_to_ndx. Add a per-CPU SRPN-to-IRQ mapping table so that SRPN can
be independently allocated and reassigned without affecting the IRQ
numbering scheme.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Reason for revert: the mapping from IRQ to NDX should only be a logical
relationship; Tricore directly treated Prio as NDX, which led to the
existence of this interface.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Read the irq number from the ICU LASR register of the current core
instead of translating the SRPN through g_srpn_to_irq. LASR must be
read before interrupts are re-enabled.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Split the single interrupt entry (tricore_doirq) into two paths:
tricore_irq_direct: fast dispatch with re-enable for nesting,
triggers a low-priority GPSR if context switch is needed.

tricore_irq_sched: deferred context switch and signal delivery at
the lowest SRPN, runs only after all nested interrupts complete.

Defer signal delivery for the running task to the scheduling GPSR so
up_schedule_sigaction() always has a saved context. Save and restore
PPRS around this path to preserve the protection register set.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
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 <zhangyu117@xiaomi.com>
The fast irq path (like CONFIG_ARCH_HIPRI_INTERRUPT) does not save
regs in irq, similar to arm's pendsv, so xcp.regs may be NULL.
TriCore cannot access the NULL address, so check regs before use.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
@zhangyu981027

Copy link
Copy Markdown
Contributor Author

The body says "Depends on #21307", which is closed without merge, and "only the last 4 commits belong to this PR", but the PR carries 20 commits. Three of them are also in #21355.

Fix: rebase on master, keep only the commits of this PR, and update the body.

The logs in the Testing section do not say that CONFIG_ARCH_IRQPRIO is on, and no defconfig sets it, so they may run only the non-nesting path.

Fix: add an ostest log with CONFIG_ARCH_IRQPRIO=y.

The PR info gives detailed test results

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@casaroli please review again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: tricore Issues related to the TriCore architecture from Infineon Board: tricore Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants