cmsis_os.h 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. /* ----------------------------------------------------------------------
  2. * $Date: 5. February 2013
  3. * $Revision: V1.02
  4. *
  5. * Project: CMSIS-RTOS API
  6. * Title: cmsis_os.h 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. *----------------------------------------------------------------------------
  28. *
  29. * Portions Copyright © 2016 STMicroelectronics International N.V. All rights reserved.
  30. * Portions Copyright (c) 2013 ARM LIMITED
  31. * All rights reserved.
  32. * Redistribution and use in source and binary forms, with or without
  33. * modification, are permitted provided that the following conditions are met:
  34. * - Redistributions of source code must retain the above copyright
  35. * notice, this list of conditions and the following disclaimer.
  36. * - Redistributions in binary form must reproduce the above copyright
  37. * notice, this list of conditions and the following disclaimer in the
  38. * documentation and/or other materials provided with the distribution.
  39. * - Neither the name of ARM nor the names of its contributors may be used
  40. * to endorse or promote products derived from this software without
  41. * specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  44. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  45. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  46. * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  47. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  48. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  49. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  50. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  51. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  53. * POSSIBILITY OF SUCH DAMAGE.
  54. *---------------------------------------------------------------------------*/
  55. /**
  56. ******************************************************************************
  57. * @file cmsis_os.h
  58. * @author MCD Application Team
  59. * @date 13-July-2017
  60. * @brief Header of cmsis_os.c
  61. * A new set of APIs are added in addition to existing ones, these APIs
  62. * are specific to FreeRTOS.
  63. ******************************************************************************
  64. * @attention
  65. *
  66. * Redistribution and use in source and binary forms, with or without
  67. * modification, are permitted, provided that the following conditions are met:
  68. *
  69. * 1. Redistribution of source code must retain the above copyright notice,
  70. * this list of conditions and the following disclaimer.
  71. * 2. Redistributions in binary form must reproduce the above copyright notice,
  72. * this list of conditions and the following disclaimer in the documentation
  73. * and/or other materials provided with the distribution.
  74. * 3. Neither the name of STMicroelectronics nor the names of other
  75. * contributors to this software may be used to endorse or promote products
  76. * derived from this software without specific written permission.
  77. * 4. This software, including modifications and/or derivative works of this
  78. * software, must execute solely and exclusively on microcontroller or
  79. * microprocessor devices manufactured by or for STMicroelectronics.
  80. * 5. Redistribution and use of this software other than as permitted under
  81. * this license is void and will automatically terminate your rights under
  82. * this license.
  83. *
  84. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  85. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  86. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  87. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  88. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  89. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  90. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  91. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  92. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  93. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  94. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  95. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  96. *
  97. ******************************************************************************
  98. */
  99. #include "FreeRTOS.h"
  100. #include "task.h"
  101. #include "timers.h"
  102. #include "queue.h"
  103. #include "semphr.h"
  104. #include "event_groups.h"
  105. /**
  106. \page cmsis_os_h Header File Template: cmsis_os.h
  107. The file \b cmsis_os.h is a template header file for a CMSIS-RTOS compliant Real-Time Operating System (RTOS).
  108. Each RTOS that is compliant with CMSIS-RTOS shall provide a specific \b cmsis_os.h header file that represents
  109. its implementation.
  110. The file cmsis_os.h contains:
  111. - CMSIS-RTOS API function definitions
  112. - struct definitions for parameters and return types
  113. - status and priority values used by CMSIS-RTOS API functions
  114. - macros for defining threads and other kernel objects
  115. <b>Name conventions and header file modifications</b>
  116. All definitions are prefixed with \b os to give an unique name space for CMSIS-RTOS functions.
  117. Definitions that are prefixed \b os_ are not used in the application code but local to this header file.
  118. All definitions and functions that belong to a module are grouped and have a common prefix, i.e. \b osThread.
  119. Definitions that are marked with <b>CAN BE CHANGED</b> can be adapted towards the needs of the actual CMSIS-RTOS implementation.
  120. These definitions can be specific to the underlying RTOS kernel.
  121. Definitions that are marked with <b>MUST REMAIN UNCHANGED</b> cannot be altered. Otherwise the CMSIS-RTOS implementation is no longer
  122. compliant to the standard. Note that some functions are optional and need not to be provided by every CMSIS-RTOS implementation.
  123. <b>Function calls from interrupt service routines</b>
  124. The following CMSIS-RTOS functions can be called from threads and interrupt service routines (ISR):
  125. - \ref osSignalSet
  126. - \ref osSemaphoreRelease
  127. - \ref osPoolAlloc, \ref osPoolCAlloc, \ref osPoolFree
  128. - \ref osMessagePut, \ref osMessageGet
  129. - \ref osMailAlloc, \ref osMailCAlloc, \ref osMailGet, \ref osMailPut, \ref osMailFree
  130. Functions that cannot be called from an ISR are verifying the interrupt status and return in case that they are called
  131. from an ISR context the status code \b osErrorISR. In some implementations this condition might be caught using the HARD FAULT vector.
  132. Some CMSIS-RTOS implementations support CMSIS-RTOS function calls from multiple ISR at the same time.
  133. If this is impossible, the CMSIS-RTOS rejects calls by nested ISR functions with the status code \b osErrorISRRecursive.
  134. <b>Define and reference object definitions</b>
  135. With <b>\#define osObjectsExternal</b> objects are defined as external symbols. This allows to create a consistent header file
  136. that is used throughout a project as shown below:
  137. <i>Header File</i>
  138. \code
  139. #include <cmsis_os.h> // CMSIS RTOS header file
  140. // Thread definition
  141. extern void thread_sample (void const *argument); // function prototype
  142. osThreadDef (thread_sample, osPriorityBelowNormal, 1, 100);
  143. // Pool definition
  144. osPoolDef(MyPool, 10, long);
  145. \endcode
  146. This header file defines all objects when included in a C/C++ source file. When <b>\#define osObjectsExternal</b> is
  147. present before the header file, the objects are defined as external symbols. A single consistent header file can therefore be
  148. used throughout the whole project.
  149. <i>Example</i>
  150. \code
  151. #include "osObjects.h" // Definition of the CMSIS-RTOS objects
  152. \endcode
  153. \code
  154. #define osObjectExternal // Objects will be defined as external symbols
  155. #include "osObjects.h" // Reference to the CMSIS-RTOS objects
  156. \endcode
  157. */
  158. #ifndef _CMSIS_OS_H
  159. #define _CMSIS_OS_H
  160. /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version.
  161. #define osCMSIS 0x10002 ///< API version (main [31:16] .sub [15:0])
  162. /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number.
  163. #define osCMSIS_KERNEL 0x10000 ///< RTOS identification and version (main [31:16] .sub [15:0])
  164. /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS.
  165. #define osKernelSystemId "KERNEL V1.00" ///< RTOS identification string
  166. /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS.
  167. #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available
  168. #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available
  169. #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available
  170. #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available
  171. #define osFeature_Signals 8 ///< maximum number of Signal Flags available per thread
  172. #define osFeature_Semaphore 1 ///< osFeature_Semaphore function: 1=available, 0=not available
  173. #define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available
  174. #define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available
  175. #ifdef __cplusplus
  176. extern "C"
  177. {
  178. #endif
  179. // ==== Enumeration, structures, defines ====
  180. /// Priority used for thread control.
  181. /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS.
  182. typedef enum {
  183. osPriorityIdle = -3, ///< priority: idle (lowest)
  184. osPriorityLow = -2, ///< priority: low
  185. osPriorityBelowNormal = -1, ///< priority: below normal
  186. osPriorityNormal = 0, ///< priority: normal (default)
  187. osPriorityAboveNormal = +1, ///< priority: above normal
  188. osPriorityHigh = +2, ///< priority: high
  189. osPriorityRealtime = +3, ///< priority: realtime (highest)
  190. osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
  191. } osPriority;
  192. /// Timeout value.
  193. /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS.
  194. #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value
  195. /// Status code values returned by CMSIS-RTOS functions.
  196. /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS.
  197. typedef enum {
  198. osOK = 0, ///< function completed; no error or event occurred.
  199. osEventSignal = 0x08, ///< function completed; signal event occurred.
  200. osEventMessage = 0x10, ///< function completed; message event occurred.
  201. osEventMail = 0x20, ///< function completed; mail event occurred.
  202. osEventTimeout = 0x40, ///< function completed; timeout occurred.
  203. osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object.
  204. osErrorResource = 0x81, ///< resource not available: a specified resource was not available.
  205. osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period.
  206. osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines.
  207. osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object.
  208. osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority.
  209. osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation.
  210. osErrorValue = 0x86, ///< value of a parameter is out of range.
  211. osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits.
  212. os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
  213. } osStatus;
  214. #if ( INCLUDE_eTaskGetState == 1 )
  215. /* Thread state returned by osThreadGetState */
  216. typedef enum {
  217. osThreadRunning = 0x0, /* A thread is querying the state of itself, so must be running. */
  218. osThreadReady = 0x1 , /* The thread being queried is in a read or pending ready list. */
  219. osThreadBlocked = 0x2, /* The thread being queried is in the Blocked state. */
  220. osThreadSuspended = 0x3, /* The thread being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
  221. osThreadDeleted = 0x4, /* The thread being queried has been deleted, but its TCB has not yet been freed. */
  222. osThreadError = 0x7FFFFFFF
  223. } osThreadState;
  224. #endif /* INCLUDE_eTaskGetState */
  225. /// Timer type value for the timer definition.
  226. /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS.
  227. typedef enum {
  228. osTimerOnce = 0, ///< one-shot timer
  229. osTimerPeriodic = 1 ///< repeating timer
  230. } os_timer_type;
  231. /// Entry point of a thread.
  232. /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS.
  233. typedef void (*os_pthread) (void const *argument);
  234. /// Entry point of a timer call back function.
  235. /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS.
  236. typedef void (*os_ptimer) (void const *argument);
  237. // >>> the following data type definitions may shall adapted towards a specific RTOS
  238. /// Thread ID identifies the thread (pointer to a thread control block).
  239. /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS.
  240. typedef TaskHandle_t osThreadId;
  241. /// Timer ID identifies the timer (pointer to a timer control block).
  242. /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS.
  243. typedef TimerHandle_t osTimerId;
  244. /// Mutex ID identifies the mutex (pointer to a mutex control block).
  245. /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS.
  246. typedef SemaphoreHandle_t osMutexId;
  247. /// Semaphore ID identifies the semaphore (pointer to a semaphore control block).
  248. /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS.
  249. typedef SemaphoreHandle_t osSemaphoreId;
  250. /// Pool ID identifies the memory pool (pointer to a memory pool control block).
  251. /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS.
  252. typedef struct os_pool_cb *osPoolId;
  253. /// Message ID identifies the message queue (pointer to a message queue control block).
  254. /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS.
  255. typedef QueueHandle_t osMessageQId;
  256. /// Mail ID identifies the mail queue (pointer to a mail queue control block).
  257. /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS.
  258. typedef struct os_mailQ_cb *osMailQId;
  259. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  260. typedef StaticTask_t osStaticThreadDef_t;
  261. typedef StaticTimer_t osStaticTimerDef_t;
  262. typedef StaticSemaphore_t osStaticMutexDef_t;
  263. typedef StaticSemaphore_t osStaticSemaphoreDef_t;
  264. typedef StaticQueue_t osStaticMessageQDef_t;
  265. #endif
  266. /// Thread Definition structure contains startup information of a thread.
  267. /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
  268. typedef struct os_thread_def {
  269. char *name; ///< Thread name
  270. os_pthread pthread; ///< start address of thread function
  271. osPriority tpriority; ///< initial thread priority
  272. uint32_t instances; ///< maximum number of instances of that thread function
  273. uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
  274. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  275. uint32_t *buffer; ///< stack buffer for static allocation; NULL for dynamic allocation
  276. osStaticThreadDef_t *controlblock; ///< control block to hold thread's data for static allocation; NULL for dynamic allocation
  277. #endif
  278. } osThreadDef_t;
  279. /// Timer Definition structure contains timer parameters.
  280. /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
  281. typedef struct os_timer_def {
  282. os_ptimer ptimer; ///< start address of a timer function
  283. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  284. osStaticTimerDef_t *controlblock; ///< control block to hold timer's data for static allocation; NULL for dynamic allocation
  285. #endif
  286. } osTimerDef_t;
  287. /// Mutex Definition structure contains setup information for a mutex.
  288. /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS.
  289. typedef struct os_mutex_def {
  290. uint32_t dummy; ///< dummy value.
  291. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  292. osStaticMutexDef_t *controlblock; ///< control block for static allocation; NULL for dynamic allocation
  293. #endif
  294. } osMutexDef_t;
  295. /// Semaphore Definition structure contains setup information for a semaphore.
  296. /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS.
  297. typedef struct os_semaphore_def {
  298. uint32_t dummy; ///< dummy value.
  299. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  300. osStaticSemaphoreDef_t *controlblock; ///< control block for static allocation; NULL for dynamic allocation
  301. #endif
  302. } osSemaphoreDef_t;
  303. /// Definition structure for memory block allocation.
  304. /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS.
  305. typedef struct os_pool_def {
  306. uint32_t pool_sz; ///< number of items (elements) in the pool
  307. uint32_t item_sz; ///< size of an item
  308. void *pool; ///< pointer to memory for pool
  309. } osPoolDef_t;
  310. /// Definition structure for message queue.
  311. /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
  312. typedef struct os_messageQ_def {
  313. uint32_t queue_sz; ///< number of elements in the queue
  314. uint32_t item_sz; ///< size of an item
  315. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  316. uint8_t *buffer; ///< buffer for static allocation; NULL for dynamic allocation
  317. osStaticMessageQDef_t *controlblock; ///< control block to hold queue's data for static allocation; NULL for dynamic allocation
  318. #endif
  319. //void *pool; ///< memory array for messages
  320. } osMessageQDef_t;
  321. /// Definition structure for mail queue.
  322. /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS.
  323. typedef struct os_mailQ_def {
  324. uint32_t queue_sz; ///< number of elements in the queue
  325. uint32_t item_sz; ///< size of an item
  326. struct os_mailQ_cb **cb;
  327. } osMailQDef_t;
  328. /// Event structure contains detailed information about an event.
  329. /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS.
  330. /// However the struct may be extended at the end.
  331. typedef struct {
  332. osStatus status; ///< status code: event or error information
  333. union {
  334. uint32_t v; ///< message as 32-bit value
  335. void *p; ///< message or mail as void pointer
  336. int32_t signals; ///< signal flags
  337. } value; ///< event value
  338. union {
  339. osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
  340. osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
  341. } def; ///< event definition
  342. } osEvent;
  343. // ==== Kernel Control Functions ====
  344. /// Initialize the RTOS Kernel for creating objects.
  345. /// \return status code that indicates the execution status of the function.
  346. /// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS.
  347. osStatus osKernelInitialize (void);
  348. /// Start the RTOS Kernel.
  349. /// \return status code that indicates the execution status of the function.
  350. /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS.
  351. osStatus osKernelStart (void);
  352. /// Check if the RTOS kernel is already started.
  353. /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS.
  354. /// \return 0 RTOS is not started, 1 RTOS is started.
  355. int32_t osKernelRunning(void);
  356. #if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available
  357. /// Get the RTOS kernel system timer counter
  358. /// \note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS.
  359. /// \return RTOS kernel system timer as 32-bit value
  360. uint32_t osKernelSysTick (void);
  361. /// The RTOS kernel system timer frequency in Hz
  362. /// \note Reflects the system timer setting and is typically defined in a configuration file.
  363. #define osKernelSysTickFrequency (configTICK_RATE_HZ)
  364. /// Convert a microseconds value to a RTOS kernel system timer value.
  365. /// \param microsec time value in microseconds.
  366. /// \return time value normalized to the \ref osKernelSysTickFrequency
  367. #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000)
  368. #endif // System Timer available
  369. // ==== Thread Management ====
  370. /// Create a Thread Definition with function, priority, and stack requirements.
  371. /// \param name name of the thread function.
  372. /// \param priority initial priority of the thread function.
  373. /// \param instances number of possible thread instances.
  374. /// \param stacksz stack size (in bytes) requirements for the thread function.
  375. /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the
  376. /// macro body is implementation specific in every CMSIS-RTOS.
  377. #if defined (osObjectsExternal) // object is external
  378. #define osThreadDef(name, thread, priority, instances, stacksz) \
  379. extern const osThreadDef_t os_thread_def_##name
  380. #else // define the object
  381. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  382. #define osThreadDef(name, thread, priority, instances, stacksz) \
  383. const osThreadDef_t os_thread_def_##name = \
  384. { #name, (thread), (priority), (instances), (stacksz), NULL, NULL }
  385. #define osThreadStaticDef(name, thread, priority, instances, stacksz, buffer, control) \
  386. const osThreadDef_t os_thread_def_##name = \
  387. { #name, (thread), (priority), (instances), (stacksz), (buffer), (control) }
  388. #else //configSUPPORT_STATIC_ALLOCATION == 0
  389. #define osThreadDef(name, thread, priority, instances, stacksz) \
  390. const osThreadDef_t os_thread_def_##name = \
  391. { #name, (thread), (priority), (instances), (stacksz)}
  392. #endif
  393. #endif
  394. /// Access a Thread definition.
  395. /// \param name name of the thread definition object.
  396. /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the
  397. /// macro body is implementation specific in every CMSIS-RTOS.
  398. #define osThread(name) \
  399. &os_thread_def_##name
  400. /// Create a thread and add it to Active Threads and set it to state READY.
  401. /// \param[in] thread_def thread definition referenced with \ref osThread.
  402. /// \param[in] argument pointer that is passed to the thread function as start argument.
  403. /// \return thread ID for reference by other functions or NULL in case of error.
  404. /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
  405. osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);
  406. /// Return the thread ID of the current running thread.
  407. /// \return thread ID for reference by other functions or NULL in case of error.
  408. /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS.
  409. osThreadId osThreadGetId (void);
  410. /// Terminate execution of a thread and remove it from Active Threads.
  411. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  412. /// \return status code that indicates the execution status of the function.
  413. /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS.
  414. osStatus osThreadTerminate (osThreadId thread_id);
  415. /// Pass control to next thread that is in state \b READY.
  416. /// \return status code that indicates the execution status of the function.
  417. /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS.
  418. osStatus osThreadYield (void);
  419. /// Change priority of an active thread.
  420. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  421. /// \param[in] priority new priority value for the thread function.
  422. /// \return status code that indicates the execution status of the function.
  423. /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS.
  424. osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
  425. /// Get current priority of an active thread.
  426. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  427. /// \return current priority value of the thread function.
  428. /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS.
  429. osPriority osThreadGetPriority (osThreadId thread_id);
  430. // ==== Generic Wait Functions ====
  431. /// Wait for Timeout (Time Delay).
  432. /// \param[in] millisec time delay value
  433. /// \return status code that indicates the execution status of the function.
  434. osStatus osDelay (uint32_t millisec);
  435. #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
  436. /// Wait for Signal, Message, Mail, or Timeout.
  437. /// \param[in] millisec timeout value or 0 in case of no time-out
  438. /// \return event that contains signal, message, or mail information or error code.
  439. /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS.
  440. osEvent osWait (uint32_t millisec);
  441. #endif // Generic Wait available
  442. // ==== Timer Management Functions ====
  443. /// Define a Timer object.
  444. /// \param name name of the timer object.
  445. /// \param function name of the timer call back function.
  446. /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the
  447. /// macro body is implementation specific in every CMSIS-RTOS.
  448. #if defined (osObjectsExternal) // object is external
  449. #define osTimerDef(name, function) \
  450. extern const osTimerDef_t os_timer_def_##name
  451. #else // define the object
  452. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  453. #define osTimerDef(name, function) \
  454. const osTimerDef_t os_timer_def_##name = \
  455. { (function), NULL }
  456. #define osTimerStaticDef(name, function, control) \
  457. const osTimerDef_t os_timer_def_##name = \
  458. { (function), (control) }
  459. #else //configSUPPORT_STATIC_ALLOCATION == 0
  460. #define osTimerDef(name, function) \
  461. const osTimerDef_t os_timer_def_##name = \
  462. { (function) }
  463. #endif
  464. #endif
  465. /// Access a Timer definition.
  466. /// \param name name of the timer object.
  467. /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the
  468. /// macro body is implementation specific in every CMSIS-RTOS.
  469. #define osTimer(name) \
  470. &os_timer_def_##name
  471. /// Create a timer.
  472. /// \param[in] timer_def timer object referenced with \ref osTimer.
  473. /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
  474. /// \param[in] argument argument to the timer call back function.
  475. /// \return timer ID for reference by other functions or NULL in case of error.
  476. /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS.
  477. osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);
  478. /// Start or restart a timer.
  479. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
  480. /// \param[in] millisec time delay value of the timer.
  481. /// \return status code that indicates the execution status of the function.
  482. /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
  483. osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
  484. /// Stop the timer.
  485. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
  486. /// \return status code that indicates the execution status of the function.
  487. /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
  488. osStatus osTimerStop (osTimerId timer_id);
  489. /// Delete a timer that was created by \ref osTimerCreate.
  490. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
  491. /// \return status code that indicates the execution status of the function.
  492. /// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
  493. osStatus osTimerDelete (osTimerId timer_id);
  494. // ==== Signal Management ====
  495. /// Set the specified Signal Flags of an active thread.
  496. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  497. /// \param[in] signals specifies the signal flags of the thread that should be set.
  498. /// \return osOK if successful, osErrorOS if failed.
  499. /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
  500. int32_t osSignalSet (osThreadId thread_id, int32_t signals);
  501. /// Clear the specified Signal Flags of an active thread.
  502. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  503. /// \param[in] signals specifies the signal flags of the thread that shall be cleared.
  504. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
  505. /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS.
  506. int32_t osSignalClear (osThreadId thread_id, int32_t signals);
  507. /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
  508. /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
  509. /// \param[in] millisec timeout value or 0 in case of no time-out.
  510. /// \return event flag information or error code.
  511. /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
  512. osEvent osSignalWait (int32_t signals, uint32_t millisec);
  513. // ==== Mutex Management ====
  514. /// Define a Mutex.
  515. /// \param name name of the mutex object.
  516. /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the
  517. /// macro body is implementation specific in every CMSIS-RTOS.
  518. #if defined (osObjectsExternal) // object is external
  519. #define osMutexDef(name) \
  520. extern const osMutexDef_t os_mutex_def_##name
  521. #else // define the object
  522. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  523. #define osMutexDef(name) \
  524. const osMutexDef_t os_mutex_def_##name = { 0, NULL }
  525. #define osMutexStaticDef(name, control) \
  526. const osMutexDef_t os_mutex_def_##name = { 0, (control) }
  527. #else //configSUPPORT_STATIC_ALLOCATION == 0
  528. #define osMutexDef(name) \
  529. const osMutexDef_t os_mutex_def_##name = { 0 }
  530. #endif
  531. #endif
  532. /// Access a Mutex definition.
  533. /// \param name name of the mutex object.
  534. /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the
  535. /// macro body is implementation specific in every CMSIS-RTOS.
  536. #define osMutex(name) \
  537. &os_mutex_def_##name
  538. /// Create and Initialize a Mutex object.
  539. /// \param[in] mutex_def mutex definition referenced with \ref osMutex.
  540. /// \return mutex ID for reference by other functions or NULL in case of error.
  541. /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS.
  542. osMutexId osMutexCreate (const osMutexDef_t *mutex_def);
  543. /// Wait until a Mutex becomes available.
  544. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
  545. /// \param[in] millisec timeout value or 0 in case of no time-out.
  546. /// \return status code that indicates the execution status of the function.
  547. /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS.
  548. osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
  549. /// Release a Mutex that was obtained by \ref osMutexWait.
  550. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
  551. /// \return status code that indicates the execution status of the function.
  552. /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
  553. osStatus osMutexRelease (osMutexId mutex_id);
  554. /// Delete a Mutex that was created by \ref osMutexCreate.
  555. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
  556. /// \return status code that indicates the execution status of the function.
  557. /// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS.
  558. osStatus osMutexDelete (osMutexId mutex_id);
  559. // ==== Semaphore Management Functions ====
  560. #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available
  561. /// Define a Semaphore object.
  562. /// \param name name of the semaphore object.
  563. /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the
  564. /// macro body is implementation specific in every CMSIS-RTOS.
  565. #if defined (osObjectsExternal) // object is external
  566. #define osSemaphoreDef(name) \
  567. extern const osSemaphoreDef_t os_semaphore_def_##name
  568. #else // define the object
  569. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  570. #define osSemaphoreDef(name) \
  571. const osSemaphoreDef_t os_semaphore_def_##name = { 0, NULL }
  572. #define osSemaphoreStaticDef(name, control) \
  573. const osSemaphoreDef_t os_semaphore_def_##name = { 0, (control) }
  574. #else //configSUPPORT_STATIC_ALLOCATION == 0
  575. #define osSemaphoreDef(name) \
  576. const osSemaphoreDef_t os_semaphore_def_##name = { 0 }
  577. #endif
  578. #endif
  579. /// Access a Semaphore definition.
  580. /// \param name name of the semaphore object.
  581. /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the
  582. /// macro body is implementation specific in every CMSIS-RTOS.
  583. #define osSemaphore(name) \
  584. &os_semaphore_def_##name
  585. /// Create and Initialize a Semaphore object used for managing resources.
  586. /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
  587. /// \param[in] count number of available resources.
  588. /// \return semaphore ID for reference by other functions or NULL in case of error.
  589. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
  590. osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);
  591. /// Wait until a Semaphore token becomes available.
  592. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
  593. /// \param[in] millisec timeout value or 0 in case of no time-out.
  594. /// \return number of available tokens, or -1 in case of incorrect parameters.
  595. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
  596. int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
  597. /// Release a Semaphore token.
  598. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
  599. /// \return status code that indicates the execution status of the function.
  600. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS.
  601. osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
  602. /// Delete a Semaphore that was created by \ref osSemaphoreCreate.
  603. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
  604. /// \return status code that indicates the execution status of the function.
  605. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS.
  606. osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
  607. #endif // Semaphore available
  608. // ==== Memory Pool Management Functions ====
  609. #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available
  610. /// \brief Define a Memory Pool.
  611. /// \param name name of the memory pool.
  612. /// \param no maximum number of blocks (objects) in the memory pool.
  613. /// \param type data type of a single block (object).
  614. /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the
  615. /// macro body is implementation specific in every CMSIS-RTOS.
  616. #if defined (osObjectsExternal) // object is external
  617. #define osPoolDef(name, no, type) \
  618. extern const osPoolDef_t os_pool_def_##name
  619. #else // define the object
  620. #define osPoolDef(name, no, type) \
  621. const osPoolDef_t os_pool_def_##name = \
  622. { (no), sizeof(type), NULL }
  623. #endif
  624. /// \brief Access a Memory Pool definition.
  625. /// \param name name of the memory pool
  626. /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the
  627. /// macro body is implementation specific in every CMSIS-RTOS.
  628. #define osPool(name) \
  629. &os_pool_def_##name
  630. /// Create and Initialize a memory pool.
  631. /// \param[in] pool_def memory pool definition referenced with \ref osPool.
  632. /// \return memory pool ID for reference by other functions or NULL in case of error.
  633. /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS.
  634. osPoolId osPoolCreate (const osPoolDef_t *pool_def);
  635. /// Allocate a memory block from a memory pool.
  636. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  637. /// \return address of the allocated memory block or NULL in case of no memory available.
  638. /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS.
  639. void *osPoolAlloc (osPoolId pool_id);
  640. /// Allocate a memory block from a memory pool and set memory block to zero.
  641. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  642. /// \return address of the allocated memory block or NULL in case of no memory available.
  643. /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS.
  644. void *osPoolCAlloc (osPoolId pool_id);
  645. /// Return an allocated memory block back to a specific memory pool.
  646. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  647. /// \param[in] block address of the allocated memory block that is returned to the memory pool.
  648. /// \return status code that indicates the execution status of the function.
  649. /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS.
  650. osStatus osPoolFree (osPoolId pool_id, void *block);
  651. #endif // Memory Pool Management available
  652. // ==== Message Queue Management Functions ====
  653. #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available
  654. /// \brief Create a Message Queue Definition.
  655. /// \param name name of the queue.
  656. /// \param queue_sz maximum number of messages in the queue.
  657. /// \param type data type of a single message element (for debugger).
  658. /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the
  659. /// macro body is implementation specific in every CMSIS-RTOS.
  660. #if defined (osObjectsExternal) // object is external
  661. #define osMessageQDef(name, queue_sz, type) \
  662. extern const osMessageQDef_t os_messageQ_def_##name
  663. #else // define the object
  664. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  665. #define osMessageQDef(name, queue_sz, type) \
  666. const osMessageQDef_t os_messageQ_def_##name = \
  667. { (queue_sz), sizeof (type), NULL, NULL }
  668. #define osMessageQStaticDef(name, queue_sz, type, buffer, control) \
  669. const osMessageQDef_t os_messageQ_def_##name = \
  670. { (queue_sz), sizeof (type) , (buffer), (control)}
  671. #else //configSUPPORT_STATIC_ALLOCATION == 1
  672. #define osMessageQDef(name, queue_sz, type) \
  673. const osMessageQDef_t os_messageQ_def_##name = \
  674. { (queue_sz), sizeof (type) }
  675. #endif
  676. #endif
  677. /// \brief Access a Message Queue Definition.
  678. /// \param name name of the queue
  679. /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the
  680. /// macro body is implementation specific in every CMSIS-RTOS.
  681. #define osMessageQ(name) \
  682. &os_messageQ_def_##name
  683. /// Create and Initialize a Message Queue.
  684. /// \param[in] queue_def queue definition referenced with \ref osMessageQ.
  685. /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
  686. /// \return message queue ID for reference by other functions or NULL in case of error.
  687. /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS.
  688. osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);
  689. /// Put a Message to a Queue.
  690. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
  691. /// \param[in] info message information.
  692. /// \param[in] millisec timeout value or 0 in case of no time-out.
  693. /// \return status code that indicates the execution status of the function.
  694. /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
  695. osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
  696. /// Get a Message or Wait for a Message from a Queue.
  697. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
  698. /// \param[in] millisec timeout value or 0 in case of no time-out.
  699. /// \return event information that includes status code.
  700. /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
  701. osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
  702. #endif // Message Queues available
  703. // ==== Mail Queue Management Functions ====
  704. #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available
  705. /// \brief Create a Mail Queue Definition.
  706. /// \param name name of the queue
  707. /// \param queue_sz maximum number of messages in queue
  708. /// \param type data type of a single message element
  709. /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the
  710. /// macro body is implementation specific in every CMSIS-RTOS.
  711. #if defined (osObjectsExternal) // object is external
  712. #define osMailQDef(name, queue_sz, type) \
  713. extern struct os_mailQ_cb *os_mailQ_cb_##name \
  714. extern osMailQDef_t os_mailQ_def_##name
  715. #else // define the object
  716. #define osMailQDef(name, queue_sz, type) \
  717. struct os_mailQ_cb *os_mailQ_cb_##name; \
  718. const osMailQDef_t os_mailQ_def_##name = \
  719. { (queue_sz), sizeof (type), (&os_mailQ_cb_##name) }
  720. #endif
  721. /// \brief Access a Mail Queue Definition.
  722. /// \param name name of the queue
  723. /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the
  724. /// macro body is implementation specific in every CMSIS-RTOS.
  725. #define osMailQ(name) \
  726. &os_mailQ_def_##name
  727. /// Create and Initialize mail queue.
  728. /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ
  729. /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
  730. /// \return mail queue ID for reference by other functions or NULL in case of error.
  731. /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS.
  732. osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);
  733. /// Allocate a memory block from a mail.
  734. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  735. /// \param[in] millisec timeout value or 0 in case of no time-out
  736. /// \return pointer to memory block that can be filled with mail or NULL in case of error.
  737. /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS.
  738. void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
  739. /// Allocate a memory block from a mail and set memory block to zero.
  740. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  741. /// \param[in] millisec timeout value or 0 in case of no time-out
  742. /// \return pointer to memory block that can be filled with mail or NULL in case of error.
  743. /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS.
  744. void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
  745. /// Put a mail to a queue.
  746. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  747. /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
  748. /// \return status code that indicates the execution status of the function.
  749. /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
  750. osStatus osMailPut (osMailQId queue_id, void *mail);
  751. /// Get a mail from a queue.
  752. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  753. /// \param[in] millisec timeout value or 0 in case of no time-out
  754. /// \return event that contains mail information or error code.
  755. /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS.
  756. osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
  757. /// Free a memory block from a mail.
  758. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  759. /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet.
  760. /// \return status code that indicates the execution status of the function.
  761. /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS.
  762. osStatus osMailFree (osMailQId queue_id, void *mail);
  763. #endif // Mail Queues available
  764. /*************************** Additional specific APIs to Free RTOS ************/
  765. /**
  766. * @brief Handles the tick increment
  767. * @param none.
  768. * @retval none.
  769. */
  770. void osSystickHandler(void);
  771. #if ( INCLUDE_eTaskGetState == 1 )
  772. /**
  773. * @brief Obtain the state of any thread.
  774. * @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  775. * @retval the stae of the thread, states are encoded by the osThreadState enumerated type.
  776. */
  777. osThreadState osThreadGetState(osThreadId thread_id);
  778. #endif /* INCLUDE_eTaskGetState */
  779. #if ( INCLUDE_eTaskGetState == 1 )
  780. /**
  781. * @brief Check if a thread is already suspended or not.
  782. * @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  783. * @retval status code that indicates the execution status of the function.
  784. */
  785. osStatus osThreadIsSuspended(osThreadId thread_id);
  786. #endif /* INCLUDE_eTaskGetState */
  787. /**
  788. * @brief Suspend execution of a thread.
  789. * @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  790. * @retval status code that indicates the execution status of the function.
  791. */
  792. osStatus osThreadSuspend (osThreadId thread_id);
  793. /**
  794. * @brief Resume execution of a suspended thread.
  795. * @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  796. * @retval status code that indicates the execution status of the function.
  797. */
  798. osStatus osThreadResume (osThreadId thread_id);
  799. /**
  800. * @brief Suspend execution of a all active threads.
  801. * @retval status code that indicates the execution status of the function.
  802. */
  803. osStatus osThreadSuspendAll (void);
  804. /**
  805. * @brief Resume execution of a all suspended threads.
  806. * @retval status code that indicates the execution status of the function.
  807. */
  808. osStatus osThreadResumeAll (void);
  809. /**
  810. * @brief Delay a task until a specified time
  811. * @param PreviousWakeTime Pointer to a variable that holds the time at which the
  812. * task was last unblocked. PreviousWakeTime must be initialised with the current time
  813. * prior to its first use (PreviousWakeTime = osKernelSysTick() )
  814. * @param millisec time delay value
  815. * @retval status code that indicates the execution status of the function.
  816. */
  817. osStatus osDelayUntil (uint32_t *PreviousWakeTime, uint32_t millisec);
  818. /**
  819. * @brief Abort the delay for a specific thread
  820. * @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId
  821. * @retval status code that indicates the execution status of the function.
  822. */
  823. osStatus osAbortDelay(osThreadId thread_id);
  824. /**
  825. * @brief Lists all the current threads, along with their current state
  826. * and stack usage high water mark.
  827. * @param buffer A buffer into which the above mentioned details
  828. * will be written
  829. * @retval status code that indicates the execution status of the function.
  830. */
  831. osStatus osThreadList (uint8_t *buffer);
  832. /**
  833. * @brief Receive an item from a queue without removing the item from the queue.
  834. * @param queue_id message queue ID obtained with \ref osMessageCreate.
  835. * @param millisec timeout value or 0 in case of no time-out.
  836. * @retval event information that includes status code.
  837. */
  838. osEvent osMessagePeek (osMessageQId queue_id, uint32_t millisec);
  839. /**
  840. * @brief Get the number of messaged stored in a queue.
  841. * @param queue_id message queue ID obtained with \ref osMessageCreate.
  842. * @retval number of messages stored in a queue.
  843. */
  844. uint32_t osMessageWaiting(osMessageQId queue_id);
  845. /**
  846. * @brief Get the available space in a message queue.
  847. * @param queue_id message queue ID obtained with \ref osMessageCreate.
  848. * @retval available space in a message queue.
  849. */
  850. uint32_t osMessageAvailableSpace(osMessageQId queue_id);
  851. /**
  852. * @brief Delete a Message Queue
  853. * @param queue_id message queue ID obtained with \ref osMessageCreate.
  854. * @retval status code that indicates the execution status of the function.
  855. */
  856. osStatus osMessageDelete (osMessageQId queue_id);
  857. /**
  858. * @brief Create and Initialize a Recursive Mutex
  859. * @param mutex_def mutex definition referenced with \ref osMutex.
  860. * @retval mutex ID for reference by other functions or NULL in case of error..
  861. */
  862. osMutexId osRecursiveMutexCreate (const osMutexDef_t *mutex_def);
  863. /**
  864. * @brief Release a Recursive Mutex
  865. * @param mutex_id mutex ID obtained by \ref osRecursiveMutexCreate.
  866. * @retval status code that indicates the execution status of the function.
  867. */
  868. osStatus osRecursiveMutexRelease (osMutexId mutex_id);
  869. /**
  870. * @brief Release a Recursive Mutex
  871. * @param mutex_id mutex ID obtained by \ref osRecursiveMutexCreate.
  872. * @param millisec timeout value or 0 in case of no time-out.
  873. * @retval status code that indicates the execution status of the function.
  874. */
  875. osStatus osRecursiveMutexWait (osMutexId mutex_id, uint32_t millisec);
  876. /**
  877. * @brief Returns the current count value of a counting semaphore
  878. * @param semaphore_id semaphore_id ID obtained by \ref osSemaphoreCreate.
  879. * @retval count value
  880. */
  881. uint32_t osSemaphoreGetCount(osSemaphoreId semaphore_id);
  882. #ifdef __cplusplus
  883. }
  884. #endif
  885. #endif // _CMSIS_OS_H