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 d7385967784dc3a96e3661b63ee6e5caa8ded699 Author: yangsong8 <[email protected]> AuthorDate: Tue Feb 24 15:27:52 2026 +0800 arch/tricore: add bus error hook func to handle safety bus test Add tricore_bustrap_register_hook() so that safety test modules can intercept expected bus errors during self-tests. If the registered hook handles the trap, tricore_bustrap returns normally instead of triggering a system panic. Signed-off-by: yangsong8 <[email protected]> --- arch/tricore/src/common/tricore_internal.h | 7 ++++ arch/tricore/src/common/tricore_trapcall.c | 67 ++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/arch/tricore/src/common/tricore_internal.h b/arch/tricore/src/common/tricore_internal.h index ac8aab260dd..1724d6ff449 100644 --- a/arch/tricore/src/common/tricore_internal.h +++ b/arch/tricore/src/common/tricore_internal.h @@ -128,6 +128,12 @@ #ifndef __ASSEMBLY__ typedef void (*up_vector_t)(void); + +/* Bus trap hook function type for safety test modules. + * Returns OK if the trap was handled, ERROR otherwise. + */ + +typedef int (*tricore_bustrap_hook_t)(uint32_t tid, void *context); #endif /**************************************************************************** @@ -186,6 +192,7 @@ void tricore_sigdeliver(void); void tricore_svcall(volatile void *trap); void tricore_trapcall(volatile void *trap); void tricore_trapinit(void); +void tricore_bustrap_register_hook(tricore_bustrap_hook_t hook); /* Context Save Areas *******************************************************/ diff --git a/arch/tricore/src/common/tricore_trapcall.c b/arch/tricore/src/common/tricore_trapcall.c index 589647088c7..df12db04fcd 100644 --- a/arch/tricore/src/common/tricore_trapcall.c +++ b/arch/tricore/src/common/tricore_trapcall.c @@ -47,6 +47,10 @@ static IfxCpu_Trap g_trapinfo; +/* Bus trap hook for safety test modules (e.g., BusMonTst). */ + +static tricore_bustrap_hook_t g_bustrap_hook; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -65,6 +69,27 @@ static void tricore_trapinfo(volatile void *trap) * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: tricore_bustrap_register_hook + * + * Description: + * Register a hook function for bus trap handling. This allows safety test + * modules (e.g., BusMonTst) to intercept and handle expected bus errors + * during self-tests without triggering a system panic. + * + * Input Parameters: + * hook - The hook function to register, or NULL to unregister + * + * Returned Value: + * None + * + ****************************************************************************/ + +void tricore_bustrap_register_hook(tricore_bustrap_hook_t hook) +{ + g_bustrap_hook = hook; +} + int weak_function tricore_nmitrap(uint32_t tid, void *context, void *arg) { _alert("PANIC!!! NMI Trap:\n"); @@ -247,6 +272,23 @@ int tricore_contexmnttrap(uint32_t tid, void *context, void *arg) int tricore_bustrap(uint32_t tid, void *context, void *arg) { + /* First, let the registered hook try to handle the trap. + * This is used by safety test modules (e.g., BusMonTst) to handle + * expected bus errors during self-tests. + */ + + if (g_bustrap_hook != NULL) + { + if (g_bustrap_hook(tid, context) == OK) + { + /* Hook handled the trap, return normally */ + + return OK; + } + } + + /* Hook did not handle or no hook registered, proceed with panic */ + _alert("PANIC!!! System Bus Trap:\n"); _alert("\tClass %d TID: %" PRId32 " regs: %p\n", IfxCpu_Trap_Class_bus, tid, context); @@ -333,6 +375,7 @@ int tricore_assertiontrap(uint32_t tid, void *context, void *arg) void tricore_trapcall(volatile void *trap) { uintptr_t *regs; + bool was_interrupt_context; IfxCpu_Trap *ctrap = (IfxCpu_Trap *)trap; IfxCpu_Trap_Class tclass = (IfxCpu_Trap_Class)ctrap->tClass; @@ -342,15 +385,16 @@ void tricore_trapcall(volatile void *trap) regs = tricore_csa2addr(tricore_mfcr(CPU_PCXI)); - if (!up_interrupt_context()) + 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; } - up_set_interrupt_context(true); - if (tclass == IfxCpu_Trap_Class_nonMaskableInterrupt) { tricore_nmitrap(tid, regs, NULL); @@ -384,7 +428,22 @@ void tricore_trapcall(volatile void *trap) if (tclass == IfxCpu_Trap_Class_bus) { - tricore_bustrap(tid, regs, NULL); + if (tricore_bustrap(tid, regs, NULL) == OK) + { + /* Bus trap was handled by hook */ + + 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. + */ + + g_running_tasks[this_cpu()]->xcp.regs = NULL; + } + } + __jumpBackToLink(); }
