你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

CMSIS-RTOS2 文档翻译 之 通用 RTOS 接口

[复制链接]
XinLiYF 发布时间:2018-4-21 15:48
本帖最后由 XinLiYF 于 2018-4-22 21:59 编辑 : v* y$ o" {3 @( T

) J6 [% ?4 n/ ^$ f( \7 I
通用 RTOS 接口3 J! Y+ v* |3 i. q  _

+ R% @; S0 u$ y% b4 \" m
CMSIS-RTOS2 是一个通用的 API ,不受底层 RTOS 内核的影响。应用程序员在用户代码中调用 CMSIS-RTOS2 API 函数以确保从一个 RTOS 到另一个 RTOS 的最大可移植性。使用 CMSIS-RTOS2 API 的中间件可以避免不必要的移植工作。
, Y4 j$ x4 S8 `* T
+ p" P- ]2 T: }/ d; [
CMSIS-RTOS API 结构

( s5 ^# s, o" V% ?5 z) s% c
" u" x( i6 ]  p4 h
典型的 CMSIS-RTOS2 API 实现与现有的实时内核接口。CMSIS-RTOS2 API 提供以下属性和功能:
* b+ ~, j+ D0 c/ g
  • 函数名称,标识符和参数是描述性的,易于理解的。这些功能强大而灵活,减少了暴露给用户的功能数量。
  • 线程管理允许您定义,创建和控制线程。
  • 中断服务程序(ISR)可以调用一些 CMSIS-RTOS 功能。 当 CMSIS-RTOS 函数不能从 ISR 上下文中调用时,它会拒绝调用并返回错误代码。
  • 三种不同的事件类型支持多个线程和/或 ISR 之间的通信:8 R0 U" x6 I$ o9 Y" y2 Q
    • 线程标志: 可用于向线程指示特定条件。
    • 事件标志: 可用于向线程或 ISR 指示事件。
    • 消息: 可以发送到线程或 ISR 。消息缓冲在队列中。
      ! B5 K+ B+ R$ ^
  • 互斥管理和信号量已合并。
  • CPU 时间可以安排以下功能:
    + |4 E% f* ^2 ~( `
    • 超时参数包含在许多 CMSIS-RTOS 功能中,以避免系统锁定。当指定超时时,系统会等待,直到资源可用或发生事件。在等待时,运行其他线程。
    • osDelay 和 osDelayUntil 函数将线程置于 WAITING 状态一段指定的时间。
    • osThreadYield 提供协作式线程切换并将执行传递给具有相同优先级的另一个线程。
      ' t2 G4 b0 Y7 K
  • 定时器管理功能用于触发功能的执行。
    % F5 f% i, D& N9 a' D
- r/ H2 K  v! S
CMSIS-RTOS2 API 旨在通过 Cortex-M 存储器保护单元(MPU)选择性地整合多处理器系统和/或访问保护。
* V6 |) l- e9 u/ v: }
在一些 RTOS 实现中,线程可能在不同的处理器上执行,因此消息队列可能驻留在共享内存资源中。
+ r( ~+ [, t3 A! O! P" z
CMSIS-RTOS2 API 鼓励软件行业发展现有的 RTOS 实施。实时操作系统的实现可以在针对 Cortex-M 处理器的不同方面进行不同的优化。可选功能可能是例如

2 |! l5 F8 a4 o1 p( A; E7 q/ K
  • 支持 Cortex-M 内存保护单元(MPU)。
  • 支持多处理器系统。
  • 支持 DMA 控制器。
  • 确定性上下文切换。
  • 循环上下文切换。
  • 避免死锁,例如优先倒置。
  • 通过使用 Armv7-M 指令 LDREX 和 STREX 来实现零中断延迟。
    ( {: m& i/ k% s; ]8 D# Z% ^- l

* ]5 L3 f2 h* t4 ]! I1 i9 e1 W使用 CMSIS-RTOS2 实现
. O7 U4 ?0 |% h$ b; }2 B8 S
CMSIS-RTOS2 实现通常作为库提供。要将 RTOS 功能添加到现有的基于 CMSIS 的应用程序中,需要添加 RTOS 库(通常是一个或多个配置文件)。有一个新的头文件 cmsis_os2.h 可用。这是完全可移植应用程序所需的唯一头文件。在这种情况下,不能使用用户为控制块,对象数据和线程堆栈提供的内存。或者,您可以包含一个实现特定的头文件(例如 rtx_os.h),该文件还提供了用于资源分配的定义(例如控制块的大小,对象数据和线程堆栈所需的内存)。 这是可选的,意味着应用程序代码不是完全可移植的。
7 g( N, E  `$ I+ q, B; [7 p
% J' Z& h3 z, z- q. z
CMSIS-RTOS 文件结构
+ u7 {$ k. C" B! j' C4 C

2 R, n) m' o' @, g4 q# V
* ?4 s) C8 T% b/ D
将文件添加到项目后,用户可以开始使用 CMSIS-RTOS 功能。下面提供了一个代码示例:
- d- T/ U! B' I
代码示例
  1. /*----------------------------------------------------------------------------. r2 _( o- T, d% e7 _) l
  2. * CMSIS-RTOS 'main' function template
    - {8 `) b- @% V7 j, V. M5 E. c
  3. *---------------------------------------------------------------------------*/; a4 c7 Q  g' W1 N, o

  4. 8 W) N& u4 a7 u* F
  5. #include "RTE_Components.h"- f- W2 I) G8 j5 N2 H, y; y
  6. #include  CMSIS_device_header  R( \8 ]# z  \' I
  7. #include "cmsis_os2.h"
    6 k8 F1 w, W1 x# Y
  8. 7 f( s8 @5 D0 u/ l" q/ X6 q* T
  9. /*----------------------------------------------------------------------------
    . t# h# d& o/ ], k0 K
  10. * Application main thread) v- d3 F1 i% a
  11. *---------------------------------------------------------------------------*/4 e  {% z/ c) t- w+ W- S0 _
  12. void app_main (void *argument) {
    ; e+ L/ R3 L/ P9 g, \+ m2 I2 c

  13. 7 O: J9 q+ s) e4 o
  14.   // ..." q+ t; c5 m/ s0 p0 t  o2 Y
  15.   for (;;) {}. V6 a6 ^, w+ ]4 V4 ?
  16. }8 G( X- w8 {: \4 V9 S( S
  17. 6 |  E8 N) a5 t
  18. int main (void) {0 \( H# L  L$ L& h: X4 h

  19. - F  u3 c$ y" F6 G: T2 k
  20.   // System Initialization
    5 G( J" ^' M0 c1 o
  21.   SystemCoreClockUpdate();. V+ d% q! ?6 H1 y
  22. #ifdef RTE_Compiler_EventRecorder
    , ~& S+ {. r+ Q6 R! U
  23.   // Initialize and start Event Recorder
    , S, X  z: D: ]$ f9 {
  24.   EventRecorderInitialize(EventRecordError, 1U);
    3 H: c; @. ]9 ^: N
  25. #endif7 o* v: v4 H! g  a8 M# y- q0 R% \( I
  26.   // ..." _( \- h( Q8 F; P' Z9 R- n

  27. 5 v. K# L5 m5 T
  28.   osKernelInitialize();                 // Initialize CMSIS-RTOS! o* G- n: @3 e" R0 q
  29.   osThreadNew(app_main, NULL, NULL);    // Create application main thread1 p( i7 x) B& s- @7 A- ^0 Q, Z
  30.   osKernelStart();                      // Start thread execution; e: f6 Y4 X4 G0 q9 y
  31.   for (;;) {}
    + ?* B- k. l& q3 }- C5 A
  32. }
复制代码
" C7 k( E% A: u' I: t/ A
cmsis_os2.h 头文件

; \' P, i( n: f( a, i
文件 cmsis_os2.h 是一个标准头文件,与每个 CMSIS-RTOS2 兼容的实时操作系统(RTOS)相连接。每个实现都提供了相同的 cmsis_os2.h ,它定义了到 CMSIS-RTOS2 的接口。
2 R; o7 v, m) g9 G! b/ C% ^' R
通过使用 cmsis_os2.h 和动态对象分配,可以创建在不同的 CMSIS-RTOS2 实现上使用时不需要修改的源代码或库。
# [1 z3 w7 O! d
头文件 cmsis_os2.h
  1. /*
    9 Y& j. W. r; T( K
  2. * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
    0 }* l6 N* r: u: s* I' E! C& M
  3. *
    5 w# A* d7 K& |* d. v8 d( B: m
  4. * SPDX-License-Identifier: Apache-2.0
    / z; U2 b! g% O* U& R  U' K& j  n
  5. *4 Q  o$ e+ u  h( w' C
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
    6 t/ H: _& Y6 ^  O$ h* z
  7. * not use this file except in compliance with the License.
    $ A" T5 Q" B8 `5 i6 a
  8. * You may obtain a copy of the License at, d+ M3 J; j, {4 i
  9. *
    0 z3 k! h) f/ p7 y( @
  10. * www.apache.org/licenses/LICENSE-2.0
    , U% c  q5 G8 Q: U8 s
  11. *6 m. Z9 p9 p- P: G  O1 V
  12. * Unless required by applicable law or agreed to in writing, software
    5 }2 v2 Y  b* N) Y+ Y  [; l
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT9 [* z% }' g# T7 l, r% \$ t+ Z
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied./ Z/ l: V! _+ S$ {0 @
  15. * See the License for the specific language governing permissions and2 B" d0 u8 @0 {8 J
  16. * limitations under the License.# h9 t7 v3 `% h/ H2 u
  17. *2 Y' e2 L; C$ A; `6 S% \
  18. * ----------------------------------------------------------------------
      J8 f" T/ a" N3 h
  19. *
    " g# f! V1 H, m- b
  20. * $Date:        30. October 20178 M9 H, o, q' C/ Q+ l: Q
  21. * $Revision:    V2.1.2
    7 ]: \" F5 P2 k* X  f* M. d
  22. *
    / A/ W! n8 W3 \$ P, d- D* J
  23. * Project:      CMSIS-RTOS2 API
    2 N: D) ^7 \' g) g& M5 C, e$ D: _
  24. * Title:        cmsis_os2.h header file" t0 L# l( G5 N. R! Z: T8 ^
  25. ** H4 D( U+ b7 n* L, c1 R
  26. * Version 2.1.2
    ) r7 L5 |/ `8 b. v! h( |0 I
  27. *    Additional functions allowed to be called from Interrupt Service Routines:
    % Y" H. P. t5 o
  28. *    - osKernelGetInfo, osKernelGetState
    , d% a: q# w0 S) S
  29. * Version 2.1.1, a  n: J5 V  R) I
  30. *    Additional functions allowed to be called from Interrupt Service Routines:
    3 u$ P  r/ L+ B: ?. q. b
  31. *    - osKernelGetTickCount, osKernelGetTickFreq
    7 ^% f; K$ ]0 O2 l( Q
  32. *    Changed Kernel Tick type to uint32_t:4 y+ R) i7 }- j) z
  33. *    - updated: osKernelGetTickCount, osDelayUntil
    4 h0 j' a5 Y3 u! {' }3 W4 ^
  34. * Version 2.1.0, E1 l0 G8 H5 w# Y8 q1 A- y
  35. *    Support for critical and uncritical sections (nesting safe):' j) I+ n% v* d, \) C% [: G1 H
  36. *    - updated: osKernelLock, osKernelUnlock
    . O3 m, @( s* i6 A& a1 ^7 r7 s, H
  37. *    - added: osKernelRestoreLock  O& x% _+ ^4 [+ F
  38. *    Updated Thread and Event Flags:4 D6 ]3 }& N: g2 S
  39. *    - changed flags parameter and return type from int32_t to uint32_t! \3 t4 p% |2 Y9 t
  40. * Version 2.0.0
    " b2 ^" f$ V5 C8 y% B( u& H
  41. *    Initial Release
    , c$ h& {3 @4 N( o6 |# U- B3 \
  42. *---------------------------------------------------------------------------*/
    1 i9 r& H/ z4 T2 {' ?$ ]

  43. $ ?$ }' _. U- [4 i. H; q- V
  44. #ifndef CMSIS_OS2_H_
    ' F! \3 Y* z# `5 [3 _
  45. #define CMSIS_OS2_H_
    5 \2 G+ C  _% v
  46. 3 D( @  j" N" I( d# \7 L, K; D; S2 v
  47. #ifndef __NO_RETURN
    ( \9 i  [& ]# g3 D  h1 w, S& h+ @
  48. #if   defined(__CC_ARM)
    3 S. V( w# Y& _( E: k
  49. #define __NO_RETURN __declspec(noreturn)/ `3 x% e  r8 ], p  G2 G
  50. #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
    , S$ |* D& @. {( k8 E
  51. #define __NO_RETURN __attribute__((__noreturn__))
    $ V2 w  Y& v/ I# X  V+ }/ U
  52. #elif defined(__GNUC__)" k& |, t; Z3 |
  53. #define __NO_RETURN __attribute__((__noreturn__))
    " w+ O5 [; S  U7 Y1 U/ R% ]
  54. #elif defined(__ICCARM__)- A& R: t# H3 G  C4 D) w
  55. #define __NO_RETURN __noreturn& @5 z8 d4 |) Q- S8 X8 p; G
  56. #else
    7 S) n; B3 K. D. t' U' b3 w
  57. #define __NO_RETURN
    ; s" u& z2 ?" ~1 G
  58. #endif
    & _. X4 j/ l; r) [1 f' ]8 F# U
  59. #endif) |5 `9 M+ H9 F$ F9 D

  60. ( U2 t+ C7 A3 x4 a3 Y* H4 C4 T
  61. #include <stdint.h>
    0 Q/ x& w& n/ I+ I6 f
  62. #include <stddef.h>: c* G$ W  N: ?! c5 Z! p
  63. % L9 |: u! ~/ ?6 s' @* f  X* i
  64. #ifdef  __cplusplus
    , H0 C# D) ^; B4 r
  65. extern "C"
    ; ]8 X1 G% F! u& P) z, G3 z
  66. {
    9 c5 M! S+ a, Q3 W' s; T
  67. #endif# V: [9 A3 [) s% w

  68. + A" [# M: x9 ~# p7 P

  69. " i2 X+ F: v. _: x4 N4 @7 F+ m
  70. //  ==== Enumerations, structures, defines ====
    " j5 H5 q+ v. j) s8 R. s

  71. , @% x. {6 |: ?
  72. /// Version information.* K# c$ G/ [$ i5 r" `
  73. typedef struct {
    ! a5 j6 q9 Z! |) E4 O
  74.   uint32_t                       api;   ///< API version (major.minor.rev: mmnnnrrrr dec).
    & @, j$ C+ O9 W- h* V! J: [% x
  75.   uint32_t                    kernel;   ///< Kernel version (major.minor.rev: mmnnnrrrr dec).  y3 @, w1 g1 ~
  76. } osVersion_t;$ h. l  w9 o$ M. W! W4 C' ?7 G
  77. * K' p9 w! H1 I! H4 J' {
  78. /// Kernel state.. N+ }4 H# F3 q7 O  W7 T3 C
  79. typedef enum {) C  y, K5 |; c# a
  80.   osKernelInactive        =  0,         ///< Inactive.
    + _5 V- O2 W  G: h1 e4 t# I+ a
  81.   osKernelReady           =  1,         ///< Ready.
    ) l) d6 Y' f1 M
  82.   osKernelRunning         =  2,         ///< Running.
    # K# F; k, Y$ P% G$ M3 I# I
  83.   osKernelLocked          =  3,         ///< Locked.8 G+ S9 h1 I! A/ D; q( w, S
  84.   osKernelSuspended       =  4,         ///< Suspended.
    & w/ l) D0 I! q/ o  E- ?5 ~$ h2 m0 ~6 m
  85.   osKernelError           = -1,         ///< Error.9 ?( [; p9 I; }' a3 v" W
  86.   osKernelReserved        = 0x7FFFFFFFU ///< Prevents enum down-size compiler optimization.( g/ j" Q3 w- H6 ?
  87. } osKernelState_t;
    0 a8 _  ]$ t) ^! T* }$ M" {
  88. 7 k8 p9 X) ?3 S$ R
  89. /// Thread state.. M9 U" r0 a' r! o7 _, G7 {& q- f
  90. typedef enum {8 m5 v9 H/ |3 p( B5 \
  91.   osThreadInactive        =  0,         ///< Inactive.
    ! `, k0 z* D5 T8 i) Q* A
  92.   osThreadReady           =  1,         ///< Ready.
    7 `3 e, W  @+ w) b$ h
  93.   osThreadRunning         =  2,         ///< Running.0 R7 e- _, T9 P& s2 n4 w0 Q
  94.   osThreadBlocked         =  3,         ///< Blocked.
    : u+ v5 q) o; d( r' S
  95.   osThreadTerminated      =  4,         ///< Terminated.
    3 V( z$ i. Q9 |3 X. X+ q
  96.   osThreadError           = -1,         ///< Error.+ ^" z, E+ }" R
  97.   osThreadReserved        = 0x7FFFFFFF  ///< Prevents enum down-size compiler optimization.
    # F. S. r% G: H& A; [  J
  98. } osThreadState_t;/ H7 w" H4 C  N) v0 A

  99. ! _! o( W9 P( Q" T) @" P
  100. /// Priority values.; [& h/ I; Q4 E7 c, S( \$ ~4 E: s
  101. typedef enum {
    & S% ~3 [( L0 i
  102.   osPriorityNone          =  0,         ///< No priority (not initialized).
    ! Z$ M9 V, B  w2 C- r
  103.   osPriorityIdle          =  1,         ///< Reserved for Idle thread.
    ( w( ]6 d& _3 m4 R5 w- M0 L7 W, r( p
  104.   osPriorityLow           =  8,         ///< Priority: low
    ! E  d3 b- U. i' z' B
  105.   osPriorityLow1          =  8+1,       ///< Priority: low + 12 V" G% ^% g2 v5 \% Z' W
  106.   osPriorityLow2          =  8+2,       ///< Priority: low + 26 A5 O+ `' ^) n- E" N: e% O# W" ~7 W0 t
  107.   osPriorityLow3          =  8+3,       ///< Priority: low + 3, b8 `# i/ v1 Z" c: Y% L3 ?
  108.   osPriorityLow4          =  8+4,       ///< Priority: low + 4
    " G7 ]# _" p4 a4 R% E1 O) P
  109.   osPriorityLow5          =  8+5,       ///< Priority: low + 5; a, O- Z7 N  z' O$ N' Q7 z# ?
  110.   osPriorityLow6          =  8+6,       ///< Priority: low + 6
    : \/ d: M1 Z' V) W4 t4 r% D
  111.   osPriorityLow7          =  8+7,       ///< Priority: low + 78 k' ^6 D$ a$ [! C
  112.   osPriorityBelowNormal   = 16,         ///< Priority: below normal+ G; c3 s# p1 q4 x* Z
  113.   osPriorityBelowNormal1  = 16+1,       ///< Priority: below normal + 11 u6 J4 k! I# p) b4 v
  114.   osPriorityBelowNormal2  = 16+2,       ///< Priority: below normal + 2
    ! r5 F# f# X- L' m# k' o$ Y
  115.   osPriorityBelowNormal3  = 16+3,       ///< Priority: below normal + 3
    + n  T/ m5 d# O) D/ F+ a( |' W
  116.   osPriorityBelowNormal4  = 16+4,       ///< Priority: below normal + 4
    4 p6 ~% r' d- [: O8 C
  117.   osPriorityBelowNormal5  = 16+5,       ///< Priority: below normal + 5
    ( X5 @  V4 R. X" T
  118.   osPriorityBelowNormal6  = 16+6,       ///< Priority: below normal + 6
    5 N* K! }; x2 D; l
  119.   osPriorityBelowNormal7  = 16+7,       ///< Priority: below normal + 7( I! G  ]& q. u
  120.   osPriorityNormal        = 24,         ///< Priority: normal
    # A+ T8 t1 j6 s: E* O  j& b- g$ ^
  121.   osPriorityNormal1       = 24+1,       ///< Priority: normal + 12 }( _3 n' c. S* y& S8 @
  122.   osPriorityNormal2       = 24+2,       ///< Priority: normal + 2
    7 i$ v7 ^/ ^- I! N% Q# W
  123.   osPriorityNormal3       = 24+3,       ///< Priority: normal + 3
    5 w( B; L3 W/ R& L' h  ?( `4 W+ p
  124.   osPriorityNormal4       = 24+4,       ///< Priority: normal + 4
    2 G" W4 F( D4 p1 K
  125.   osPriorityNormal5       = 24+5,       ///< Priority: normal + 5; u& T4 N" ?6 [- l! W' C/ B
  126.   osPriorityNormal6       = 24+6,       ///< Priority: normal + 6" h* r, _/ l+ N6 c
  127.   osPriorityNormal7       = 24+7,       ///< Priority: normal + 7
    # |  c# ?+ d8 w( S+ W0 G
  128.   osPriorityAboveNormal   = 32,         ///< Priority: above normal
      e0 O  S% t. o' l
  129.   osPriorityAboveNormal1  = 32+1,       ///< Priority: above normal + 1$ N( K, C$ K! H: D" E$ U
  130.   osPriorityAboveNormal2  = 32+2,       ///< Priority: above normal + 2
    6 K# w7 e) v+ }3 V" e
  131.   osPriorityAboveNormal3  = 32+3,       ///< Priority: above normal + 3# l; L8 a, |( B/ {
  132.   osPriorityAboveNormal4  = 32+4,       ///< Priority: above normal + 4
    3 ~  z( |; F  ^6 n6 r- e
  133.   osPriorityAboveNormal5  = 32+5,       ///< Priority: above normal + 5& a* a3 G& d2 Z
  134.   osPriorityAboveNormal6  = 32+6,       ///< Priority: above normal + 6
    ( g% r! t9 @5 u. E
  135.   osPriorityAboveNormal7  = 32+7,       ///< Priority: above normal + 7
    - T5 Z, y8 `! D& ~* O4 Y) ~4 x4 h; D9 ?
  136.   osPriorityHigh          = 40,         ///< Priority: high. _% {+ t  X% `" I& e' X) E
  137.   osPriorityHigh1         = 40+1,       ///< Priority: high + 1
    " f  `! [6 U4 |0 K+ ~5 Q1 A0 T
  138.   osPriorityHigh2         = 40+2,       ///< Priority: high + 2
    ' A: q  B2 t# z" n( l+ _( V
  139.   osPriorityHigh3         = 40+3,       ///< Priority: high + 30 ]  @6 U' B/ Q5 M  d
  140.   osPriorityHigh4         = 40+4,       ///< Priority: high + 46 Y" ~$ V( z" x5 z; A) E0 m8 B
  141.   osPriorityHigh5         = 40+5,       ///< Priority: high + 5
    3 a0 H0 ~$ s6 m  V
  142.   osPriorityHigh6         = 40+6,       ///< Priority: high + 6$ P! i+ |2 k! c" O/ t; j
  143.   osPriorityHigh7         = 40+7,       ///< Priority: high + 7! `* E. \* a! w# Y& N
  144.   osPriorityRealtime      = 48,         ///< Priority: realtime* c! d; T5 x) Z3 ?
  145.   osPriorityRealtime1     = 48+1,       ///< Priority: realtime + 1
    " S- L! D  e. n
  146.   osPriorityRealtime2     = 48+2,       ///< Priority: realtime + 2
    - S& R* A( T7 O, U
  147.   osPriorityRealtime3     = 48+3,       ///< Priority: realtime + 37 I9 }# M3 V$ u, {
  148.   osPriorityRealtime4     = 48+4,       ///< Priority: realtime + 4* I& K; i* N) t5 _& w" \
  149.   osPriorityRealtime5     = 48+5,       ///< Priority: realtime + 5! o  @* k9 ^: e" A2 j; i
  150.   osPriorityRealtime6     = 48+6,       ///< Priority: realtime + 6
    , U5 d( {( H. U$ I' g; d
  151.   osPriorityRealtime7     = 48+7,       ///< Priority: realtime + 7* D0 N9 g' k4 v% N/ A( i0 k3 D2 U
  152.   osPriorityISR           = 56,         ///< Reserved for ISR deferred thread.
    & D. T, h9 a* G( @
  153.   osPriorityError         = -1,         ///< System cannot determine priority or illegal priority.: B2 i. I8 h9 |! \
  154.   osPriorityReserved      = 0x7FFFFFFF  ///< Prevents enum down-size compiler optimization.
    ) C0 x4 U! p  B
  155. } osPriority_t;( u/ a" L$ H) P9 V0 w

  156. + W0 Z. X" [/ L" u2 @) F) f
  157. /// Entry point of a thread.  O& n. _4 C% C( F5 m# |
  158. typedef void (*osThreadFunc_t) (void *argument);
    " O8 j" F( I6 r$ f/ P( ~6 S
  159. , [0 J( Z9 i1 e5 ]6 J: M
  160. /// Timer callback function., g, U. k; r: ]3 u  s4 I: t9 u5 X
  161. typedef void (*osTimerFunc_t) (void *argument);8 G* Z# C' c) ?0 n+ L- b+ J7 K

  162. ' Y- J; k  D- Z% d
  163. /// Timer type.2 v9 \" Y3 b& z( c
  164. typedef enum {
    6 P/ a. d- ~; {) o, V1 S2 J
  165.   osTimerOnce               = 0,          ///< One-shot timer.9 G5 A0 h0 h8 H3 K/ W9 k, E" G- z
  166.   osTimerPeriodic           = 1           ///< Repeating timer.
    - {8 g- s' Y  e
  167. } osTimerType_t;/ j# S  _( s0 y- K2 j0 }

  168. 4 m/ F6 b. ^9 ]4 o
  169. // Timeout value.
    # x7 a4 N% h" @* J  g, f
  170. #define osWaitForever         0xFFFFFFFFU ///< Wait forever timeout value.
    5 d! G) e4 d5 D, ~

  171. ! l; x- q: _& T8 d3 p/ o
  172. // Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).& \5 L( P  D0 m# U. _# G3 ]
  173. #define osFlagsWaitAny        0x00000000U ///< Wait for any flag (default).* p" _/ n7 [: ?
  174. #define osFlagsWaitAll        0x00000001U ///< Wait for all flags.
      ^+ `" Y; p! l
  175. #define osFlagsNoClear        0x00000002U ///< Do not clear flags which have been specified to wait for.
    * ~4 ^4 y# e4 r( [) E

  176. " h! N$ r, H' c+ S$ Q; C
  177. // Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx).+ E% _$ N2 v: s1 Z; T: B: K6 u0 @
  178. #define osFlagsError          0x80000000U ///< Error indicator.
    ! [2 c3 e7 H  [% h" f
  179. #define osFlagsErrorUnknown   0xFFFFFFFFU ///< osError (-1).
    8 _( Z# Z% h4 z8 }7 G
  180. #define osFlagsErrorTimeout   0xFFFFFFFEU ///< osErrorTimeout (-2).
    / S' J3 N5 U0 l6 J- c8 }  R' i
  181. #define osFlagsErrorResource  0xFFFFFFFDU ///< osErrorResource (-3).1 F" X: X0 Q5 c1 ~5 }) v8 S
  182. #define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4).( ^) P0 C8 Z7 I" C5 [( w# c
  183. #define osFlagsErrorISR       0xFFFFFFFAU ///< osErrorISR (-6).
      s/ l" ]# Y0 ^7 u+ m7 Z1 t
  184. & @6 u0 V" U" J6 z
  185. // Thread attributes (attr_bits in \ref osThreadAttr_t).3 \# [( y0 n. n# o" t: y3 ]4 x
  186. #define osThreadDetached      0x00000000U ///< Thread created in detached mode (default)
    % G5 _3 }. l# Y  I. ]# O* C
  187. #define osThreadJoinable      0x00000001U ///< Thread created in joinable mode
    5 T6 M: j8 n+ o: I9 K. l7 ?& I
  188. 9 b: ~2 [) g0 V% E
  189. // Mutex attributes (attr_bits in \ref osMutexAttr_t)./ t& p6 ?* v! u% X& X* G
  190. #define osMutexRecursive      0x00000001U ///< Recursive mutex.
    ( Y6 z5 A9 F* M' R# \$ I
  191. #define osMutexPrioInherit    0x00000002U ///< Priority inherit protocol.
    ) I7 Q6 y% c" v7 r. ?' h4 k
  192. #define osMutexRobust         0x00000008U ///< Robust mutex.9 h6 B, [( K1 Y$ F+ f0 I% J) J
  193. - T3 z8 Q  ^7 m0 D7 a8 D
  194. /// Status code values returned by CMSIS-RTOS functions.
    : ^7 N2 K  Y! ^: D, F
  195. typedef enum {4 X% }2 j, c6 @/ V: _; D- @
  196.   osOK                      =  0,         ///< Operation completed successfully.
    ! G  A/ a  b- Q$ A  f
  197.   osError                   = -1,         ///< Unspecified RTOS error: run-time error but no other error message fits.
    & t. o- f& D# x4 M) E4 l9 R
  198.   osErrorTimeout            = -2,         ///< Operation not completed within the timeout period.
    + T+ d& C" M( d! P) f
  199.   osErrorResource           = -3,         ///< Resource not available.
    2 D& I% l; w9 i& E, C
  200.   osErrorParameter          = -4,         ///< Parameter error.
    $ C+ I# p7 K7 ^
  201.   osErrorNoMemory           = -5,         ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
    , z! d* \0 e$ g7 A% a4 f8 e0 F2 Z
  202.   osErrorISR                = -6,         ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
    3 f6 m5 e( @% J
  203.   osStatusReserved          = 0x7FFFFFFF  ///< Prevents enum down-size compiler optimization.
    1 `' ^4 ]8 m! l) |" N
  204. } osStatus_t;4 R% T2 S9 u$ |, q  r

  205. 3 G+ l1 M  g. O2 n

  206. * e, k4 }1 P. N4 l. W; T
  207. /// \details Thread ID identifies the thread.7 o- M# e: }" a/ o
  208. typedef void *osThreadId_t;! w# v6 B% v" S# C

  209. : m: w" N" @" \! I) Z
  210. /// \details Timer ID identifies the timer.
    5 z4 M8 U- O& g+ C5 Z, M
  211. typedef void *osTimerId_t;8 I2 n% ~; K9 l0 k
  212. 9 G. Z4 Q5 e5 E% c) A9 X
  213. /// \details Event Flags ID identifies the event flags.
    ) K5 W+ t+ _) D! Z6 L1 w3 l) \
  214. typedef void *osEventFlagsId_t;+ Z; k7 r( X0 Z
  215. ; x' G$ P# e& m* [4 c, [
  216. /// \details Mutex ID identifies the mutex.
    ) E$ S: c# V# f( f7 i# ^
  217. typedef void *osMutexId_t;
    6 K! H1 Y; B" |0 B) d. C
  218. . a5 F: L1 U4 c7 X) B# Y8 H1 U& \
  219. /// \details Semaphore ID identifies the semaphore.
    + m0 e* k# y7 }4 _( q0 M/ G0 _
  220. typedef void *osSemaphoreId_t;- e* @- j& G4 [# h
  221. % o5 d$ I1 w' I8 a# |
  222. /// \details Memory Pool ID identifies the memory pool.& Z; Q5 ]& r1 W$ _6 i& H* i) O& |
  223. typedef void *osMemoryPoolId_t;
    ( ?2 s3 a0 m8 w! r; U; r- y# g

  224. & c, M6 d* o3 F  l7 t1 m- z
  225. /// \details Message Queue ID identifies the message queue.' m* k5 ^  _- F" C& [2 [
  226. typedef void *osMessageQueueId_t;( N4 L6 v3 e' V; F

  227. 6 s) z" Q) k2 _, c- E

  228. / ?, {4 Y' r) w( P2 [
  229. #ifndef TZ_MODULEID_T" x# f0 q/ X5 r: t+ I
  230. #define TZ_MODULEID_T* X( h" w+ L2 F2 T  R7 L  r7 S
  231. /// \details Data type that identifies secure software modules called by a process.$ X# J, E0 \5 x6 l
  232. typedef uint32_t TZ_ModuleId_t;
    3 ^5 m4 I  n6 Q' E7 c; L
  233. #endif& H" x% a2 y; U! ^9 o  P

  234. 7 A* a. g6 \* ~! K- \- L
  235. : b6 r3 K* h/ m* I
  236. /// Attributes structure for thread.0 k+ y6 @  v5 E1 j; c
  237. typedef struct {% T! `/ t* S7 {
  238.   const char                   *name;   ///< name of the thread. m0 a( z7 e( ^3 n( s
  239.   uint32_t                 attr_bits;   ///< attribute bits  F1 ~- N: \% H4 n- m4 g0 c
  240.   void                      *cb_mem;    ///< memory for control block
    + a8 y* Q2 l% Q' l- l' j) `6 [7 b
  241.   uint32_t                   cb_size;   ///< size of provided memory for control block
    ; t% y/ M: {" p/ e/ ^
  242.   void                   *stack_mem;    ///< memory for stack2 m" ~' L) T) U0 K: H4 m
  243.   uint32_t                stack_size;   ///< size of stack
    # P2 K4 L* g& j# K2 c) \) o
  244.   osPriority_t              priority;   ///< initial thread priority (default: osPriorityNormal)- E! q4 }# M& \* q( }0 D
  245.   TZ_ModuleId_t            tz_module;   ///< TrustZone module identifier
    8 @; p9 {. y6 K8 m' f1 _* K- J
  246.   uint32_t                  reserved;   ///< reserved (must be 0)
    ! h) I6 y2 B) Q0 P8 Q, d
  247. } osThreadAttr_t;/ v! M+ J6 u# d  D( N. Z$ j; k; l9 h
  248. $ c- Y* _0 r3 h7 g
  249. /// Attributes structure for timer.
    ) N, \' s( D0 O5 i
  250. typedef struct {& T7 _% p' D  p: ~- ]1 }
  251.   const char                   *name;   ///< name of the timer
    ( l3 h" R: @  _( t* o7 d/ m$ e
  252.   uint32_t                 attr_bits;   ///< attribute bits
    8 k, u" }9 E" R9 j
  253.   void                      *cb_mem;    ///< memory for control block
    8 y4 H8 v/ ^% q" W; L
  254.   uint32_t                   cb_size;   ///< size of provided memory for control block5 {5 T% |* ], e8 N
  255. } osTimerAttr_t;8 y9 Y/ b, J/ I% a
  256. ) W) ?5 ?. v; d4 Y" ^6 k
  257. /// Attributes structure for event flags.9 ]6 K3 r6 K- \6 x# i4 F
  258. typedef struct {
    3 A2 |8 y' I+ j, R; t0 K
  259.   const char                   *name;   ///< name of the event flags" l! c9 v* i7 {4 U. Y
  260.   uint32_t                 attr_bits;   ///< attribute bits
    3 J4 L- k1 S+ ^$ e; S1 j
  261.   void                      *cb_mem;    ///< memory for control block% t1 J: a# K/ T2 V* l7 E# B2 n
  262.   uint32_t                   cb_size;   ///< size of provided memory for control block! {9 M- f1 g" t+ ^+ D' \
  263. } osEventFlagsAttr_t;
    6 Q* b+ _) d. V: V% i
  264. ' h5 A& U" E. m
  265. /// Attributes structure for mutex.
    # {5 d. m' V. I) w) b$ M: p
  266. typedef struct {
    $ u7 h! `# a6 c% f% W( {- S8 E' i4 h
  267.   const char                   *name;   ///< name of the mutex
    % X0 t; c4 x  L1 t
  268.   uint32_t                 attr_bits;   ///< attribute bits
    * H( ]( A/ e7 T
  269.   void                      *cb_mem;    ///< memory for control block# Z7 K# G5 F2 `5 t0 z
  270.   uint32_t                   cb_size;   ///< size of provided memory for control block: p1 a9 \. ], L7 ?5 }
  271. } osMutexAttr_t;
    4 M- r. E" k2 g6 o" R1 J

  272. ; g+ @# j" t, r  |$ b# w9 z, b
  273. /// Attributes structure for semaphore.5 l4 n' \% z% _" R
  274. typedef struct {
    " R: t! O1 [; m, f# f
  275.   const char                   *name;   ///< name of the semaphore
    + j" L1 Y5 X. Z" w
  276.   uint32_t                 attr_bits;   ///< attribute bits
    " z1 T; U1 n+ B+ f# O" l
  277.   void                      *cb_mem;    ///< memory for control block( [/ \: H+ N6 P/ s" ]9 b1 C
  278.   uint32_t                   cb_size;   ///< size of provided memory for control block/ Y3 c/ F' {) ], B. l
  279. } osSemaphoreAttr_t;
    ' C! d+ H! o% ~" S6 ?- R1 _
  280. - e) e+ [) x. ~! K) F4 c6 B
  281. /// Attributes structure for memory pool.1 j; o- v; \  M# }: x
  282. typedef struct {3 X9 ]' ~- e( j$ o2 u" O6 F
  283.   const char                   *name;   ///< name of the memory pool
    6 o$ V" Z4 Q! A  h2 w
  284.   uint32_t                 attr_bits;   ///< attribute bits
    9 @+ i/ k# r8 Y. m
  285.   void                      *cb_mem;    ///< memory for control block0 F, A0 d7 t5 |! _
  286.   uint32_t                   cb_size;   ///< size of provided memory for control block+ z: d# ?- ^6 A3 Y* n
  287.   void                      *mp_mem;    ///< memory for data storage
    ; o8 P9 l! t5 T  J* \
  288.   uint32_t                   mp_size;   ///< size of provided memory for data storage 6 H/ L% M# R! s5 ~8 g. x" C
  289. } osMemoryPoolAttr_t;$ `7 Z2 J6 a3 Z! n

  290. 7 X# N+ G& w! i5 ]+ a
  291. /// Attributes structure for message queue.( I& y5 a7 s0 n; p
  292. typedef struct {% {. a, U& w6 q% ?
  293.   const char                   *name;   ///< name of the message queue
    0 i$ o0 V& y! \, n1 ]
  294.   uint32_t                 attr_bits;   ///< attribute bits7 W$ Y( E, A( f& y) A* o* ?2 f; _3 s
  295.   void                      *cb_mem;    ///< memory for control block  |2 }) m$ d0 v+ Q
  296.   uint32_t                   cb_size;   ///< size of provided memory for control block. j) j$ q: o% C6 ~! K* S5 b' w2 J( T
  297.   void                      *mq_mem;    ///< memory for data storage6 Z8 a/ J. s; k" o# |- u
  298.   uint32_t                   mq_size;   ///< size of provided memory for data storage
    ; w) w- S+ v, _! ]' U
  299. } osMessageQueueAttr_t;; n( Y+ r- z" j2 \3 P+ l/ [
  300. ! o9 J) y; z+ x" |

  301. # i4 F! z1 p  K& M: S1 J, A
  302. //  ==== Kernel Management Functions ====( D2 R3 p, [8 H8 E
  303. 3 n6 h& w, w9 n+ C5 x+ E" j* M9 S
  304. /// Initialize the RTOS Kernel.
    9 H. e; {) D/ b
  305. /// \return status code that indicates the execution status of the function.. l& E- d% s- a" {, e3 ]- c: h  O
  306. osStatus_t osKernelInitialize (void);
    ( I; B& m& s" x! P7 [& @2 b" v

  307. 8 s; Q9 i8 x3 G! v7 Q/ h
  308. ///  Get RTOS Kernel Information.
    % B0 d- R. k* t8 {8 J/ L& B
  309. /// \param[out]    version       pointer to buffer for retrieving version information.
    " H% \6 d( O* {' v$ H
  310. /// \param[out]    id_buf        pointer to buffer for retrieving kernel identification string.+ u: f; L# G0 Z' t* v9 K
  311. /// \param[in]     id_size       size of buffer for kernel identification string.
    ' B" I9 o4 O( y+ J) A
  312. /// \return status code that indicates the execution status of the function.; Y( W4 E6 {& H# G2 O9 N! z4 }
  313. osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);( u. b6 Z0 ~# N

  314. : L2 R2 b. L' O9 i1 A8 h1 |
  315. /// Get the current RTOS Kernel state.
    + ]. M2 L4 A: q0 C# ?5 [) A* U6 |/ _5 T
  316. /// \return current RTOS Kernel state.
    ; C1 j1 c6 r. V% B- H$ E2 O8 z
  317. osKernelState_t osKernelGetState (void);% Q3 Q) l7 a4 n7 r% t1 ^

  318. 9 M* U( Q, ]+ M% A* C+ U
  319. /// Start the RTOS Kernel scheduler.6 B8 D2 H2 b) H1 t7 j
  320. /// \return status code that indicates the execution status of the function.
    5 @- x: g" F' {# ^! X9 Y' z
  321. osStatus_t osKernelStart (void);
    9 a5 m+ k* ?& h8 c- m4 f
  322. 2 q' }8 }8 k# M' k6 q% R5 l# Y: a
  323. /// Lock the RTOS Kernel scheduler.. {- q3 O7 g; ]' W' ^. C
  324. /// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
    " B3 i1 L: x8 G& @+ c& B8 p( Y8 W9 i
  325. int32_t osKernelLock (void);
    3 t7 c/ x4 E1 B
  326.   N! t4 v6 f7 }) [
  327. /// Unlock the RTOS Kernel scheduler.
    5 ]1 E8 [$ M$ X) N
  328. /// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
    ; p6 X: p# e2 D$ R, x
  329. int32_t osKernelUnlock (void);
    5 I* G& H  t6 g) p5 @/ l7 n
  330. 0 R) f2 H* l1 N, ^9 J/ h- l
  331. /// Restore the RTOS Kernel scheduler lock state.+ D% z+ Y0 i" c; O. W
  332. /// \param[in]     lock          lock state obtained by \ref osKernelLock or \ref osKernelUnlock.1 h! f" v2 S# y& M9 ^( c* Z( F. p, q+ y
  333. /// \return new lock state (1 - locked, 0 - not locked, error code if negative).
    ! o0 k" l# ]/ V1 S4 k
  334. int32_t osKernelRestoreLock (int32_t lock);0 p' {" L+ M2 R

  335. ' s& C% K  Y0 O( z7 I& L3 `! d
  336. /// Suspend the RTOS Kernel scheduler.: i6 s  Q" n8 s4 o- z
  337. /// \return time in ticks, for how long the system can sleep or power-down.! f3 C, H7 j# ]; ]4 V* H0 e
  338. uint32_t osKernelSuspend (void);
    , u  l# E, ^  h- z5 N0 {- u6 U

  339. ; V8 q, s6 T! l/ A! \
  340. /// Resume the RTOS Kernel scheduler.
    8 |2 _# ?% m( v' p* t
  341. /// \param[in]     sleep_ticks   time in ticks for how long the system was in sleep or power-down mode.2 t3 E7 U7 [& ~4 W  B( A
  342. void osKernelResume (uint32_t sleep_ticks);6 ~7 z/ k% z1 f2 _. R
  343. ' K; n9 g9 j1 y; I
  344. /// Get the RTOS kernel tick count.
    ) O# K* \  P* v, u2 h6 V" y, \& z
  345. /// \return RTOS kernel current tick count.( x% Z) _, ]8 m8 p
  346. uint32_t osKernelGetTickCount (void);
      z7 C5 I  e  x) ^( ~

  347. * @% Y! W" t8 z7 Q
  348. /// Get the RTOS kernel tick frequency.1 O* }: l+ _# }8 g9 s) u
  349. /// \return frequency of the kernel tick in hertz, i.e. kernel ticks per second.: o) M0 {* @+ [6 }6 f
  350. uint32_t osKernelGetTickFreq (void);
    5 k2 j# b: {' G: _

  351. 5 W* g3 U1 q& v  F2 o' d
  352. /// Get the RTOS kernel system timer count.
    $ J6 R8 O) q9 ~7 f  _" e
  353. /// \return RTOS kernel current system timer count as 32-bit value.
    # T0 Q/ `( R( Z. Q" h; n, _
  354. uint32_t osKernelGetSysTimerCount (void);$ Q( U1 f1 h% M2 k. @3 H: B! _
  355. % ]% W* q, g5 @
  356. /// Get the RTOS kernel system timer frequency., L2 `' f% o! N
  357. /// \return frequency of the system timer in hertz, i.e. timer ticks per second.* _1 R. l( T$ y2 E) X; G$ o6 Y: S. J
  358. uint32_t osKernelGetSysTimerFreq (void);
    1 s5 q& P7 K( C% @
  359. + l6 y2 Y) ?7 p) k' F0 F
  360. 9 `$ j8 y, R2 |
  361. //  ==== Thread Management Functions ====7 }: t# y4 L4 F5 F
  362. ! c5 F" z" n0 \0 i+ k
  363. /// Create a thread and add it to Active Threads.) O. t6 d; u) X( R. A( W& N; I' w
  364. /// \param[in]     func          thread function.) i- \3 g& N" i  ~# `" j
  365. /// \param[in]     argument      pointer that is passed to the thread function as start argument.: M, `8 p% E5 v' d$ H+ [
  366. /// \param[in]     attr          thread attributes; NULL: default values.
    1 e* L" z, i3 J: f
  367. /// \return thread ID for reference by other functions or NULL in case of error.
    " P1 f5 t' r- \4 O9 O0 X0 u, z
  368. osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr);% _6 Q) z9 D3 c& x* D) ~
  369. " c9 P) ^7 g' g, m% j! X3 c
  370. /// Get name of a thread.$ |# S5 J3 k' x3 h$ [8 V/ B
  371. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    5 E/ V* l: n+ N- T4 |4 R3 c
  372. /// \return name as NULL terminated string.
    ' Y+ F/ Q* m7 f) f
  373. const char *osThreadGetName (osThreadId_t thread_id);3 \  C" L8 l3 P& d- B
  374. # Z0 v' e- _* p7 o8 O# o  }2 A& V
  375. /// Return the thread ID of the current running thread.
    % J- S+ Z3 _0 P, N
  376. /// \return thread ID for reference by other functions or NULL in case of error.
    ) |# D: L1 F2 `/ a
  377. osThreadId_t osThreadGetId (void);
    ( O5 O: K, Z- W+ y! |! E
  378. - v6 d! G; Q: H- p( S4 q% W
  379. /// Get current thread state of a thread.; M8 C. B& V' E' R8 X
  380. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    : w: S0 {: p, K3 N; x
  381. /// \return current thread state of the specified thread.
    8 W' u3 c$ f9 h+ P1 V9 U
  382. osThreadState_t osThreadGetState (osThreadId_t thread_id);  \# w; d& J0 t
  383. $ p0 ?+ b; d/ B1 @+ O  b* C
  384. /// Get stack size of a thread.! a+ J: `$ m7 J" `
  385. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.( v5 M  @/ ?* @$ h( @
  386. /// \return stack size in bytes.
    4 N! d) V8 F$ S% Q" ^1 c
  387. uint32_t osThreadGetStackSize (osThreadId_t thread_id);, S" r4 n' E, ?  \
  388. 2 C0 y, a+ N+ \) P
  389. /// Get available stack space of a thread based on stack watermark recording during execution.
    9 x  ^. @! e+ e
  390. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    / S/ ~! `3 l- `3 a
  391. /// \return remaining stack space in bytes.+ e5 g% {+ Z( q3 y. `* ?
  392. uint32_t osThreadGetStackSpace (osThreadId_t thread_id);
    , ^% T$ t* a# Q  |. f+ q$ n

  393. 4 V& f4 ]: g- A. Z( {/ f8 c* ?
  394. /// Change priority of a thread.
    % [8 c- h; r6 _0 R6 Z) [- `4 M! a
  395. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.5 Z9 d$ F1 ~7 A# P
  396. /// \param[in]     priority      new priority value for the thread function.
    - u; D% L" J, `# D4 K
  397. /// \return status code that indicates the execution status of the function.
    & E! h' H2 v. B) b4 w' N
  398. osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);
    . b6 ]1 H5 s1 G- P4 k  |9 \

  399. . P. K* y+ T. T' ?) x' R
  400. /// Get current priority of a thread.
      e# e2 V( v( J
  401. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    0 R/ T& H3 M) ^
  402. /// \return current priority value of the specified thread.
    $ E$ ^, l! Y( o/ U
  403. osPriority_t osThreadGetPriority (osThreadId_t thread_id);
    ) _+ X& T$ b. m  v

  404. ) i* p6 V0 x7 [$ ]0 K
  405. /// Pass control to next thread that is in state \b READY.
    / D" M# c( I6 }8 x! v- z1 ?  G4 H
  406. /// \return status code that indicates the execution status of the function.
    % d. L8 h- a; v( l$ o6 R
  407. osStatus_t osThreadYield (void);
    + _# ~  s/ T/ C" `, }" c" c3 o

  408. 3 `, p# i$ A7 w  F0 P" _! o6 g* m
  409. /// Suspend execution of a thread.
    9 o4 R! [% A0 y+ o7 z! Z
  410. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    & G' [# `0 ?" \% y* G
  411. /// \return status code that indicates the execution status of the function." |+ j& Y. y- H3 R- C; D, q$ |! Z
  412. osStatus_t osThreadSuspend (osThreadId_t thread_id);2 ]/ H+ T. Q8 p( F2 ^' g$ C3 E' ?* p/ |
  413. 9 V8 ~7 u, T9 V; b! w* ^3 ?. v
  414. /// Resume execution of a thread.3 |. B0 Z2 X* `7 M( i- G
  415. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    + q  F, L* O" O0 E& }3 @
  416. /// \return status code that indicates the execution status of the function.
    & z! t8 q! _; p; z
  417. osStatus_t osThreadResume (osThreadId_t thread_id);
    + `! e/ h2 A& S( r4 T* b
  418. " C4 Q; H$ m, [! x# h: B
  419. /// Detach a thread (thread storage can be reclaimed when thread terminates).
      n7 [* G' D6 @2 }0 d5 u
  420. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.4 y$ I9 o. H$ M+ q
  421. /// \return status code that indicates the execution status of the function.
    & ?8 i0 s8 }% B2 @
  422. osStatus_t osThreadDetach (osThreadId_t thread_id);
    ( B/ z+ L+ s. b1 V4 D
  423. ! D! z/ r  c  E- ^2 p- f
  424. /// Wait for specified thread to terminate.
    ' Q( q$ ^' Y: U0 m, a. V
  425. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.3 t) m: `" z& B) E" }! a( w
  426. /// \return status code that indicates the execution status of the function.
    3 p' t, z! ~8 q8 l# P; n
  427. osStatus_t osThreadJoin (osThreadId_t thread_id);2 }0 I& ~! t1 H4 F' M+ ?

  428.   U- f" P$ @0 R+ {
  429. /// Terminate execution of current running thread.
    - y8 g2 Q  r( w$ F
  430. __NO_RETURN void osThreadExit (void);
    ; V0 H/ x* Q, r% \3 L) }

  431. : F+ a1 |1 o, B9 c6 E3 \
  432. /// Terminate execution of a thread.7 j  a9 i, Y3 ~
  433. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.1 }4 U( {: N$ W# D  Z8 l0 [
  434. /// \return status code that indicates the execution status of the function.& P$ ]8 t; h. n( h- [
  435. osStatus_t osThreadTerminate (osThreadId_t thread_id);
    ( {) O/ t, P+ Y  M2 k
  436. - K! m& L( c9 Q0 X5 y6 N
  437. /// Get number of active threads.
      S8 n2 Z' T* y! T3 U
  438. /// \return number of active threads./ H9 D! V1 h6 j0 R1 R5 S
  439. uint32_t osThreadGetCount (void);
    - C0 w, O- S: L% \' v/ A

  440. # x8 s: A( {& A% i
  441. /// Enumerate active threads.
    ; \- [: n- U1 O0 T
  442. /// \param[out]    thread_array  pointer to array for retrieving thread IDs.7 Y( K% Z, J/ F+ a* D
  443. /// \param[in]     array_items   maximum number of items in array for retrieving thread IDs.+ e9 R3 \- }- P+ A
  444. /// \return number of enumerated threads.
    & N" j/ d; M2 N$ H2 `
  445. uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);
    , F& J/ e* I( V& b& Z5 m/ s
  446. ( a0 \: j" C, m- f8 ^

  447. % y! W5 E9 g- a
  448. //  ==== Thread Flags Functions ====5 E+ g/ Y1 A4 c+ R/ F2 C- {1 `

  449. 0 O+ t9 e9 \: ^- F- {2 L
  450. /// Set the specified Thread Flags of a thread.
    ( K% H6 q5 R: Q1 M$ X2 q* l7 ^
  451. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.; A, z$ D% P# y
  452. /// \param[in]     flags         specifies the flags of the thread that shall be set.
      T- q2 r1 T. K
  453. /// \return thread flags after setting or error code if highest bit set.
    ) V7 i* ]; Z7 U$ k" b, l
  454. uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags);" g/ q, X$ {: `( q6 t
  455. ( e: c( |1 {# Z0 @/ h* b
  456. /// Clear the specified Thread Flags of current running thread.
    4 ~( u6 g) _8 P" x7 r
  457. /// \param[in]     flags         specifies the flags of the thread that shall be cleared.8 i2 ?2 S1 v. z6 M! H9 O6 h  v
  458. /// \return thread flags before clearing or error code if highest bit set.
    $ ?5 |1 b: s& u5 m1 K, ?
  459. uint32_t osThreadFlagsClear (uint32_t flags);
    ( n+ C" F+ z4 S1 O

  460. 0 M' \; j7 A4 _4 j9 t( I
  461. /// Get the current Thread Flags of current running thread.* ?; b2 p' Q6 y2 S8 D2 Z, W  c# U
  462. /// \return current thread flags.3 u2 C" m  M( M( B2 b/ }
  463. uint32_t osThreadFlagsGet (void);
    ' q$ H( {3 A7 j9 M! t
  464. 6 k* i; [4 R, X
  465. /// Wait for one or more Thread Flags of the current running thread to become signaled.
    # @# B5 a3 Q( t" X$ k; f7 j1 x. h
  466. /// \param[in]     flags         specifies the flags to wait for.$ ^% C! y& ^  w, E. N$ e
  467. /// \param[in]     options       specifies flags options (osFlagsXxxx).
    * C* H+ r$ c' ~3 i; ]
  468. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
    3 `# G2 U  O/ P, r
  469. /// \return thread flags before clearing or error code if highest bit set.
    : ^" I6 m5 Y  e
  470. uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout);
    3 I! U. ~5 G- z- u
  471. % z! c  g5 O" u1 B7 D
  472. ) s$ D5 v4 w8 P9 v/ {! G
  473. //  ==== Generic Wait Functions ====: n6 v; e% d7 ?% u1 D

  474. + S0 z" P( w) c2 s4 h
  475. /// Wait for Timeout (Time Delay).
    , o, T  f' A; p  P& C, g( a; `
  476. /// \param[in]     ticks         \ref CMSIS_RTOS_TimeOutValue "time ticks" value3 c' K! K# Q7 ^  j0 j* W
  477. /// \return status code that indicates the execution status of the function.
    , u5 W3 m( k3 p0 b$ \5 V; p
  478. osStatus_t osDelay (uint32_t ticks);! U" ?2 I' U/ P
  479. % ]  {- `  Q' Q! w
  480. /// Wait until specified time.
    , G" R, ]9 {" \" A9 \$ s; s! I
  481. /// \param[in]     ticks         absolute time in ticks
    ! P1 \. `- O5 Z$ p! k; X" B
  482. /// \return status code that indicates the execution status of the function.
    ( }3 S8 ~4 x/ K5 H
  483. osStatus_t osDelayUntil (uint32_t ticks);& g& ^$ H! j: f- u) }, S( g
  484. ! ~: Y. m) A# c

  485. ; i* ]0 r- k* I
  486. //  ==== Timer Management Functions ====  s5 s* Q+ w( Y* T: W' p# }# G; {

  487. & L& n7 k7 b2 C( J: I& s% I
  488. /// Create and Initialize a timer.9 B; P! x& t) J7 I9 {' p- e8 t& B
  489. /// \param[in]     func          function pointer to callback function.
    " a. W+ |* u( G; i: ^4 \( E
  490. /// \param[in]     type          \ref osTimerOnce for one-shot or \ref osTimerPeriodic for periodic behavior.6 G1 d) @. M' S9 r, D4 L) l! @
  491. /// \param[in]     argument      argument to the timer callback function.
    % O2 Y' p( R' \" G
  492. /// \param[in]     attr          timer attributes; NULL: default values.
    ; G: |4 g  W" H6 f
  493. /// \return timer ID for reference by other functions or NULL in case of error./ H- @6 E0 b& I/ Y/ V
  494. osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
    & }, h- X8 g! G* u/ M

  495. 9 A- F' z3 b4 x  u0 W
  496. /// Get name of a timer.! _( F. ?, v, b6 u9 r# B8 ~- O
  497. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
    7 V$ Q# [: B  P+ D. w
  498. /// \return name as NULL terminated string.
    0 F5 ~) H) Y4 _: O& W
  499. const char *osTimerGetName (osTimerId_t timer_id);/ {9 o8 ^2 x/ S+ F3 A( c$ X0 z0 W( o/ L

  500. # a7 t3 s! A; u" C! v
  501. /// Start or restart a timer.
    $ e1 U' v3 z  D/ c% G+ V& v" ]
  502. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
    5 P5 N% [4 O* q1 I! x1 f
  503. /// \param[in]     ticks         \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer.
    3 I9 q' e: l1 h: b) t" e2 f
  504. /// \return status code that indicates the execution status of the function.
    / o% T5 I! P1 \% w3 {# w
  505. osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
    ! f" w$ ^7 N2 U: L& U

  506. * B" ]( [9 b- B6 D
  507. /// Stop a timer.
    " C" D" R' P  T. m
  508. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.. h( V, Z5 F& a  Y, H
  509. /// \return status code that indicates the execution status of the function.
    ' ]. v3 L! T% G4 D7 J2 M! t  h
  510. osStatus_t osTimerStop (osTimerId_t timer_id);; {+ V& [0 I' v% U
  511. + {8 Q. V4 y8 @3 R
  512. /// Check if a timer is running.
    : A2 ~* }4 x9 O9 L
  513. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
    7 X! ^1 S# Q+ L. v
  514. /// \return 0 not running, 1 running.9 E, _/ @# Z2 |* y
  515. uint32_t osTimerIsRunning (osTimerId_t timer_id);1 ]( ~) c1 k1 m. D6 t/ t9 X
  516. ! \" j% F) o2 o& M; @
  517. /// Delete a timer.% X- i# g4 z+ X1 U$ r( @! g
  518. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.* G) o1 k5 s) Q8 `" U
  519. /// \return status code that indicates the execution status of the function.
    & K  V, o) M0 n) }7 |6 x
  520. osStatus_t osTimerDelete (osTimerId_t timer_id);
    7 K+ M; b& ]7 V1 K( ^
  521. + W/ W- f) Z" x* k" q' ?

  522. & F, \4 |; \6 s3 K. X, }; i3 U" Q5 @" x6 k
  523. //  ==== Event Flags Management Functions ====
    4 {$ T4 [) `! E  A7 N
  524. % `: B* ^& ~! o& Z$ p3 d7 f
  525. /// Create and Initialize an Event Flags object.& O3 `# p, `6 ^6 ^
  526. /// \param[in]     attr          event flags attributes; NULL: default values.
    / i% p, k( F% X( i9 R# ~  m
  527. /// \return event flags ID for reference by other functions or NULL in case of error., y8 o# s8 S0 u' r3 \
  528. osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
      O0 n- _: e" ?2 A3 @, ~/ f& Y

  529. # j6 z( ~; K$ u( {8 ?+ w- o! q+ C
  530. /// Get name of an Event Flags object.9 R3 G; I2 d* d7 b) t. n6 }4 X
  531. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew./ e4 f7 [- q% t4 w! {' N( x8 N
  532. /// \return name as NULL terminated string.
    " u: }% G/ {# ]: s. p  {
  533. const char *osEventFlagsGetName (osEventFlagsId_t ef_id);
    5 |: B9 d7 G2 B

  534. " N  h5 R9 p0 z4 C0 c1 S  U
  535. /// Set the specified Event Flags.: ]8 ^4 M; }) o. S% {5 |
  536. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.
    2 F& z9 _. b. v4 J
  537. /// \param[in]     flags         specifies the flags that shall be set., U& d7 `, W; c7 y2 p
  538. /// \return event flags after setting or error code if highest bit set.
    ; q0 a4 R; t% V% M
  539. uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags);/ u$ _5 @5 A' @; v! f9 b

  540. 3 A* `; }- v7 `- f& ^
  541. /// Clear the specified Event Flags.
    4 n# o: s5 t9 }1 y( E
  542. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.
    ' B3 ]) W0 G# `7 u
  543. /// \param[in]     flags         specifies the flags that shall be cleared.3 X- [) n$ h8 M( a$ B- ?! d
  544. /// \return event flags before clearing or error code if highest bit set.
    1 i6 X+ {5 Z& z, U3 J
  545. uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags);
    6 j; u7 E( q0 ?) A! _# T

  546.   F' _+ C+ s  Y2 n
  547. /// Get the current Event Flags.
    ( e. |  K" Q  V0 l- [
  548. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.$ u9 W7 k6 q* `# B
  549. /// \return current event flags.9 C5 i# x( M( J: k, X
  550. uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);$ Q! o2 G. P+ D' t4 P2 k( l

  551. 1 v# a/ K. [7 n" [3 R
  552. /// Wait for one or more Event Flags to become signaled.
    8 k9 l, u3 ?9 t3 y( }) B1 n( y
  553. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.
    4 S4 L3 E: O# }/ f1 X0 y4 ^
  554. /// \param[in]     flags         specifies the flags to wait for.
    7 j0 w( j5 d. s
  555. /// \param[in]     options       specifies flags options (osFlagsXxxx).2 v' \1 J/ ?& O: u- o& x) F
  556. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.8 R+ p( l4 o' D3 L: A0 l
  557. /// \return event flags before clearing or error code if highest bit set.# d+ [4 `6 y0 |* |, e
  558. uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout);
    $ W# x0 f# T/ Z9 k

  559. ! W' g9 V4 h1 d% V8 i6 x7 K' |1 G7 P
  560. /// Delete an Event Flags object./ O5 J& i$ q+ _+ B
  561. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.9 b6 Q/ e8 i4 `( U( Y
  562. /// \return status code that indicates the execution status of the function.9 x' N; M: h& G, g7 _3 Z6 Y+ o
  563. osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);7 V& _- l1 E1 }0 p

  564. # z, j& x( B* h2 _* h* K
  565. + O3 d% F3 g* R1 _2 h3 C
  566. //  ==== Mutex Management Functions ====
    % r/ u& p9 a5 r$ I! z0 x0 N
  567. 3 A2 z& O# W6 O9 J! y
  568. /// Create and Initialize a Mutex object.2 K7 `: K) o) `+ u/ J& q
  569. /// \param[in]     attr          mutex attributes; NULL: default values.
    0 N# {* Z4 {$ J3 w! m, ]
  570. /// \return mutex ID for reference by other functions or NULL in case of error.
    0 J& E" b$ e7 {/ \' P8 d6 X
  571. osMutexId_t osMutexNew (const osMutexAttr_t *attr);
    4 e9 `* X3 M$ z; v3 o, N8 j! f

  572. 8 ^* g: w7 R# p# ]
  573. /// Get name of a Mutex object.
    + B; M- P. F0 M
  574. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.
    - l$ T$ W; l5 r3 c9 J4 M
  575. /// \return name as NULL terminated string.. }# Q" ]6 @% s/ Y( G" N
  576. const char *osMutexGetName (osMutexId_t mutex_id);
    % m5 x0 J8 {; t# @4 b7 a

  577. " W: v/ w! T7 S3 e
  578. /// Acquire a Mutex or timeout if it is locked.6 I, U9 K$ k4 ]  h2 x* d
  579. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.  |: [% S) ^( ^2 V+ u& r( b  W7 b' k
  580. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
    5 f. E' {9 I" w: o8 y7 N
  581. /// \return status code that indicates the execution status of the function.
    , z. Q3 X4 P9 o% L, ~
  582. osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);, e* {+ Y. h( w0 x8 X
  583. # }* `8 U# ]$ e
  584. /// Release a Mutex that was acquired by \ref osMutexAcquire.% O8 S  M& N. e, r5 j0 ?# I' \3 X
  585. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.6 v7 _: S1 ]5 {, D
  586. /// \return status code that indicates the execution status of the function.; F0 A+ q! N9 x
  587. osStatus_t osMutexRelease (osMutexId_t mutex_id);2 \7 X. L2 J+ L5 a7 l

  588. ) h( I6 ]* t2 F8 U6 J# B6 k8 T
  589. /// Get Thread which owns a Mutex object.* u3 o  s/ @( F: p4 j& o9 Y) o- |: j
  590. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.
    + T5 V( J+ Z  e0 X
  591. /// \return thread ID of owner thread or NULL when mutex was not acquired.* i8 l. F/ f4 Y1 s# v5 u
  592. osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);& |& E; G& B" U& ~

  593. ( Y0 n; d8 b9 H1 H/ ^1 o
  594. /// Delete a Mutex object.
    & E% ?; J/ D; m7 z9 S& i
  595. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew., P$ i# G; p! s1 C/ T
  596. /// \return status code that indicates the execution status of the function.
    / t( C& U3 M$ ?' Z& J# [# X
  597. osStatus_t osMutexDelete (osMutexId_t mutex_id);7 M! j# q) ~- m$ K

  598. ! J* n3 R! z2 L% E) C0 h8 X

  599. % L$ U7 V& F% G5 d5 h
  600. //  ==== Semaphore Management Functions ====
    8 W2 u; P( j5 B. m& [/ c& P4 i- r

  601. $ i/ e, _5 C9 o- G; u
  602. /// Create and Initialize a Semaphore object.
      k9 w/ v! Y& v  e/ L# J  x$ }# O
  603. /// \param[in]     max_count     maximum number of available tokens.
    2 L* J2 b( S# P- g% Z3 d
  604. /// \param[in]     initial_count initial number of available tokens.3 G& S/ [4 P' V% R
  605. /// \param[in]     attr          semaphore attributes; NULL: default values.7 g# s- ^( J5 o+ U  b; O: k
  606. /// \return semaphore ID for reference by other functions or NULL in case of error.
    2 W8 q3 x; Q2 j7 o0 E/ q% I
  607. osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
    $ D1 S7 W8 Q, a% C

  608. 3 F0 e' z* u$ I; S
  609. /// Get name of a Semaphore object.& w8 ^5 o$ `; Q1 V& ?0 r0 A
  610. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.& R/ D6 P4 f4 ?4 s# Z1 z
  611. /// \return name as NULL terminated string., K+ l* \0 B$ L1 J$ h2 M' @) W4 [
  612. const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);8 [! E- T$ p5 p& Y6 S- n

  613. # v# s. G1 J' s9 w3 h; ]
  614. /// Acquire a Semaphore token or timeout if no tokens are available.
    , J, o, J2 V, ]3 o- _
  615. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.
    : c# v- l- J/ {( R, k) X
  616. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.  u+ W/ t+ N) r9 d2 |
  617. /// \return status code that indicates the execution status of the function.* R9 P. i4 D! R' w: t
  618. osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout);
    . Z3 E) }3 i$ U7 M3 O" X8 }0 M# E

  619. ; z3 }, D& w5 p2 K1 M! _; P
  620. /// Release a Semaphore token up to the initial maximum count.
    ) B% F4 Z! K6 B/ d9 m  M2 L, k4 r
  621. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.
    # Z! y# I9 V) h8 R" n% b6 u. w
  622. /// \return status code that indicates the execution status of the function.
    $ G# ~" V. W1 I5 n/ b$ r
  623. osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
    2 L2 N3 w# o' H0 _! \

  624. + i9 ~; R. l! m0 Z; p4 p
  625. /// Get current Semaphore token count.
    * g0 b0 i% U, ~4 }
  626. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.
    ) W' X+ ?; a2 \  W9 o4 G# h
  627. /// \return number of tokens available.
    & M: f" N9 W" X  _& C  p
  628. uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);9 J! K. E' p- d# ]5 M

  629. 8 g3 S1 S6 H& s. S3 p& o( e
  630. /// Delete a Semaphore object.1 C7 W0 M- U( X# |: R
  631. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.) m) g2 Q* o0 E! w9 g" H! v+ \
  632. /// \return status code that indicates the execution status of the function.' O: }3 R1 A1 c1 V' j
  633. osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
    7 N6 ?  W8 Q# t; d

  634. ' v2 b0 r  _- }9 \. M: C* d
  635. 4 J5 s$ X* q% \( I. I+ F& q
  636. //  ==== Memory Pool Management Functions ====8 A: S2 X+ @) R% B
  637. ' @; m9 P. g% ?! T3 a  [% `
  638. /// Create and Initialize a Memory Pool object." R. l' _3 ]+ c: N
  639. /// \param[in]     block_count   maximum number of memory blocks in memory pool.: }6 x* _- h1 P4 a9 L) H
  640. /// \param[in]     block_size    memory block size in bytes.1 f" V7 t) A. S9 J
  641. /// \param[in]     attr          memory pool attributes; NULL: default values.9 h, I6 m# w3 V1 c# b. ^
  642. /// \return memory pool ID for reference by other functions or NULL in case of error.
    6 X# b! x: N. `3 b! M& B
  643. osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);- _/ d; R7 h+ U
  644. 0 L/ n9 r, v' X! y
  645. /// Get name of a Memory Pool object.9 j  q( H! G& z3 U! T2 m  K# M" Y
  646. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.
    $ B# X5 q9 I( ^1 v# l9 d' S2 L4 G
  647. /// \return name as NULL terminated string.
    ' c5 Q7 w# U" h  l. t+ V; F4 w) {/ A
  648. const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id);7 |3 K2 n# D$ `( i9 f

  649. . h- i/ W( {1 o  m3 N5 Z8 R
  650. /// Allocate a memory block from a Memory Pool.+ e' _( h/ ?- {5 J0 q
  651. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.+ Z. ?: P$ G$ @) Y
  652. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
    3 c7 N+ h4 T& [6 M/ }9 c% t
  653. /// \return address of the allocated memory block or NULL in case of no memory is available.
    # w& J3 n0 y) Q1 O3 y1 S1 l
  654. void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout);
      b! x2 s3 i0 E3 a* T- ^3 _/ A
  655. / R. p6 I- A2 t3 a* I- ?! n. }
  656. /// Return an allocated memory block back to a Memory Pool.
    - k1 Q6 _# ^, q2 h! G
  657. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.+ n! o8 E: l6 F; B; I
  658. /// \param[in]     block         address of the allocated memory block to be returned to the memory pool.1 n& t2 C5 e6 A' }6 J4 c
  659. /// \return status code that indicates the execution status of the function.9 J7 d, T8 e( d( d" d  |
  660. osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);- r. B6 K" r: q! L, H8 @6 f

  661. / @  {( m* d' I: p! E, d
  662. /// Get maximum number of memory blocks in a Memory Pool.; u/ j  D) @; p, m5 Q7 v! p
  663. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.# s7 Q( h# _# L, Q$ \) J
  664. /// \return maximum number of memory blocks." W0 c' L; M% s
  665. uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);+ |9 I) z$ T2 J; @3 b: H
  666. + \; N4 U; V3 k- F
  667. /// Get memory block size in a Memory Pool.
    1 [% e0 C! a% J* j" R
  668. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew., q# o: F: v2 S
  669. /// \return memory block size in bytes.) Y' S9 L9 J* E3 }
  670. uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
    1 B6 n  i1 t8 W

  671. ! }9 i, h2 j% h8 }4 S/ d5 a$ _; u
  672. /// Get number of memory blocks used in a Memory Pool." ^; o7 h4 v2 ]7 |) i" E; F' L
  673. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.) T# F; ?' m' K! X4 l
  674. /// \return number of memory blocks used.
    7 ~" B/ B, S, S$ {  s3 }& C+ @
  675. uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
    ' u9 K7 A/ b# ?( A. k' f2 e4 y, x

  676. # q2 I  i4 {5 X' P, t0 ^3 H
  677. /// Get number of memory blocks available in a Memory Pool.
    ; z: f. I6 u+ J. R
  678. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.+ C( @6 `0 V% s- Y+ @8 Q+ c
  679. /// \return number of memory blocks available.- o; ^/ E0 L3 R4 p. g
  680. uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
    $ m( B( f' N& T- r/ _
  681.   `( u2 z  W, g4 O2 @3 u
  682. /// Delete a Memory Pool object.6 O7 I: R, f8 }* G/ P5 ?% M
  683. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew., y, f0 V* P! p. v+ r$ q2 e: p
  684. /// \return status code that indicates the execution status of the function.  x* ?# c  ~( b
  685. osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);* L6 v3 w9 N; F( [' r
  686. 9 a- V* L( c: E( y- V! [

  687. ) A( j0 b  s- ?1 {0 j
  688. //  ==== Message Queue Management Functions ====
    % T5 Y6 N4 K9 `7 i3 g$ l  h8 Q

  689. 8 Z: b) o$ D6 j8 c4 I: D; a
  690. /// Create and Initialize a Message Queue object.9 {" `  n8 G. A8 A9 d
  691. /// \param[in]     msg_count     maximum number of messages in queue.
    1 H5 V, a1 P/ o) E
  692. /// \param[in]     msg_size      maximum message size in bytes.
    2 z- |5 H. g+ ^& o' l
  693. /// \param[in]     attr          message queue attributes; NULL: default values.1 k$ E7 D$ r* _; J8 w
  694. /// \return message queue ID for reference by other functions or NULL in case of error.& r( d. b# U# E0 ~1 b& s
  695. osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
    $ `+ t/ v0 p3 ]' v. C5 L9 X# @

  696. # P' h& B. U8 K- f' s$ e
  697. /// Get name of a Message Queue object.  ^2 `" {# B1 A
  698. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.
    6 o8 D0 n3 w8 n
  699. /// \return name as NULL terminated string.. E' l$ s) y6 {; W* E: [$ S4 x
  700. const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
      P3 n. m) V' O2 V) w
  701. 1 J4 h: k  r- V! w5 N) m
  702. /// Put a Message into a Queue or timeout if Queue is full.
    5 j1 D# W( X( d  `8 n$ i
  703. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.
    $ M. [: H7 h. a  n: `4 s
  704. /// \param[in]     msg_ptr       pointer to buffer with message to put into a queue.5 u5 _; B1 r: X% [7 a( F
  705. /// \param[in]     msg_prio      message priority.
    , e; o0 y% V2 e" p7 w8 ^! s
  706. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.& t0 K& ]4 s# Y' d# q. H
  707. /// \return status code that indicates the execution status of the function.
    7 W* ?; b% h, T/ m9 r+ [- t+ t2 g
  708. osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);5 T% f  q4 L/ P5 V

  709. . i" X7 g1 n- `& ?8 ~- k% A2 y
  710. /// Get a Message from a Queue or timeout if Queue is empty.3 P! u/ J+ m) ]/ [' z" }. P1 m9 j. a& Y
  711. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.% G: V9 G# V- E
  712. /// \param[out]    msg_ptr       pointer to buffer for message to get from a queue.& u! ?7 _% r  V# Z& e  h
  713. /// \param[out]    msg_prio      pointer to buffer for message priority or NULL.
      a. H/ l) n. z9 ^+ F6 g
  714. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
    7 `  J+ h  g  m( g! A$ W1 d
  715. /// \return status code that indicates the execution status of the function.
    : S+ k* ]& J0 _0 f
  716. osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);6 P" f6 g8 s8 ^& g/ z
  717. : h8 n- ^, c! M& U& |; l* |
  718. /// Get maximum number of messages in a Message Queue.
    : f& J) t# c5 `- ^/ n0 F$ k
  719. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.
    % X6 s! A8 G3 Y: j
  720. /// \return maximum number of messages.
    ( u& g: l& B3 [9 {  C) x
  721. uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);% [$ a9 D+ W" o3 E6 J9 D' [3 x
  722. - |3 V' O! L  p' [" x- E
  723. /// Get maximum message size in a Memory Pool.$ a# ~/ J  r& A5 `4 D
  724. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.) r0 e1 y1 S' Q# P2 J
  725. /// \return maximum message size in bytes.
    2 p# @  E% S, l9 @
  726. uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);  ]; I4 N" K+ B2 v2 g+ H) i) \
  727. ' {7 D9 p# {6 Q  A- Q. V; h4 T
  728. /// Get number of queued messages in a Message Queue.
    ' z) I* U6 u6 ~& H! W- l1 N, A
  729. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.
    : q( m; `) v9 j; b
  730. /// \return number of queued messages.( l# p  {. v% G2 r5 P- O3 O+ k
  731. uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);& M( W: I' Q  F5 q/ Q

  732. 5 v- _; @& O% |9 ?9 w+ U
  733. /// Get number of available slots for messages in a Message Queue.
    # _8 V5 p% H- L. J
  734. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.  c( k  h% B0 X6 T
  735. /// \return number of available slots for messages./ s4 e/ C3 d" T/ W/ o0 n
  736. uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
    $ ^" h# G- s" N4 G

  737. ; j( Q% G# C* J* U* h+ T# b
  738. /// Reset a Message Queue to initial empty state.
    * T4 f) T/ E, D4 v" v4 W
  739. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.2 O/ ?- D' Q; S6 G! R
  740. /// \return status code that indicates the execution status of the function.
    7 J, w* F0 y* {( A! o/ b
  741. osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);* o) ]  f, ?" O0 J8 ?* E
  742. 9 T: @8 M  \% t
  743. /// Delete a Message Queue object.2 I5 K' v+ d# y6 c; F
  744. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.
    + z" a: G3 _9 d$ {  J( Z. y& `
  745. /// \return status code that indicates the execution status of the function.0 b* `8 F" I' p% [" W2 L9 ?
  746. osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);9 h' [2 o, T. j# H

  747.   l% s1 _4 `/ P/ q
  748. 3 ^# L7 X4 e3 a2 a/ H+ V2 c4 i
  749. #ifdef  __cplusplus
    5 ~1 w: l. C% i' x
  750. }8 |0 h) Z7 m# w. V3 {: V
  751. #endif8 y" w  ~; j7 L! L
  752. 7 D+ m  C. K. b6 q' R2 l. \/ N% V
  753. #endif  // CMSIS_OS2_H_
复制代码
5 @8 l3 o; j, A. B- C5 a' B; |
归档链接:
1 Z3 v# Z4 @- F9 {  ZCMSIS-RTOS2 文档翻译 之 简介5 a* T( Z8 C3 w  I4 |2 F( g
CMSIS-RTOS2 文档翻译 之 修订记录
6 t$ @7 C, ^. XCMSIS-RTOS2 文档翻译 之 功能概述$ b) r* s+ S0 N1 h8 P
CMSIS-RTOS2 文档翻译 之 RTOS 验证
收藏 评论4 发布时间:2018-4-21 15:48

举报

4个回答
黑皮男 回答时间:2018-4-21 16:36:17
支持,我现在用的是cmsis_os接口
XinLiYF 回答时间:2018-4-22 09:14:50
黑皮男 发表于 2018-4-21 16:36# N0 {! r; y$ e" J
支持,我现在用的是cmsis_os接口
0 N& ]: c) s8 X2 m' s! v) P9 f' n
就是相关的教程和文档比较少,用的人比较少,你很有前瞻性啊。
黑皮男 回答时间:2018-4-22 09:42:30
XinLiYF 发表于 2018-4-22 09:14- H$ H9 E4 Z- H0 i. O& p6 K0 f4 k. L
就是相关的教程和文档比较少,用的人比较少,你很有前瞻性啊。
' o  p8 k9 E# Z+ G
之前都是自己封装RTOS的接口,发现cmsis_os后,既然都有统一的接口,干脆就拿来用了,比自己封装的要好很多
XinLiYF 回答时间:2018-4-22 10:26:00
黑皮男 发表于 2018-4-22 09:42
& W) K/ O, z1 X, G( b7 I, B之前都是自己封装RTOS的接口,发现cmsis_os后,既然都有统一的接口,干脆就拿来用了,比自己封装的要好很 ...

& N7 x* S% \7 Z/ o( {刚去你 GitHub 逛啦一圈 ,你肯定是一个外表粗犷内心细腻的人 ,GitHub 上关注你了

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版