cmsis_os2.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * ----------------------------------------------------------------------
  19. *
  20. * $Date: 12. June 2020
  21. * $Revision: V2.1.3
  22. *
  23. * Project: CMSIS-RTOS2 API
  24. * Title: cmsis_os2.h header file
  25. *
  26. * Version 2.1.3
  27. * Additional functions allowed to be called from Interrupt Service Routines:
  28. * - osThreadGetId
  29. * Version 2.1.2
  30. * Additional functions allowed to be called from Interrupt Service Routines:
  31. * - osKernelGetInfo, osKernelGetState
  32. * Version 2.1.1
  33. * Additional functions allowed to be called from Interrupt Service Routines:
  34. * - osKernelGetTickCount, osKernelGetTickFreq
  35. * Changed Kernel Tick type to uint32_t:
  36. * - updated: osKernelGetTickCount, osDelayUntil
  37. * Version 2.1.0
  38. * Support for critical and uncritical sections (nesting safe):
  39. * - updated: osKernelLock, osKernelUnlock
  40. * - added: osKernelRestoreLock
  41. * Updated Thread and Event Flags:
  42. * - changed flags parameter and return type from int32_t to uint32_t
  43. * Version 2.0.0
  44. * Initial Release
  45. *---------------------------------------------------------------------------*/
  46. #ifndef CMSIS_OS2_H_
  47. #define CMSIS_OS2_H_
  48. #ifndef __NO_RETURN
  49. #if defined(__CC_ARM)
  50. #define __NO_RETURN __declspec(noreturn)
  51. #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  52. #define __NO_RETURN __attribute__((__noreturn__))
  53. #elif defined(__GNUC__)
  54. #define __NO_RETURN __attribute__((__noreturn__))
  55. #elif defined(__ICCARM__)
  56. #define __NO_RETURN __noreturn
  57. #else
  58. #define __NO_RETURN
  59. #endif
  60. #endif
  61. #include <furi/base.h>
  62. #ifdef __cplusplus
  63. extern "C"
  64. {
  65. #endif
  66. // ==== Enumerations, structures, defines ====
  67. /// Version information.
  68. typedef struct {
  69. uint32_t api; ///< API version (major.minor.rev: mmnnnrrrr dec).
  70. uint32_t kernel; ///< Kernel version (major.minor.rev: mmnnnrrrr dec).
  71. } osVersion_t;
  72. /// Kernel state.
  73. typedef enum {
  74. osKernelInactive = 0, ///< Inactive.
  75. osKernelReady = 1, ///< Ready.
  76. osKernelRunning = 2, ///< Running.
  77. osKernelLocked = 3, ///< Locked.
  78. osKernelSuspended = 4, ///< Suspended.
  79. osKernelError = -1, ///< Error.
  80. osKernelReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
  81. } osKernelState_t;
  82. /// Timer callback function.
  83. typedef void (*osTimerFunc_t) (void *argument);
  84. /// Timer type.
  85. typedef enum {
  86. osTimerOnce = 0, ///< One-shot timer.
  87. osTimerPeriodic = 1 ///< Repeating timer.
  88. } osTimerType_t;
  89. /// \details Timer ID identifies the timer.
  90. typedef void *osTimerId_t;
  91. /// \details Message Queue ID identifies the message queue.
  92. typedef void *osMessageQueueId_t;
  93. #ifndef TZ_MODULEID_T
  94. #define TZ_MODULEID_T
  95. /// \details Data type that identifies secure software modules called by a process.
  96. typedef uint32_t TZ_ModuleId_t;
  97. #endif
  98. /// Attributes structure for timer.
  99. typedef struct {
  100. const char *name; ///< name of the timer
  101. uint32_t attr_bits; ///< attribute bits
  102. void *cb_mem; ///< memory for control block
  103. uint32_t cb_size; ///< size of provided memory for control block
  104. } osTimerAttr_t;
  105. /// Attributes structure for message queue.
  106. typedef struct {
  107. const char *name; ///< name of the message queue
  108. uint32_t attr_bits; ///< attribute bits
  109. void *cb_mem; ///< memory for control block
  110. uint32_t cb_size; ///< size of provided memory for control block
  111. void *mq_mem; ///< memory for data storage
  112. uint32_t mq_size; ///< size of provided memory for data storage
  113. } osMessageQueueAttr_t;
  114. // ==== Kernel Management Functions ====
  115. /// Initialize the RTOS Kernel.
  116. /// \return status code that indicates the execution status of the function.
  117. osStatus_t osKernelInitialize (void);
  118. /// Get RTOS Kernel Information.
  119. /// \param[out] version pointer to buffer for retrieving version information.
  120. /// \param[out] id_buf pointer to buffer for retrieving kernel identification string.
  121. /// \param[in] id_size size of buffer for kernel identification string.
  122. /// \return status code that indicates the execution status of the function.
  123. osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
  124. /// Get the current RTOS Kernel state.
  125. /// \return current RTOS Kernel state.
  126. osKernelState_t osKernelGetState (void);
  127. /// Start the RTOS Kernel scheduler.
  128. /// \return status code that indicates the execution status of the function.
  129. osStatus_t osKernelStart (void);
  130. /// Lock the RTOS Kernel scheduler.
  131. /// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
  132. int32_t osKernelLock (void);
  133. /// Unlock the RTOS Kernel scheduler.
  134. /// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
  135. int32_t osKernelUnlock (void);
  136. /// Restore the RTOS Kernel scheduler lock state.
  137. /// \param[in] lock lock state obtained by \ref osKernelLock or \ref osKernelUnlock.
  138. /// \return new lock state (1 - locked, 0 - not locked, error code if negative).
  139. int32_t osKernelRestoreLock (int32_t lock);
  140. /// Suspend the RTOS Kernel scheduler.
  141. /// \return time in ticks, for how long the system can sleep or power-down.
  142. uint32_t osKernelSuspend (void);
  143. /// Resume the RTOS Kernel scheduler.
  144. /// \param[in] sleep_ticks time in ticks for how long the system was in sleep or power-down mode.
  145. void osKernelResume (uint32_t sleep_ticks);
  146. /// Get the RTOS kernel tick count.
  147. /// \return RTOS kernel current tick count.
  148. uint32_t osKernelGetTickCount (void);
  149. /// Get the RTOS kernel tick frequency.
  150. /// \return frequency of the kernel tick in hertz, i.e. kernel ticks per second.
  151. uint32_t osKernelGetTickFreq (void);
  152. /// Get the RTOS kernel system timer frequency.
  153. /// \return frequency of the system timer in hertz, i.e. timer ticks per second.
  154. uint32_t osKernelGetSysTimerFreq (void);
  155. // ==== Generic Wait Functions ====
  156. /// Wait for Timeout (Time Delay).
  157. /// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value
  158. /// \return status code that indicates the execution status of the function.
  159. osStatus_t osDelay (uint32_t ticks);
  160. /// Wait until specified time.
  161. /// \param[in] ticks absolute time in ticks
  162. /// \return status code that indicates the execution status of the function.
  163. osStatus_t osDelayUntil (uint32_t ticks);
  164. // ==== Timer Management Functions ====
  165. /// Create and Initialize a timer.
  166. /// \param[in] func function pointer to callback function.
  167. /// \param[in] type \ref osTimerOnce for one-shot or \ref osTimerPeriodic for periodic behavior.
  168. /// \param[in] argument argument to the timer callback function.
  169. /// \param[in] attr timer attributes; NULL: default values.
  170. /// \return timer ID for reference by other functions or NULL in case of error.
  171. osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
  172. /// Get name of a timer.
  173. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  174. /// \return name as null-terminated string.
  175. const char *osTimerGetName (osTimerId_t timer_id);
  176. /// Start or restart a timer.
  177. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  178. /// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer.
  179. /// \return status code that indicates the execution status of the function.
  180. osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
  181. /// Stop a timer.
  182. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  183. /// \return status code that indicates the execution status of the function.
  184. osStatus_t osTimerStop (osTimerId_t timer_id);
  185. /// Check if a timer is running.
  186. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  187. /// \return 0 not running, 1 running.
  188. uint32_t osTimerIsRunning (osTimerId_t timer_id);
  189. /// Delete a timer.
  190. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  191. /// \return status code that indicates the execution status of the function.
  192. osStatus_t osTimerDelete (osTimerId_t timer_id);
  193. // ==== Message Queue Management Functions ====
  194. /// Create and Initialize a Message Queue object.
  195. /// \param[in] msg_count maximum number of messages in queue.
  196. /// \param[in] msg_size maximum message size in bytes.
  197. /// \param[in] attr message queue attributes; NULL: default values.
  198. /// \return message queue ID for reference by other functions or NULL in case of error.
  199. osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
  200. /// Get name of a Message Queue object.
  201. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  202. /// \return name as null-terminated string.
  203. const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
  204. /// Put a Message into a Queue or timeout if Queue is full.
  205. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  206. /// \param[in] msg_ptr pointer to buffer with message to put into a queue.
  207. /// \param[in] msg_prio message priority.
  208. /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  209. /// \return status code that indicates the execution status of the function.
  210. osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);
  211. /// Get a Message from a Queue or timeout if Queue is empty.
  212. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  213. /// \param[out] msg_ptr pointer to buffer for message to get from a queue.
  214. /// \param[out] msg_prio pointer to buffer for message priority or NULL.
  215. /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  216. /// \return status code that indicates the execution status of the function.
  217. osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);
  218. /// Get maximum number of messages in a Message Queue.
  219. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  220. /// \return maximum number of messages.
  221. uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
  222. /// Get maximum message size in a Message Queue.
  223. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  224. /// \return maximum message size in bytes.
  225. uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
  226. /// Get number of queued messages in a Message Queue.
  227. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  228. /// \return number of queued messages.
  229. uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
  230. /// Get number of available slots for messages in a Message Queue.
  231. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  232. /// \return number of available slots for messages.
  233. uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
  234. /// Reset a Message Queue to initial empty state.
  235. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  236. /// \return status code that indicates the execution status of the function.
  237. osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
  238. /// Delete a Message Queue object.
  239. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  240. /// \return status code that indicates the execution status of the function.
  241. osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
  242. #ifdef __cplusplus
  243. }
  244. #endif
  245. #endif // CMSIS_OS2_H_