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="https://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
187 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
189 \def osRtxErrorStackOverflow
190 \brief Stack overflow, i.e. stack pointer below its lower memory limit for descending stacks.
192 This error identifier is used with \ref osRtxErrorNotify when RTX5 detects a thread stack overflow.
193 The object_id announced along this error can be used to identify the affected thread.
195 \ref threadConfig_watermark used together with larger stack sizes can help to figure out actual
196 memory requirements for threads.
198 \attention Whenever this error identifier is signaled memory corruption has already happened.
201 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
203 \def osRtxErrorISRQueueOverflow
204 \brief ISR Queue overflow detected when inserting object.
206 This error identifier is used with \ref osRtxErrorNotify when RTX5 detects an overflow of the
207 interrupt post processing message queue. The object_id can be used to identify the affected
210 \attention Whenever this error identifier is signaled the system state is already inconsistent.
213 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
215 \def osRtxErrorTimerQueueOverflow
216 \brief User Timer Callback Queue overflow detected for timer.
218 This error identifier is used with \ref osRtxErrorNotify when RTX5 detects an overflow of the
219 timer callback queue. The object_id can be used to identify the affected timer.
221 \attention Whenever this error identifier is signaled a timer callback is already lost.
224 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
226 \def osRtxErrorClibSpace
227 \brief Standard C/C++ library libspace not available.
229 This error identifier is used with \ref osRtxErrorNotify when RTX5 detects usage of libspace
230 but not enough memory was reserved using \c OS_THREAD_LIBSPACE_NUM.
233 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
235 \def osRtxErrorClibMutex
236 \brief Standard C/C++ library mutex initialization failed.
238 This error identifier is used with \ref osRtxErrorNotify when RTX5 fails to create mutexes needed
239 to lock global C/C++ library resources.
247 \defgroup rtx5_specific_functions Functions
248 \brief RTX5 functions
253 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
255 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
256 \param[in] code The code to identify the error condition.
257 \param[in] object_id A reference to any RTX object to identify the object that caused the issue, can be \token{NULL}.
259 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
260 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
262 The parameter \a code passes the actual error code to this function:
263 | Error Code | Description |
264 |-----------------------------------|-----------------------------------------------------------------------------------|
265 | \ref osRtxErrorStackOverflow | Stack overflow detected for thread (thread_id=object_id) |
266 | \ref osRtxErrorISRQueueOverflow | ISR Queue overflow detected when inserting object (object_id) |
267 | \ref osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id) |
268 | \ref osRtxErrorClibSpace | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
269 | \ref osRtxErrorClibMutex | Standard C/C++ library mutex initialization failed |
271 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
272 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
273 need to increase the size of the object causing an overflow.
279 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
283 case osRtxErrorStackOverflow:
284 // Stack overflow detected for thread (thread_id=object_id)
286 case osRtxErrorISRQueueOverflow:
287 // ISR Queue overflow detected when inserting object (object_id)
289 case osRtxErrorTimerQueueOverflow:
290 // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
292 case osRtxErrorClibSpace:
293 // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
295 case osRtxErrorClibMutex:
296 // Standard C/C++ library mutex initialization failed
307 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
309 \fn void osRtxIdleThread (void *argument);
310 \param[in] argument Unused parameter, always set to \token{NULL}.
312 The function \b osRtxIdleThread is executed by the RTX kernel when no other threads are ready to run.
314 By default, this thread is an empty end-less loop that does nothing. It only waits until another task
315 becomes ready to run. You may change the code of the \b osRtxIdleThread function to put the CPU into
316 a power-saving or idle mode, see \ref TickLess.
318 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
321 The idle thread should never be blocked nor terminated!
324 <li>blocking functions,</li>
325 <li>\ref osThreadTerminate, or </li>
326 <li>\ref osThreadExit</li>
328 and <b>do not</b> return from this function when providing a user defined implementation.
334 __NO_RETURN void osRtxIdleThread (void *argument) {