1 /* ---------------------------------------------------------------------- 2 * $Date: 5. February 2013 3 * $Revision: V1.02 4 * 5 * Project: CMSIS-RTOS API 6 * Title: cmsis_os.h template header file 7 * 8 * Version 0.02 9 * Initial Proposal Phase 10 * Version 0.03 11 * osKernelStart added, optional feature: main started as thread 12 * osSemaphores have standard behavior 13 * osTimerCreate does not start the timer, added osTimerStart 14 * osThreadPass is renamed to osThreadYield 15 * Version 1.01 16 * Support for C++ interface 17 * - const attribute removed from the osXxxxDef_t typedef's 18 * - const attribute added to the osXxxxDef macros 19 * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete 20 * Added: osKernelInitialize 21 * Version 1.02 22 * Control functions for short timeouts in microsecond resolution: 23 * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec 24 * Removed: osSignalGet 25 *---------------------------------------------------------------------------- 26 * 27 * Copyright (c) 2013-2017 ARM LIMITED 28 * 29 * SPDX-License-Identifier: Apache-2.0 30 * 31 * Licensed under the Apache License, Version 2.0 (the License); you may 32 * not use this file except in compliance with the License. 33 * You may obtain a copy of the License at 34 * 35 * www.apache.org/licenses/LICENSE-2.0 36 * 37 * Unless required by applicable law or agreed to in writing, software 38 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 39 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40 * See the License for the specific language governing permissions and 41 * limitations under the License. 42 *---------------------------------------------------------------------------*/ 43 44 45 #ifndef ZEPHYR_INCLUDE_CMSIS_RTOS_V1_CMSIS_OS_H_ 46 #define ZEPHYR_INCLUDE_CMSIS_RTOS_V1_CMSIS_OS_H_ 47 48 /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version. 49 #define osCMSIS 0x10002 ///< API version (main [31:16] .sub [15:0]) 50 51 /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number. 52 #define osCMSIS_KERNEL 0x10000 ///< RTOS identification and version (main [31:16] .sub [15:0]) 53 54 /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS. 55 #define osKernelSystemId "KERNEL V1.00" ///< RTOS identification string 56 57 /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS. 58 #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available 59 #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available 60 #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available 61 #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available 62 #define osFeature_Signals 8 ///< maximum number of Signal Flags available per thread 63 #define osFeature_Semaphore 30 ///< maximum count for \ref osSemaphoreCreate function 64 #define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available 65 #define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available 66 67 #include <stdint.h> 68 #include <stddef.h> 69 #include <kernel.h> 70 #include <sys/bitarray.h> 71 72 #ifdef __cplusplus 73 extern "C" 74 { 75 #endif 76 77 78 // ==== Enumeration, structures, defines ==== 79 80 /// Priority used for thread control. 81 /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS. 82 typedef enum { 83 osPriorityIdle = -3, ///< priority: idle (lowest) 84 osPriorityLow = -2, ///< priority: low 85 osPriorityBelowNormal = -1, ///< priority: below normal 86 osPriorityNormal = 0, ///< priority: normal (default) 87 osPriorityAboveNormal = +1, ///< priority: above normal 88 osPriorityHigh = +2, ///< priority: high 89 osPriorityRealtime = +3, ///< priority: realtime (highest) 90 osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority 91 } osPriority; 92 93 /// Timeout value. 94 /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS. 95 #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value 96 97 /// Status code values returned by CMSIS-RTOS functions. 98 /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS. 99 typedef enum { 100 osOK = 0, ///< function completed; no error or event occurred. 101 osEventSignal = 0x08, ///< function completed; signal event occurred. 102 osEventMessage = 0x10, ///< function completed; message event occurred. 103 osEventMail = 0x20, ///< function completed; mail event occurred. 104 osEventTimeout = 0x40, ///< function completed; timeout occurred. 105 osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object. 106 osErrorResource = 0x81, ///< resource not available: a specified resource was not available. 107 osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period. 108 osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines. 109 osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object. 110 osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority. 111 osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation. 112 osErrorValue = 0x86, ///< value of a parameter is out of range. 113 osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits. 114 os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization. 115 } osStatus; 116 117 118 /// Timer type value for the timer definition. 119 /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS. 120 typedef enum { 121 osTimerOnce = 0, ///< one-shot timer 122 osTimerPeriodic = 1 ///< repeating timer 123 } os_timer_type; 124 125 /// Entry point of a thread. 126 /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS. 127 typedef void (*os_pthread) (void const *argument); 128 129 /// Entry point of a timer call back function. 130 /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS. 131 typedef void (*os_ptimer) (void const *argument); 132 133 // >>> the following data type definitions may shall adapted towards a specific RTOS 134 135 /// Thread ID identifies the thread (pointer to a thread control block). 136 /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS. 137 typedef struct os_thread_cb *osThreadId; 138 139 /// Timer ID identifies the timer (pointer to a timer control block). 140 /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS. 141 typedef struct os_timer_cb *osTimerId; 142 143 /// Mutex ID identifies the mutex (pointer to a mutex control block). 144 /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS. 145 typedef struct os_mutex_cb *osMutexId; 146 147 /// Semaphore ID identifies the semaphore (pointer to a semaphore control block). 148 /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS. 149 typedef struct os_semaphore_cb *osSemaphoreId; 150 151 /// Pool ID identifies the memory pool (pointer to a memory pool control block). 152 /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS. 153 typedef struct os_pool_cb *osPoolId; 154 155 /// Message ID identifies the message queue (pointer to a message queue control block). 156 /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS. 157 typedef struct os_messageQ_cb *osMessageQId; 158 159 /// Mail ID identifies the mail queue (pointer to a mail queue control block). 160 /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS. 161 typedef struct os_mailQ_cb *osMailQId; 162 163 164 /// Thread Definition structure contains startup information of a thread. 165 /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS. 166 typedef struct os_thread_def { 167 os_pthread pthread; ///< start address of thread function 168 osPriority tpriority; ///< initial thread priority 169 uint32_t instances; ///< maximum number of instances of that thread function 170 uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size 171 void *stack_mem; ///< pointer to array of stack memory 172 struct k_thread *cm_thread; ///< pointer to k_thread structure 173 struct k_poll_signal *poll_signal; 174 struct k_poll_event *poll_event; 175 int32_t signal_results; 176 ///< a bitarray used to indicate whether the thread is used or not, 0: unused, 1: used 177 void *status_mask; 178 } osThreadDef_t; 179 180 /// Timer Definition structure contains timer parameters. 181 /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS. 182 typedef struct os_timer_def { 183 os_ptimer ptimer; ///< start address of a timer function 184 } osTimerDef_t; 185 186 /// Mutex Definition structure contains setup information for a mutex. 187 /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS. 188 typedef struct os_mutex_def { 189 uint32_t dummy; ///< dummy value. 190 } osMutexDef_t; 191 192 /// Semaphore Definition structure contains setup information for a semaphore. 193 /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS. 194 typedef struct os_semaphore_def { 195 uint32_t dummy; ///< dummy value. 196 } osSemaphoreDef_t; 197 198 /// Definition structure for memory block allocation. 199 /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS. 200 typedef struct os_pool_def { 201 uint32_t pool_sz; ///< number of items (elements) in the pool 202 uint32_t item_sz; ///< size of an item 203 void *pool; ///< pointer to memory for pool 204 } osPoolDef_t; 205 206 /// Definition structure for message queue. 207 /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS. 208 typedef struct os_messageQ_def { 209 uint32_t queue_sz; ///< number of elements in the queue 210 uint32_t item_sz; ///< size of an item 211 void *pool; ///< memory array for messages 212 struct k_msgq *msgq; 213 } osMessageQDef_t; 214 215 /// Definition structure for mail queue. 216 /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS. 217 typedef struct os_mailQ_def { 218 uint32_t queue_sz; ///< number of elements in the queue 219 uint32_t item_sz; ///< size of an item 220 void *pool; ///< memory array for mail 221 struct k_mbox *mbox; 222 } osMailQDef_t; 223 224 /// Event structure contains detailed information about an event. 225 /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS. 226 /// However the struct may be extended at the end. 227 typedef struct { 228 osStatus status; ///< status code: event or error information 229 union { 230 uint32_t v; ///< message as 32-bit value 231 void *p; ///< message or mail as void pointer 232 int32_t signals; ///< signal flags 233 } value; ///< event value 234 union { 235 osMailQId mail_id; ///< mail id obtained by \ref osMailCreate 236 osMessageQId message_id; ///< message id obtained by \ref osMessageCreate 237 } def; ///< event definition 238 } osEvent; 239 240 241 // ==== Kernel Control Functions ==== 242 243 /// Initialize the RTOS Kernel for creating objects. 244 /// \return status code that indicates the execution status of the function. 245 /// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS. 246 osStatus osKernelInitialize (void); 247 248 /// Start the RTOS Kernel. 249 /// \return status code that indicates the execution status of the function. 250 /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS. 251 osStatus osKernelStart (void); 252 253 /// Check if the RTOS kernel is already started. 254 /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS. 255 /// \return 0 RTOS is not started, 1 RTOS is started. 256 int32_t osKernelRunning(void); 257 258 #if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available 259 260 /// Get the RTOS kernel system timer counter 261 /// \note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS. 262 /// \return RTOS kernel system timer as 32-bit value 263 uint32_t osKernelSysTick (void); 264 265 /// The RTOS kernel system timer frequency in Hz 266 /// \note Reflects the system timer setting and is typically defined in a configuration file. 267 #define osKernelSysTickFrequency sys_clock_hw_cycles_per_sec 268 269 /// Convert a microseconds value to a RTOS kernel system timer value. 270 /// \param microsec time value in microseconds. 271 /// \return time value normalized to the \ref osKernelSysTickFrequency 272 #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000U) 273 274 #endif // System Timer available 275 276 // ==== Thread Management ==== 277 278 /// Create a Thread Definition with function, priority, and stack requirements. 279 /// \param name name of the thread function. 280 /// \param priority initial priority of the thread function. 281 /// \param instances number of possible thread instances. 282 /// \param stacksz stack size (in bytes) requirements for the thread function. 283 /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the 284 /// macro body is implementation specific in every CMSIS-RTOS. 285 #if defined (osObjectsExternal) // object is external 286 #define osThreadDef(name, priority, instances, stacksz) \ 287 extern const osThreadDef_t os_thread_def_##name 288 #else // define the object 289 #define osThreadDef(name, priority, instances, stacksz) \ 290 static K_THREAD_STACK_ARRAY_DEFINE(stacks_##name, instances, CONFIG_CMSIS_THREAD_MAX_STACK_SIZE); \ 291 static struct k_thread cm_thread_##name[instances]; \ 292 static struct k_poll_signal wait_signal_##name; \ 293 static struct k_poll_event wait_events_##name; \ 294 static SYS_BITARRAY_DEFINE(bitarray_##name, instances); \ 295 static osThreadDef_t os_thread_def_##name = \ 296 { (name), (priority), (instances), (stacksz), (void *)(stacks_##name), \ 297 (cm_thread_##name), (&wait_signal_##name), \ 298 (&wait_events_##name), 0, (void *)(&bitarray_##name)} 299 #endif 300 301 /// Access a Thread definition. 302 /// \param name name of the thread definition object. 303 /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the 304 /// macro body is implementation specific in every CMSIS-RTOS. 305 #define osThread(name) \ 306 &os_thread_def_##name 307 308 /// Create a thread and add it to Active Threads and set it to state READY. 309 /// \param[in] thread_def thread definition referenced with \ref osThread. 310 /// \param[in] argument pointer that is passed to the thread function as start argument. 311 /// \return thread ID for reference by other functions or NULL in case of error. 312 /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS. 313 osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument); 314 315 /// Return the thread ID of the current running thread. 316 /// \return thread ID for reference by other functions or NULL in case of error. 317 /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS. 318 osThreadId osThreadGetId (void); 319 320 /// Terminate execution of a thread and remove it from Active Threads. 321 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 322 /// \return status code that indicates the execution status of the function. 323 /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS. 324 osStatus osThreadTerminate (osThreadId thread_id); 325 326 /// Pass control to next thread that is in state \b READY. 327 /// \return status code that indicates the execution status of the function. 328 /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS. 329 osStatus osThreadYield (void); 330 331 /// Change priority of an active thread. 332 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 333 /// \param[in] priority new priority value for the thread function. 334 /// \return status code that indicates the execution status of the function. 335 /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS. 336 osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); 337 338 /// Get current priority of an active thread. 339 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 340 /// \return current priority value of the thread function. 341 /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS. 342 osPriority osThreadGetPriority (osThreadId thread_id); 343 344 345 // ==== Generic Wait Functions ==== 346 347 /// Wait for Timeout (Time Delay). 348 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value 349 /// \return status code that indicates the execution status of the function. 350 osStatus osDelay (uint32_t millisec); 351 352 #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available 353 354 /// Wait for Signal, Message, Mail, or Timeout. 355 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 356 /// \return event that contains signal, message, or mail information or error code. 357 /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS. 358 osEvent osWait (uint32_t millisec); 359 360 #endif // Generic Wait available 361 362 363 // ==== Timer Management Functions ==== 364 /// Define a Timer object. 365 /// \param name name of the timer object. 366 /// \param function name of the timer call back function. 367 /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the 368 /// macro body is implementation specific in every CMSIS-RTOS. 369 #if defined (osObjectsExternal) // object is external 370 #define osTimerDef(name, function) \ 371 extern const osTimerDef_t os_timer_def_##name 372 #else // define the object 373 #define osTimerDef(name, function) \ 374 const osTimerDef_t os_timer_def_##name = \ 375 { (function) } 376 #endif 377 378 /// Access a Timer definition. 379 /// \param name name of the timer object. 380 /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the 381 /// macro body is implementation specific in every CMSIS-RTOS. 382 #define osTimer(name) \ 383 &os_timer_def_##name 384 385 /// Create a timer. 386 /// \param[in] timer_def timer object referenced with \ref osTimer. 387 /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. 388 /// \param[in] argument argument to the timer call back function. 389 /// \return timer ID for reference by other functions or NULL in case of error. 390 /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS. 391 osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument); 392 393 /// Start or restart a timer. 394 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 395 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer. 396 /// \return status code that indicates the execution status of the function. 397 /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. 398 osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); 399 400 /// Stop the timer. 401 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 402 /// \return status code that indicates the execution status of the function. 403 /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS. 404 osStatus osTimerStop (osTimerId timer_id); 405 406 /// Delete a timer that was created by \ref osTimerCreate. 407 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 408 /// \return status code that indicates the execution status of the function. 409 /// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS. 410 osStatus osTimerDelete (osTimerId timer_id); 411 412 413 // ==== Signal Management ==== 414 415 /// Set the specified Signal Flags of an active thread. 416 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 417 /// \param[in] signals specifies the signal flags of the thread that should be set. 418 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. 419 /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS. 420 int32_t osSignalSet (osThreadId thread_id, int32_t signals); 421 422 /// Clear the specified Signal Flags of an active thread. 423 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 424 /// \param[in] signals specifies the signal flags of the thread that shall be cleared. 425 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR. 426 /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS. 427 int32_t osSignalClear (osThreadId thread_id, int32_t signals); 428 429 /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. 430 /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag. 431 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 432 /// \return event flag information or error code. 433 /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS. 434 osEvent osSignalWait (int32_t signals, uint32_t millisec); 435 436 437 // ==== Mutex Management ==== 438 439 /// Define a Mutex. 440 /// \param name name of the mutex object. 441 /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the 442 /// macro body is implementation specific in every CMSIS-RTOS. 443 #if defined (osObjectsExternal) // object is external 444 #define osMutexDef(name) \ 445 extern const osMutexDef_t os_mutex_def_##name 446 #else // define the object 447 #define osMutexDef(name) \ 448 const osMutexDef_t os_mutex_def_##name = { 0 } 449 #endif 450 451 /// Access a Mutex definition. 452 /// \param name name of the mutex object. 453 /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the 454 /// macro body is implementation specific in every CMSIS-RTOS. 455 #define osMutex(name) \ 456 &os_mutex_def_##name 457 458 /// Create and Initialize a Mutex object. 459 /// \param[in] mutex_def mutex definition referenced with \ref osMutex. 460 /// \return mutex ID for reference by other functions or NULL in case of error. 461 /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS. 462 osMutexId osMutexCreate (const osMutexDef_t *mutex_def); 463 464 /// Wait until a Mutex becomes available. 465 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 466 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 467 /// \return status code that indicates the execution status of the function. 468 /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS. 469 osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); 470 471 /// Release a Mutex that was obtained by \ref osMutexWait. 472 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 473 /// \return status code that indicates the execution status of the function. 474 /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS. 475 osStatus osMutexRelease (osMutexId mutex_id); 476 477 /// Delete a Mutex that was created by \ref osMutexCreate. 478 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 479 /// \return status code that indicates the execution status of the function. 480 /// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS. 481 osStatus osMutexDelete (osMutexId mutex_id); 482 483 484 // ==== Semaphore Management Functions ==== 485 486 #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available 487 488 /// Define a Semaphore object. 489 /// \param name name of the semaphore object. 490 /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the 491 /// macro body is implementation specific in every CMSIS-RTOS. 492 #if defined (osObjectsExternal) // object is external 493 #define osSemaphoreDef(name) \ 494 extern const osSemaphoreDef_t os_semaphore_def_##name 495 #else // define the object 496 #define osSemaphoreDef(name) \ 497 const osSemaphoreDef_t os_semaphore_def_##name = { 0 } 498 #endif 499 500 /// Access a Semaphore definition. 501 /// \param name name of the semaphore object. 502 /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the 503 /// macro body is implementation specific in every CMSIS-RTOS. 504 #define osSemaphore(name) \ 505 &os_semaphore_def_##name 506 507 /// Create and Initialize a Semaphore object used for managing resources. 508 /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore. 509 /// \param[in] count number of available resources. 510 /// \return semaphore ID for reference by other functions or NULL in case of error. 511 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS. 512 osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); 513 514 /// Wait until a Semaphore token becomes available. 515 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 516 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 517 /// \return number of available tokens, or -1 in case of incorrect parameters. 518 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS. 519 int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); 520 521 /// Release a Semaphore token. 522 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 523 /// \return status code that indicates the execution status of the function. 524 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS. 525 osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); 526 527 /// Delete a Semaphore that was created by \ref osSemaphoreCreate. 528 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 529 /// \return status code that indicates the execution status of the function. 530 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS. 531 osStatus osSemaphoreDelete (osSemaphoreId semaphore_id); 532 533 #endif // Semaphore available 534 535 536 // ==== Memory Pool Management Functions ==== 537 538 #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available 539 540 /// \brief Define a Memory Pool. 541 /// \param name name of the memory pool. 542 /// \param no maximum number of blocks (objects) in the memory pool. 543 /// \param type data type of a single block (object). 544 /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the 545 /// macro body is implementation specific in every CMSIS-RTOS. 546 #if defined (osObjectsExternal) // object is external 547 #define osPoolDef(name, no, type) \ 548 extern const osPoolDef_t os_pool_def_##name 549 #else // define the object 550 #define osPoolDef(name, no, type) \ 551 K_MEM_SLAB_DEFINE(os_mem_##name, sizeof(type), no, 4); \ 552 const osPoolDef_t os_pool_def_##name = \ 553 { (no), sizeof(type), &os_mem_##name } 554 #endif 555 556 /// \brief Access a Memory Pool definition. 557 /// \param name name of the memory pool 558 /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the 559 /// macro body is implementation specific in every CMSIS-RTOS. 560 #define osPool(name) \ 561 &os_pool_def_##name 562 563 /// Create and Initialize a memory pool. 564 /// \param[in] pool_def memory pool definition referenced with \ref osPool. 565 /// \return memory pool ID for reference by other functions or NULL in case of error. 566 /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS. 567 osPoolId osPoolCreate (const osPoolDef_t *pool_def); 568 569 /// Allocate a memory block from a memory pool. 570 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 571 /// \return address of the allocated memory block or NULL in case of no memory available. 572 /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS. 573 void *osPoolAlloc (osPoolId pool_id); 574 575 /// Allocate a memory block from a memory pool and set memory block to zero. 576 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 577 /// \return address of the allocated memory block or NULL in case of no memory available. 578 /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS. 579 void *osPoolCAlloc (osPoolId pool_id); 580 581 /// Return an allocated memory block back to a specific memory pool. 582 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 583 /// \param[in] block address of the allocated memory block that is returned to the memory pool. 584 /// \return status code that indicates the execution status of the function. 585 /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS. 586 osStatus osPoolFree (osPoolId pool_id, void *block); 587 588 #endif // Memory Pool Management available 589 590 591 // ==== Message Queue Management Functions ==== 592 593 #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available 594 595 /// \brief Create a Message Queue Definition. 596 /// \param name name of the queue. 597 /// \param queue_sz maximum number of messages in the queue. 598 /// \param type data type of a single message element (for debugger). 599 /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the 600 /// macro body is implementation specific in every CMSIS-RTOS. 601 #if defined (osObjectsExternal) // object is external 602 #define osMessageQDef(name, queue_sz, type) \ 603 extern const osMessageQDef_t os_messageQ_def_##name 604 #else // define the object 605 #define osMessageQDef(name, queue_sz, type) \ 606 struct k_msgq msgq_##name; \ 607 static char __aligned(4) buf_##name[queue_sz * sizeof(type)]; \ 608 const osMessageQDef_t os_messageQ_def_##name = \ 609 { (queue_sz), sizeof (type), (buf_##name), (&msgq_##name) } 610 #endif 611 612 /// \brief Access a Message Queue Definition. 613 /// \param name name of the queue 614 /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the 615 /// macro body is implementation specific in every CMSIS-RTOS. 616 #define osMessageQ(name) \ 617 &os_messageQ_def_##name 618 619 /// Create and Initialize a Message Queue. 620 /// \param[in] queue_def queue definition referenced with \ref osMessageQ. 621 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. 622 /// \return message queue ID for reference by other functions or NULL in case of error. 623 /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS. 624 osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id); 625 626 /// Put a Message to a Queue. 627 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. 628 /// \param[in] info message information. 629 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 630 /// \return status code that indicates the execution status of the function. 631 /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS. 632 osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); 633 634 /// Get a Message or Wait for a Message from a Queue. 635 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. 636 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 637 /// \return event information that includes status code. 638 /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS. 639 osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); 640 641 #endif // Message Queues available 642 643 644 // ==== Mail Queue Management Functions ==== 645 646 #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available 647 648 /// \brief Create a Mail Queue Definition. 649 /// \param name name of the queue 650 /// \param queue_sz maximum number of messages in queue 651 /// \param type data type of a single message element 652 /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the 653 /// macro body is implementation specific in every CMSIS-RTOS. 654 #if defined (osObjectsExternal) // object is external 655 #define osMailQDef(name, queue_sz, type) \ 656 extern const osMailQDef_t os_mailQ_def_##name 657 #else // define the object 658 #define osMailQDef(name, queue_sz, type) \ 659 struct k_mbox mbox_##name; \ 660 K_MEM_SLAB_DEFINE(mailq_slab_##name, sizeof(type), queue_sz, 4); \ 661 const osMailQDef_t os_mailQ_def_##name = \ 662 { (queue_sz), sizeof (type), (&mailq_slab_##name), (&mbox_##name) } 663 #endif 664 665 /// \brief Access a Mail Queue Definition. 666 /// \param name name of the queue 667 /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the 668 /// macro body is implementation specific in every CMSIS-RTOS. 669 #define osMailQ(name) \ 670 &os_mailQ_def_##name 671 672 /// Create and Initialize mail queue. 673 /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ 674 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. 675 /// \return mail queue ID for reference by other functions or NULL in case of error. 676 /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS. 677 osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id); 678 679 /// Allocate a memory block from a mail. 680 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 681 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 682 /// \return pointer to memory block that can be filled with mail or NULL in case of error. 683 /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS. 684 void *osMailAlloc (osMailQId queue_id, uint32_t millisec); 685 686 /// Allocate a memory block from a mail and set memory block to zero. 687 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 688 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 689 /// \return pointer to memory block that can be filled with mail or NULL in case of error. 690 /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS. 691 void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); 692 693 /// Put a mail to a queue. 694 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 695 /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc. 696 /// \return status code that indicates the execution status of the function. 697 /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS. 698 osStatus osMailPut (osMailQId queue_id, void *mail); 699 700 /// Get a mail from a queue. 701 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 702 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 703 /// \return event that contains mail information or error code. 704 /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS. 705 osEvent osMailGet (osMailQId queue_id, uint32_t millisec); 706 707 /// Free a memory block from a mail. 708 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 709 /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet. 710 /// \return status code that indicates the execution status of the function. 711 /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS. 712 osStatus osMailFree (osMailQId queue_id, void *mail); 713 714 #endif // Mail Queues available 715 716 717 #ifdef __cplusplus 718 } 719 #endif 720 721 #endif /* ZEPHYR_INCLUDE_CMSIS_RTOS_V1_CMSIS_OS_H_ */ 722