3 \addtogroup rtx5_specific RTX v5 Specific API
4 \brief RTX v5 implementation specific definitions and functions defined in <b>%rtx_os.h</b>.
7 The RTX5 kernel can be customized for different application requirements:
9 - The function \ref osRtxIdleThread implements the idle thread and allows set the system into sleep modes for \ref lowPower or
10 \ref TickLess for ultra-low power operation.
12 - The function \ref osRtxErrorNotify may be extended to handle system runtime errors.
14 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>
15 and provides event information that helps to analyze the operation. Refer to \ref rtx_evr for more information.
22 \defgroup rtx5_specific_defines Macros
28 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
30 \def osRtxThreadCbSize
31 \brief Thread Control Block size
33 This macro exposes the minimum amount of memory needed for an RTX5 Thread Control Block,
34 see osThreadAttr_t::cb_mem and \ref osThreadAttr_t::cb_size.
38 // Used-defined memory for thread control block
39 static uint32_t thread_cb[osRtxThreadCbSize/4U];
43 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
46 \brief Timer Control Block size
48 This macro exposes the minimum amount of memory needed for an RTX5 Timer Control Block,
49 see osTimerAttr_t::cb_mem and \ref osTimerAttr_t::cb_size.
53 // Used-defined memory for timer control block
54 static uint32_t timer_cb[osRtxTimerCbSize/4U];
58 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
60 \def osRtxEventFlagsCbSize
61 \brief Event Flags Control Block size
63 This macro exposes the minimum amount of memory needed for an RTX5 Event Flags Control Block,
64 see osEventFlagsAttr_t::cb_mem and \ref osEventFlagsAttr_t::cb_size.
68 // Used-defined memory for event flags control block
69 static uint32_t evflags_cb[osRtxEventFlagsCbSize/4U];
73 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
76 \brief Mutex Control Block size
78 This macro exposes the minimum amount of memory needed for an RTX5 Mutex Control Block,
79 see osMutexAttr_t::cb_mem and \ref osMutexAttr_t::cb_size.
83 // Used-defined memory for mutex control block
84 static uint32_t mutex_cb[osRtxMutexCbSize/4U];
88 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
90 \def osRtxSemaphoreCbSize
91 \brief Semaphore Control Block size
93 This macro exposes the minimum amount of memory needed for an RTX5 Semaphore Control Block,
94 see osSemaphoreAttr_t::cb_mem and osSemaphoreAttr_t::cb_size.
98 // Used-defined memory for semaphore control block
99 static uint32_t sema_cb[osRtxSemaphoreCbSize/4U];
103 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
105 \def osRtxMemoryPoolCbSize
106 \brief Memory Pool Control Block size
108 This macro exposes the minimum amount of memory needed for an RTX5 Memory Pool Control Block,
109 see osMemoryPoolAttr_t::cb_mem and osMemoryPoolAttr_t::cb_size.
113 // Used-defined memory for memory pool control block
114 static uint32_t mempool_cb[osRtxMemoryPoolCbSize/4U];
118 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
120 \def osRtxMessageQueueCbSize
121 \brief Message Queue Control Block size
123 This macro exposes the minimum amount of memory needed for an RTX5 Message Queue Control Block,
124 see osMessageQueueAttr_t::cb_mem and osMessageQueueAttr_t::cb_size.
128 // Used-defined memory for message queue control block
129 static uint32_t msgqueue_cb[osRtxMessageQueueCbSize/4U];
133 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
135 \def osRtxMemoryPoolMemSize
136 \brief Memory Pool Memory size
138 This macro exposes the minimum amount of memory needed for an RTX5 Memory Pool Memory,
139 see osMemoryPoolAttr_t::mp_mem and osMemoryPoolAttr_t::mp_size.
143 // Maximum number of objects
152 // Used-defined memory for memory pool memory
153 static uint32_t mempool_mem[osRtxMemoryPoolMemSize(OBJ_COUNT, sizeof(object_t))/4U];
157 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
159 \def osRtxMessageQueueMemSize
160 \brief Message Queue Memory size
162 This macro exposes the minimum amount of memory needed for an RTX5 Message Queue Memory,
163 see osMessageQueueAttr_t::mq_mem and osMessageQueueAttr_t::mq_size.
167 // Maximum number of messages
168 #define MSG_COUNT 16U
176 // Used-defined memory for message queue
177 static uint32_t mq_mem[osRtxMessageQueueMemSize(MSG_COUNT, sizeof(msg_item_t))/4U];
181 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
183 \def osRtxErrorStackUnderflow
184 \brief Stack overflow, i.e. stack pointer below its lower memory limit for descending stacks.
186 This error identifier is used with \ref osRtxErrorNotify when RTX5 detects a thread stack overflow.
187 The object_id announced along this error can be used to identify the affected thread.
189 \ref threadConfig_watermark used together with larger stack sizes can help to figure out actual
190 memory requirements for threads.
192 \attention Whenever this error identifier is signaled memory corruption has already happened.
195 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
197 \def osRtxErrorISRQueueOverflow
198 \brief ISR Queue overflow detected when inserting object.
200 This error identifier is used with \ref osRtxErrorNotify when RTX5 detects an overflow of the
201 interrupt post processing message queue. The object_id can be used to identify the affected
204 \attention Whenever this error identifier is signaled the system state is already inconsistent.
207 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
209 \def osRtxErrorTimerQueueOverflow
210 \brief User Timer Callback Queue overflow detected for timer.
212 This error identifier is used with \ref osRtxErrorNotify when RTX5 detects an overflow of the
213 timer callback queue. The object_id can be used to identify the affected timer.
215 \attention Whenever this error identifier is signaled a timer callback is already lost.
218 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
220 \def osRtxErrorClibSpace
221 \brief Standard C/C++ library libspace not available.
223 This error identifier is used with \ref osRtxErrorNotify when RTX5 detects usage of libspace
224 but not enough memory was reserved using \c OS_THREAD_LIBSPACE_NUM.
227 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
229 \def osRtxErrorClibMutex
230 \brief Standard C/C++ library mutex initialization failed.
232 This error identifier is used with \ref osRtxErrorNotify when RTX5 fails to create mutexes needed
233 to lock global C/C++ library resources.
241 \defgroup rtx5_specific_functions Functions
242 \brief RTX5 functions
247 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
249 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
250 \param[in] code The code to identify the error condition.
251 \param[in] object_id A reference to any RTX object to identify the object that caused the issue, can be \token{NULL}.
253 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
254 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
256 The parameter \a code passes the actual error code to this function:
257 | Error Code | Description |
258 |-----------------------------------|-----------------------------------------------------------------------------------|
259 | \ref osRtxErrorStackUnderflow | Stack overflow detected for thread (thread_id=object_id) |
260 | \ref osRtxErrorISRQueueOverflow | ISR Queue overflow detected when inserting object (object_id) |
261 | \ref osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id) |
262 | \ref osRtxErrorClibSpace | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
263 | \ref osRtxErrorClibMutex | Standard C/C++ library mutex initialization failed |
265 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
266 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
267 need to increase the size of the object causing an overflow.
273 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
277 case osRtxErrorStackUnderflow:
278 // Stack overflow detected for thread (thread_id=object_id)
280 case osRtxErrorISRQueueOverflow:
281 // ISR Queue overflow detected when inserting object (object_id)
283 case osRtxErrorTimerQueueOverflow:
284 // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
286 case osRtxErrorClibSpace:
287 // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
289 case osRtxErrorClibMutex:
290 // Standard C/C++ library mutex initialization failed
301 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
303 \fn void osRtxIdleThread (void *argument);
304 \param[in] argument Unused parameter, always set to \token{NULL}.
306 The function \b osRtxIdleThread is executed by the RTX kernel when no other threads are ready to run.
308 By default, this thread is an empty end-less loop that does nothing. It only waits until another task
309 becomes ready to run. You may change the code of the \b osRtxIdleThread function to put the CPU into
310 a power-saving or idle mode, see \ref TickLess.
312 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
315 The idle thread should never be blocked nor terminated!
318 <li>blocking functions,</li>
319 <li>\ref osThreadTerminate, or </li>
320 <li>\ref osThreadExit</li>
322 and <b>do not</b> return from this function when providing a user defined implementation.
328 __NO_RETURN void osRtxIdleThread (void *argument) {