21
21
#include "mbed_error.h"
22
22
#include "mbed_interface.h"
23
23
#include "RTX_Config.h"
24
+ #include "rtos/rtos_handlers.h"
24
25
25
26
#ifdef RTE_Compiler_EventRecorder
26
27
#include "EventRecorder.h" // Keil::Compiler:Event Recorder
30
31
#endif
31
32
32
33
extern void rtos_idle_loop (void );
33
- extern void thread_terminate_hook (osThreadId_t id );
34
34
35
- __NO_RETURN void osRtxIdleThread (void * argument )
35
+ static void (* terminate_hook )(osThreadId_t id );
36
+
37
+ static void thread_terminate_hook (osThreadId_t id )
38
+ {
39
+ if (terminate_hook ) {
40
+ terminate_hook (id );
41
+ }
42
+ }
43
+
44
+ void rtos_attach_thread_terminate_hook (void (* fptr )(osThreadId_t id ))
45
+ {
46
+ terminate_hook = fptr ;
47
+ }
48
+
49
+ __NO_RETURN void osRtxIdleThread (void * argument )
36
50
{
37
51
for (;;) {
38
- rtos_idle_loop ();
52
+ rtos_idle_loop ();
39
53
}
40
54
}
41
55
42
- __NO_RETURN uint32_t osRtxErrorNotify (uint32_t code , void * object_id )
56
+ __NO_RETURN uint32_t osRtxErrorNotify (uint32_t code , void * object_id )
43
57
{
44
58
osThreadId_t tid = osThreadGetId ();
45
59
46
60
switch (code ) {
47
- case osRtxErrorStackUnderflow :
48
- // Stack underflow detected for thread (thread_id=object_id)
49
- // Note: "overflow" is printed instead of "underflow" due to end user familiarity with overflow errors
50
- MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_STACK_OVERFLOW ), "CMSIS-RTOS error: Stack overflow" , code );
51
- break ;
52
- case osRtxErrorISRQueueOverflow :
53
- // ISR Queue overflow detected when inserting object (object_id)
54
- MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_ISR_QUEUE_OVERFLOW ), "CMSIS-RTOS error: ISR Queue overflow" , code );
55
- break ;
56
- case osRtxErrorTimerQueueOverflow :
57
- // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
58
- MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_TIMER_QUEUE_OVERFLOW ), "CMSIS-RTOS error: User Timer Callback Queue overflow" , code );
59
- break ;
60
- case osRtxErrorClibSpace :
61
- // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
62
- MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_CLIB_SPACE_UNAVAILABLE ), "CMSIS-RTOS error: STD C/C++ library libspace not available" , code );
63
- break ;
64
- case osRtxErrorClibMutex :
65
- // Standard C/C++ library mutex initialization failed
66
- MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_CLIB_MUTEX_INIT_FAILURE ), "CMSIS-RTOS error: STD C/C++ library mutex initialization failed" , code );
67
- break ;
68
- default :
69
- //Unknown error flagged from kernel
70
- MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_UNKNOWN ), "CMSIS-RTOS error: Unknown" , code );
71
- break ;
61
+ case osRtxErrorStackUnderflow :
62
+ // Stack underflow detected for thread (thread_id=object_id)
63
+ // Note: "overflow" is printed instead of "underflow" due to end user familiarity with overflow errors
64
+ MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_STACK_OVERFLOW ), "CMSIS-RTOS error: Stack overflow" , code );
65
+ break ;
66
+ case osRtxErrorISRQueueOverflow :
67
+ // ISR Queue overflow detected when inserting object (object_id)
68
+ MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_ISR_QUEUE_OVERFLOW ), "CMSIS-RTOS error: ISR Queue overflow" , code );
69
+ break ;
70
+ case osRtxErrorTimerQueueOverflow :
71
+ // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
72
+ MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_TIMER_QUEUE_OVERFLOW ), "CMSIS-RTOS error: User Timer Callback Queue overflow" , code );
73
+ break ;
74
+ case osRtxErrorClibSpace :
75
+ // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
76
+ MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_CLIB_SPACE_UNAVAILABLE ), "CMSIS-RTOS error: STD C/C++ library libspace not available" , code );
77
+ break ;
78
+ case osRtxErrorClibMutex :
79
+ // Standard C/C++ library mutex initialization failed
80
+ MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_CLIB_MUTEX_INIT_FAILURE ), "CMSIS-RTOS error: STD C/C++ library mutex initialization failed" , code );
81
+ break ;
82
+ default :
83
+ //Unknown error flagged from kernel
84
+ MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_KERNEL , MBED_ERROR_CODE_UNKNOWN ), "CMSIS-RTOS error: Unknown" , code );
85
+ break ;
72
86
}
73
87
74
88
/* That shouldn't be reached */
@@ -77,52 +91,52 @@ __NO_RETURN uint32_t osRtxErrorNotify (uint32_t code, void *object_id)
77
91
78
92
#if defined(MBED_TRAP_ERRORS_ENABLED ) && MBED_TRAP_ERRORS_ENABLED
79
93
80
- static const char * error_msg (int32_t status )
94
+ static const char * error_msg (int32_t status )
81
95
{
82
96
switch (status ) {
83
- case osError :
84
- return "Unspecified RTOS error" ;
85
- case osErrorTimeout :
86
- return "Operation not completed within the timeout period" ;
87
- case osErrorResource :
88
- return "Resource not available" ;
89
- case osErrorParameter :
90
- return "Parameter error" ;
91
- case osErrorNoMemory :
92
- return "System is out of memory" ;
93
- case osErrorISR :
94
- return "Not allowed in ISR context" ;
95
- default :
96
- return "Unknown" ;
97
+ case osError :
98
+ return "Unspecified RTOS error" ;
99
+ case osErrorTimeout :
100
+ return "Operation not completed within the timeout period" ;
101
+ case osErrorResource :
102
+ return "Resource not available" ;
103
+ case osErrorParameter :
104
+ return "Parameter error" ;
105
+ case osErrorNoMemory :
106
+ return "System is out of memory" ;
107
+ case osErrorISR :
108
+ return "Not allowed in ISR context" ;
109
+ default :
110
+ return "Unknown" ;
97
111
}
98
112
}
99
113
100
- void EvrRtxKernelError (int32_t status )
114
+ void EvrRtxKernelError (int32_t status )
101
115
{
102
116
MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_RTOS_EVENT ), error_msg (status ), status );
103
117
}
104
118
105
- void EvrRtxThreadError (osThreadId_t thread_id , int32_t status )
119
+ void EvrRtxThreadError (osThreadId_t thread_id , int32_t status )
106
120
{
107
121
MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_RTOS_THREAD_EVENT ), error_msg (status ), thread_id );
108
122
}
109
123
110
- void EvrRtxTimerError (osTimerId_t timer_id , int32_t status )
124
+ void EvrRtxTimerError (osTimerId_t timer_id , int32_t status )
111
125
{
112
126
MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_RTOS_TIMER_EVENT ), error_msg (status ), timer_id );
113
127
}
114
128
115
- void EvrRtxEventFlagsError (osEventFlagsId_t ef_id , int32_t status )
129
+ void EvrRtxEventFlagsError (osEventFlagsId_t ef_id , int32_t status )
116
130
{
117
131
MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_RTOS_EVENT_FLAGS_EVENT ), error_msg (status ), ef_id );
118
132
}
119
133
120
- void EvrRtxMutexError (osMutexId_t mutex_id , int32_t status )
134
+ void EvrRtxMutexError (osMutexId_t mutex_id , int32_t status )
121
135
{
122
136
MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_RTOS_MUTEX_EVENT ), error_msg (status ), mutex_id );
123
137
}
124
138
125
- void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id , int32_t status )
139
+ void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id , int32_t status )
126
140
{
127
141
// Ignore semaphore overflow, the count will saturate with a returned error
128
142
if (status == osRtxErrorSemaphoreCountLimit ) {
@@ -132,20 +146,20 @@ void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status)
132
146
MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_RTOS_SEMAPHORE_EVENT ), error_msg (status ), semaphore_id );
133
147
}
134
148
135
- void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id , int32_t status )
149
+ void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id , int32_t status )
136
150
{
137
151
MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_RTOS_MEMORY_POOL_EVENT ), error_msg (status ), mp_id );
138
152
}
139
153
140
- void EvrRtxMessageQueueError (osMessageQueueId_t mq_id , int32_t status )
154
+ void EvrRtxMessageQueueError (osMessageQueueId_t mq_id , int32_t status )
141
155
{
142
156
MBED_ERROR1 (MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT ), error_msg (status ), mq_id );
143
157
}
144
158
145
159
#endif
146
160
147
161
// RTX hook which gets called when a thread terminates, using the event function to call hook
148
- void EvrRtxThreadExit (void )
162
+ void EvrRtxThreadExit (void )
149
163
{
150
164
osThreadId_t thread_id = osThreadGetId ();
151
165
thread_terminate_hook (thread_id );
@@ -154,7 +168,7 @@ void EvrRtxThreadExit (void)
154
168
#endif
155
169
}
156
170
157
- void EvrRtxThreadTerminate (osThreadId_t thread_id )
171
+ void EvrRtxThreadTerminate (osThreadId_t thread_id )
158
172
{
159
173
thread_terminate_hook (thread_id );
160
174
#if (!defined(EVR_RTX_DISABLE ) && (OS_EVR_THREAD != 0 ) && !defined(EVR_RTX_THREAD_TERMINATE_DISABLE ) && defined(RTE_Compiler_EventRecorder ))
0 commit comments