Skip to content

Commit a2b5301

Browse files
author
Deepika
committed
Added thread terminate hook
Hook was added in RTX4 code to assist test framework to log thread info on thread terminate, which was not working with RTX5.
1 parent 0906be6 commit a2b5301

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

rtos/TARGET_CORTEX/mbed_rtx_handlers.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@
1919
#include "rtx_evr.h"
2020
#include "mbed_rtx.h"
2121
#include "mbed_error.h"
22+
#include "RTX_Config.h"
23+
24+
#ifdef RTE_Compiler_EventRecorder
25+
#include "EventRecorder.h" // Keil::Compiler:Event Recorder
26+
// Used from rtx_evr.c
27+
#define EvtRtxThreadExit EventID(EventLevelAPI, 0xF2U, 0x19U)
28+
#define EvtRtxThreadTerminate EventID(EventLevelAPI, 0xF2U, 0x1AU)
29+
#endif
2230

2331
extern void rtos_idle_loop(void);
32+
extern void thread_terminate_hook(osThreadId_t id);
2433

2534
__NO_RETURN void osRtxIdleThread (void *argument)
2635
{
@@ -136,3 +145,21 @@ void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status)
136145
}
137146

138147
#endif
148+
149+
// RTX hook which gets called when a thread terminates, using the event function to call hook
150+
void EvrRtxThreadExit (void)
151+
{
152+
osThreadId_t thread_id = osThreadGetId();
153+
thread_terminate_hook(thread_id);
154+
#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_EXIT_DISABLE) && defined(RTE_Compiler_EventRecorder))
155+
EventRecord2(EvtRtxThreadExit, 0U, 0U);
156+
#endif
157+
}
158+
159+
void EvrRtxThreadTerminate (osThreadId_t thread_id)
160+
{
161+
thread_terminate_hook(thread_id);
162+
#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_TERMINATE_DISABLE) && defined(RTE_Compiler_EventRecorder))
163+
EventRecord2(EvtRtxThreadTerminate, (uint32_t)thread_id, 0U);
164+
#endif
165+
}

0 commit comments

Comments
 (0)