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

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

[复制链接]
XinLiYF 发布时间:2018-4-21 15:48
本帖最后由 XinLiYF 于 2018-4-22 21:59 编辑
! [" c6 h0 P7 \3 U- a% }, B+ Y
6 K1 j: f4 W" l6 N: o$ P
通用 RTOS 接口
& x1 _+ R3 ^8 y* y8 G* W+ I% U

/ i& r" c- x5 j7 k; J8 P. {% G5 M6 A
CMSIS-RTOS2 是一个通用的 API ,不受底层 RTOS 内核的影响。应用程序员在用户代码中调用 CMSIS-RTOS2 API 函数以确保从一个 RTOS 到另一个 RTOS 的最大可移植性。使用 CMSIS-RTOS2 API 的中间件可以避免不必要的移植工作。
  X+ v6 v& o  D7 S

- H9 e# C3 }; c8 VCMSIS-RTOS API 结构
& c# B) ?: S: I4 @  z! c
0 `& L& T5 I* o2 f
典型的 CMSIS-RTOS2 API 实现与现有的实时内核接口。CMSIS-RTOS2 API 提供以下属性和功能:

% e& [6 y( w! Y8 o: c* o; X$ N& |
  • 函数名称,标识符和参数是描述性的,易于理解的。这些功能强大而灵活,减少了暴露给用户的功能数量。
  • 线程管理允许您定义,创建和控制线程。
  • 中断服务程序(ISR)可以调用一些 CMSIS-RTOS 功能。 当 CMSIS-RTOS 函数不能从 ISR 上下文中调用时,它会拒绝调用并返回错误代码。
  • 三种不同的事件类型支持多个线程和/或 ISR 之间的通信:) r9 N. }$ B9 y! e/ @6 e
    • 线程标志: 可用于向线程指示特定条件。
    • 事件标志: 可用于向线程或 ISR 指示事件。
    • 消息: 可以发送到线程或 ISR 。消息缓冲在队列中。
        f# D6 t- u# l8 [4 A) l5 t0 P
  • 互斥管理和信号量已合并。
  • CPU 时间可以安排以下功能:; h2 o9 X6 o3 ~* |6 V' H5 B0 y& j  F
    • 超时参数包含在许多 CMSIS-RTOS 功能中,以避免系统锁定。当指定超时时,系统会等待,直到资源可用或发生事件。在等待时,运行其他线程。
    • osDelay 和 osDelayUntil 函数将线程置于 WAITING 状态一段指定的时间。
    • osThreadYield 提供协作式线程切换并将执行传递给具有相同优先级的另一个线程。
      % L0 l7 M4 S, L/ h1 s2 w7 E
  • 定时器管理功能用于触发功能的执行。
    . b7 F" t6 S% R6 ^0 H% H
, R0 t5 D1 O; X0 V7 f. b
CMSIS-RTOS2 API 旨在通过 Cortex-M 存储器保护单元(MPU)选择性地整合多处理器系统和/或访问保护。

3 j& }- k' u+ {" V
在一些 RTOS 实现中,线程可能在不同的处理器上执行,因此消息队列可能驻留在共享内存资源中。
1 z* X! j# X1 g6 X5 X, V0 |
CMSIS-RTOS2 API 鼓励软件行业发展现有的 RTOS 实施。实时操作系统的实现可以在针对 Cortex-M 处理器的不同方面进行不同的优化。可选功能可能是例如

( Y( z! {$ \" A/ ?4 \0 ^6 ~- u4 `
  • 支持 Cortex-M 内存保护单元(MPU)。
  • 支持多处理器系统。
  • 支持 DMA 控制器。
  • 确定性上下文切换。
  • 循环上下文切换。
  • 避免死锁,例如优先倒置。
  • 通过使用 Armv7-M 指令 LDREX 和 STREX 来实现零中断延迟。9 m* k, K$ F' z( _/ }; _0 J; T( {2 s
6 W; @* U% d* r% B% o) [" _; @
使用 CMSIS-RTOS2 实现
* F$ ~) W+ X4 R* I/ }# ?* K
CMSIS-RTOS2 实现通常作为库提供。要将 RTOS 功能添加到现有的基于 CMSIS 的应用程序中,需要添加 RTOS 库(通常是一个或多个配置文件)。有一个新的头文件 cmsis_os2.h 可用。这是完全可移植应用程序所需的唯一头文件。在这种情况下,不能使用用户为控制块,对象数据和线程堆栈提供的内存。或者,您可以包含一个实现特定的头文件(例如 rtx_os.h),该文件还提供了用于资源分配的定义(例如控制块的大小,对象数据和线程堆栈所需的内存)。 这是可选的,意味着应用程序代码不是完全可移植的。
7 n" ~7 N9 l7 ^; U6 G2 N, r

1 d/ F2 B2 G' J4 l& ]3 f+ y# JCMSIS-RTOS 文件结构
# s/ ~7 c+ Q+ J8 K

* D6 ^0 b% U7 f0 r$ O. p

" R& B/ t7 s8 d  M
将文件添加到项目后,用户可以开始使用 CMSIS-RTOS 功能。下面提供了一个代码示例:
/ l( Z' f9 ]. Q3 }. ~4 r
代码示例
  1. /*----------------------------------------------------------------------------2 ^! M; h, y3 a/ @
  2. * CMSIS-RTOS 'main' function template/ i/ ^' o6 w* K1 Z8 |0 W4 l
  3. *---------------------------------------------------------------------------*/# Q! Z& m% A) P$ Y! j

  4. ! X, i& N- N/ Z2 I7 X; l! @" I9 x
  5. #include "RTE_Components.h"
    0 t9 ]5 y9 C; T) s1 c4 W
  6. #include  CMSIS_device_header( q$ Y. k! k* {2 ?5 m8 J# s
  7. #include "cmsis_os2.h"6 Y7 g, [  ]2 j. a6 W
  8. $ K* {, m- @; L0 |% n2 @
  9. /*----------------------------------------------------------------------------
    8 l4 y# H/ ~% T( V
  10. * Application main thread
    8 d9 C+ ?3 H$ H- i& U
  11. *---------------------------------------------------------------------------*/3 k. G7 X1 _7 K6 @( |; B& ^
  12. void app_main (void *argument) {% j1 Q8 _; j1 N6 X7 O& G* p$ [) K: n

  13. 5 d: O- w! e/ d% o  c
  14.   // ...
    2 q- n1 m7 N$ A5 X3 f/ d
  15.   for (;;) {}. T% b2 R0 Z3 `0 d$ v( q
  16. }/ A2 N; g3 J5 n# Y" [7 k( {
  17. $ z8 o( b+ _3 }7 y3 d
  18. int main (void) {
    : A  B5 U4 n8 D% X- N! y$ v
  19. 9 I0 S4 W6 {  s4 A0 T( {  x
  20.   // System Initialization
    3 X  S6 b$ z3 T6 ?
  21.   SystemCoreClockUpdate();
    ) E. L! R" U+ K3 E5 `: K# X
  22. #ifdef RTE_Compiler_EventRecorder
    + o% O0 S* t: T1 c% y
  23.   // Initialize and start Event Recorder
    # t5 O9 p1 N* [% }: P
  24.   EventRecorderInitialize(EventRecordError, 1U);
    ( f4 l' J% c4 V
  25. #endif! u( Y; [  w/ l. y1 L
  26.   // ...! F- ?/ e: I( Q; F5 P

  27. 5 _$ \6 q) r# D8 k1 S
  28.   osKernelInitialize();                 // Initialize CMSIS-RTOS
    5 K$ k/ T! N; m; V
  29.   osThreadNew(app_main, NULL, NULL);    // Create application main thread2 W% X# @- k" V( h0 K) g1 m( T
  30.   osKernelStart();                      // Start thread execution
    / ^. Y0 X, b& K0 o3 I! p
  31.   for (;;) {}
    % i: e, x9 e% N
  32. }
复制代码
5 s, w# h/ d& @2 E6 b
cmsis_os2.h 头文件
; J' Z5 j6 t! X' |/ d/ R, @
文件 cmsis_os2.h 是一个标准头文件,与每个 CMSIS-RTOS2 兼容的实时操作系统(RTOS)相连接。每个实现都提供了相同的 cmsis_os2.h ,它定义了到 CMSIS-RTOS2 的接口。
9 l* G5 y( l  W6 O; d
通过使用 cmsis_os2.h 和动态对象分配,可以创建在不同的 CMSIS-RTOS2 实现上使用时不需要修改的源代码或库。

& B$ H  v! z" L! Z& {1 q- E
头文件 cmsis_os2.h
  1. /*
    , r/ p# n6 B9 j! R! q3 ^
  2. * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
    & [+ e; Z( Y4 z( u
  3. *
    2 M8 X3 ]5 [: M/ x
  4. * SPDX-License-Identifier: Apache-2.04 x2 B. Q1 Z2 V8 z0 t; @# w7 |
  5. *
    6 j* D- j' ^! g
  6. * Licensed under the Apache License, Version 2.0 (the License); you may9 p9 g, F6 X, ~4 p  D( M0 q1 }% s! c
  7. * not use this file except in compliance with the License., ?4 Y9 L# Z0 s: r; q& P
  8. * You may obtain a copy of the License at1 S' }& A0 R+ T. a8 ?
  9. *
    6 V+ g8 V2 q" @5 {: G6 v
  10. * www.apache.org/licenses/LICENSE-2.0
    0 U) J: H2 D6 ~# B
  11. *9 Q: e  V7 ?& {! _/ F
  12. * Unless required by applicable law or agreed to in writing, software
    9 W* t5 m% P! l- q/ f0 |
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
    7 x: m) s, L0 N: t  x& @
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.5 |, J* z5 W1 K) Z" _" t
  15. * See the License for the specific language governing permissions and8 z# x# `) l, m, X, x5 U
  16. * limitations under the License." J, f6 p( _  U+ T4 S% u5 L
  17. *
    + W8 a$ p/ t! m5 P7 q+ W- M
  18. * ----------------------------------------------------------------------
    9 z: {( h* j$ F) d# W
  19. *- E3 \! O5 q7 Y% x1 Y" n
  20. * $Date:        30. October 2017
    2 D! Y) \; S/ o, d7 ^( ~
  21. * $Revision:    V2.1.2# K- i+ x& ]0 q+ t  \, V
  22. *6 y: J$ Z* Q2 N
  23. * Project:      CMSIS-RTOS2 API. y; s& ]4 N! Z6 g
  24. * Title:        cmsis_os2.h header file
    0 E4 k& Z9 Y% o; a" a
  25. *: _- X* n6 H. x+ c2 Y
  26. * Version 2.1.2
    3 c9 j( P- |. }
  27. *    Additional functions allowed to be called from Interrupt Service Routines:* C1 k( q( D- U
  28. *    - osKernelGetInfo, osKernelGetState9 e! p7 I' r. Q- J* n; w# N5 n" E! f) B
  29. * Version 2.1.1
    , {( C. C; A9 L9 [7 e
  30. *    Additional functions allowed to be called from Interrupt Service Routines:7 v  ?: q& Q) b, d
  31. *    - osKernelGetTickCount, osKernelGetTickFreq8 a$ j% n3 S" N" {: X
  32. *    Changed Kernel Tick type to uint32_t:
    1 \% l, e7 K1 G+ w% G% t/ h' V
  33. *    - updated: osKernelGetTickCount, osDelayUntil9 F' ~4 ]8 N# ^
  34. * Version 2.1.0, o3 \+ _( `. x2 c) i4 A
  35. *    Support for critical and uncritical sections (nesting safe):/ [. ?4 k7 s  s' y
  36. *    - updated: osKernelLock, osKernelUnlock8 x# P5 `" S% e  k8 _! ~8 G
  37. *    - added: osKernelRestoreLock3 p( J8 {4 m7 C' ]
  38. *    Updated Thread and Event Flags:* S+ E1 S/ U+ R+ n' T6 l
  39. *    - changed flags parameter and return type from int32_t to uint32_t1 B+ F6 S% R3 d1 a( P0 y
  40. * Version 2.0.0' D4 s+ o  x! Y. B) g' m. e* l3 e9 I
  41. *    Initial Release* u4 X7 D* f# b5 p; q
  42. *---------------------------------------------------------------------------*/
    3 h1 X" c& V/ [( i# o
  43. 6 |, w  ~1 g' h3 H7 \- T7 u
  44. #ifndef CMSIS_OS2_H_
    0 v* |( N  X0 [& u& m6 y
  45. #define CMSIS_OS2_H_; U/ Y5 b: z+ t4 b' g: n4 V
  46. 4 i! `8 t$ d( ^1 C
  47. #ifndef __NO_RETURN
    0 n! P+ X7 V  X1 R7 Q3 o
  48. #if   defined(__CC_ARM)
    + w8 n% c, ?: D3 y
  49. #define __NO_RETURN __declspec(noreturn)( {# x! ]. F) a' l) y4 k) j
  50. #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
    1 B& O( r, Q" m0 o& \# v
  51. #define __NO_RETURN __attribute__((__noreturn__))3 |4 `' L+ C( n3 H- O
  52. #elif defined(__GNUC__)4 j$ w3 [' k- y- l7 h4 U: F, A& W1 ?9 s
  53. #define __NO_RETURN __attribute__((__noreturn__))
    3 F1 _! t$ W/ M2 g, d& Z3 F
  54. #elif defined(__ICCARM__)' [; ?; P6 I& E* p. G( p4 N
  55. #define __NO_RETURN __noreturn
    . r* T* x$ r" h
  56. #else
    ' M0 N3 V9 B+ A7 r% j
  57. #define __NO_RETURN* p; `- Y5 L6 r: G% r4 ^
  58. #endif
    $ `- I! M6 b& O  K. g! ^  o
  59. #endif
    + W/ Y" b0 J* T7 e9 C2 F

  60.   r, Z0 v; O* I: n9 C/ x, k) V5 X
  61. #include <stdint.h>0 z' q! w# n  c" I& e; @# ?( ^
  62. #include <stddef.h>8 g5 |7 C1 Q4 r! o! y# Z7 p/ j. [

  63. 4 m: e2 |; b, V% U9 {2 n
  64. #ifdef  __cplusplus9 |% C; L. r6 K0 O) M  p8 v
  65. extern "C"
    4 c9 j* R  {1 @. s+ \1 t! Q
  66. {& d" e! R0 L& j2 h2 z
  67. #endif" _: w# O3 b& X7 \% |/ \( N
  68. $ F8 G# O1 f, a6 Q
  69.   q4 ^' D7 B9 u7 f3 [2 @; h7 E+ Y
  70. //  ==== Enumerations, structures, defines ====: l& ~9 H  e1 O$ B9 F: a4 I" j
  71. " ^% Z. y0 j( E4 N1 V7 O% b
  72. /// Version information.
    + E) p% n: U( k% G& ~
  73. typedef struct {% {3 T+ b& a$ M! b' a1 ^
  74.   uint32_t                       api;   ///< API version (major.minor.rev: mmnnnrrrr dec).7 S; \% {! w+ |3 w6 r+ b# e7 X1 y
  75.   uint32_t                    kernel;   ///< Kernel version (major.minor.rev: mmnnnrrrr dec).
    : B; C9 {( P$ Q  n
  76. } osVersion_t;
    1 |+ Q3 ^+ @% _+ E
  77. 5 N( ?4 p: Y% l
  78. /// Kernel state.
    4 W2 r% ?2 `, ]7 K/ t
  79. typedef enum {2 k# k, b& w+ L3 v
  80.   osKernelInactive        =  0,         ///< Inactive.
    4 i  q3 P( J; |) `, |/ ^
  81.   osKernelReady           =  1,         ///< Ready.
    : d7 L; |$ i2 m' G( `- ^3 F
  82.   osKernelRunning         =  2,         ///< Running.
    5 P8 \/ k4 B5 p$ H
  83.   osKernelLocked          =  3,         ///< Locked.$ p% p5 k. r. Q! m# W
  84.   osKernelSuspended       =  4,         ///< Suspended.
    % V% e' V/ Q0 ]8 [
  85.   osKernelError           = -1,         ///< Error.6 k0 t' l. w$ T
  86.   osKernelReserved        = 0x7FFFFFFFU ///< Prevents enum down-size compiler optimization.
    , w  v. |' i: `: r  M
  87. } osKernelState_t;7 S. l- n8 ?1 O

  88. 4 @9 f5 d) @; |( Z8 j3 ]) h- f
  89. /// Thread state./ r* K% P9 L/ U0 z
  90. typedef enum {* g. U  e, t$ ^0 ?5 g% s
  91.   osThreadInactive        =  0,         ///< Inactive.3 T1 j4 A4 }# B* f9 _9 _' W" S% }
  92.   osThreadReady           =  1,         ///< Ready.
    9 L, S  @$ s9 n- c
  93.   osThreadRunning         =  2,         ///< Running.$ G* ~% _7 h( H' U8 \6 Z& ?4 z
  94.   osThreadBlocked         =  3,         ///< Blocked.
    & I, Y, B9 E# v- M  U
  95.   osThreadTerminated      =  4,         ///< Terminated.9 h0 s3 p9 K& Q
  96.   osThreadError           = -1,         ///< Error.# M4 [* N3 Y) Y$ I+ r3 ?
  97.   osThreadReserved        = 0x7FFFFFFF  ///< Prevents enum down-size compiler optimization.
    4 q7 A$ U  W/ ^. u6 X9 ^2 o
  98. } osThreadState_t;
    2 p0 \! w6 a/ e6 ^# C; G

  99. " S& P: z. x/ W, ~/ n. I' Y
  100. /// Priority values.
    , s0 m" k1 _! M) C' v
  101. typedef enum {" w/ c( Z( M) \7 H$ Y/ N% g
  102.   osPriorityNone          =  0,         ///< No priority (not initialized).
    ( G  q! X' s" O
  103.   osPriorityIdle          =  1,         ///< Reserved for Idle thread.
    4 }2 Y! O  A: F& S) g. c3 v) Q( @
  104.   osPriorityLow           =  8,         ///< Priority: low: ?! v5 q7 [/ o8 z
  105.   osPriorityLow1          =  8+1,       ///< Priority: low + 1# n. D  A2 q* e: |& F0 `
  106.   osPriorityLow2          =  8+2,       ///< Priority: low + 2
    ) s/ R7 ?0 w7 }* |: t
  107.   osPriorityLow3          =  8+3,       ///< Priority: low + 3
    : d2 A6 \4 q( Z/ o
  108.   osPriorityLow4          =  8+4,       ///< Priority: low + 49 n6 R% ~+ V' r$ w) W5 j
  109.   osPriorityLow5          =  8+5,       ///< Priority: low + 57 U, r& ?+ j% |5 ~7 f2 h8 a
  110.   osPriorityLow6          =  8+6,       ///< Priority: low + 6: I9 I$ e$ b  g* K! w( K
  111.   osPriorityLow7          =  8+7,       ///< Priority: low + 7
    % O' ], A2 n9 H0 d  n
  112.   osPriorityBelowNormal   = 16,         ///< Priority: below normal/ i  v9 H" ?3 k- {
  113.   osPriorityBelowNormal1  = 16+1,       ///< Priority: below normal + 1
    $ C. _! e' x, r7 \. O% Z
  114.   osPriorityBelowNormal2  = 16+2,       ///< Priority: below normal + 2
    + a) L; F9 J/ [
  115.   osPriorityBelowNormal3  = 16+3,       ///< Priority: below normal + 3
    9 h  Z6 v; f& t5 Q# b
  116.   osPriorityBelowNormal4  = 16+4,       ///< Priority: below normal + 4
    + B* \- m9 _% V+ R, U' x
  117.   osPriorityBelowNormal5  = 16+5,       ///< Priority: below normal + 5. J4 _+ Z  \9 u$ e) y8 i" T) @3 Y
  118.   osPriorityBelowNormal6  = 16+6,       ///< Priority: below normal + 6
    7 K$ |, n7 l8 m# i) N& A0 e: M
  119.   osPriorityBelowNormal7  = 16+7,       ///< Priority: below normal + 72 Z; y7 b4 E8 ?* K4 u+ J
  120.   osPriorityNormal        = 24,         ///< Priority: normal
    3 @" `) B# B. j
  121.   osPriorityNormal1       = 24+1,       ///< Priority: normal + 19 w0 D9 ^$ \4 t5 ?' l2 Z
  122.   osPriorityNormal2       = 24+2,       ///< Priority: normal + 2
    9 N# B: o5 n% P/ @5 i
  123.   osPriorityNormal3       = 24+3,       ///< Priority: normal + 3
    * u2 v& k. F; E/ \- ^8 v6 B
  124.   osPriorityNormal4       = 24+4,       ///< Priority: normal + 4$ ^, U1 u- o. f
  125.   osPriorityNormal5       = 24+5,       ///< Priority: normal + 5
    0 c! t8 r4 Z- R* q. n; B
  126.   osPriorityNormal6       = 24+6,       ///< Priority: normal + 6
    . F7 w; c! L/ I* l
  127.   osPriorityNormal7       = 24+7,       ///< Priority: normal + 7
    ! {: t8 A. ^2 L, E8 y( V& H5 \
  128.   osPriorityAboveNormal   = 32,         ///< Priority: above normal
    7 a* P' R! a* Y4 ^3 @
  129.   osPriorityAboveNormal1  = 32+1,       ///< Priority: above normal + 1
    * O9 u" M- x4 W: W3 J+ P
  130.   osPriorityAboveNormal2  = 32+2,       ///< Priority: above normal + 29 N/ h" A$ {" o, u* Y7 b
  131.   osPriorityAboveNormal3  = 32+3,       ///< Priority: above normal + 3% ^7 d, j7 I2 W/ V
  132.   osPriorityAboveNormal4  = 32+4,       ///< Priority: above normal + 4, P# Z9 E: Y: c; o. |; ?, }" B- I
  133.   osPriorityAboveNormal5  = 32+5,       ///< Priority: above normal + 5) S6 ^0 T) W6 J, ^$ r. ?; p8 v8 M
  134.   osPriorityAboveNormal6  = 32+6,       ///< Priority: above normal + 6
    $ l+ x9 X* j+ c
  135.   osPriorityAboveNormal7  = 32+7,       ///< Priority: above normal + 7
    , i6 m3 B3 m( ?4 u
  136.   osPriorityHigh          = 40,         ///< Priority: high$ [4 n) f4 [4 G- O' f
  137.   osPriorityHigh1         = 40+1,       ///< Priority: high + 1# N( m" e( G2 _, v& s
  138.   osPriorityHigh2         = 40+2,       ///< Priority: high + 2! x, _$ M6 a1 e  R2 E4 ]" \
  139.   osPriorityHigh3         = 40+3,       ///< Priority: high + 3- N9 c3 }7 x- R$ q
  140.   osPriorityHigh4         = 40+4,       ///< Priority: high + 4# }8 x8 }' J4 R% W% L% X5 E
  141.   osPriorityHigh5         = 40+5,       ///< Priority: high + 5
    0 v1 j: ?5 r2 v9 j& z: e
  142.   osPriorityHigh6         = 40+6,       ///< Priority: high + 6) y  s9 o1 u3 @8 w& R
  143.   osPriorityHigh7         = 40+7,       ///< Priority: high + 74 h2 v5 I$ n2 x8 E
  144.   osPriorityRealtime      = 48,         ///< Priority: realtime8 }) m6 {" @/ ]* f
  145.   osPriorityRealtime1     = 48+1,       ///< Priority: realtime + 1
    4 H" L( v, o; t$ v4 T1 a
  146.   osPriorityRealtime2     = 48+2,       ///< Priority: realtime + 2
    . [; H! W: F5 I' z: A3 b7 k
  147.   osPriorityRealtime3     = 48+3,       ///< Priority: realtime + 3
    % C1 t2 r% ]7 W! O- \4 C3 G
  148.   osPriorityRealtime4     = 48+4,       ///< Priority: realtime + 47 u) S$ W* C+ m0 J8 D7 w1 h$ H
  149.   osPriorityRealtime5     = 48+5,       ///< Priority: realtime + 55 e: P. j% N! s0 f$ n! x
  150.   osPriorityRealtime6     = 48+6,       ///< Priority: realtime + 6
    ( ?! ~3 Q5 ~( b) ^
  151.   osPriorityRealtime7     = 48+7,       ///< Priority: realtime + 7
    ' }3 {1 J5 g  I
  152.   osPriorityISR           = 56,         ///< Reserved for ISR deferred thread.
    3 R/ b# A1 d8 c  O! O- g
  153.   osPriorityError         = -1,         ///< System cannot determine priority or illegal priority.' \. K4 I/ w0 l0 w& D6 `
  154.   osPriorityReserved      = 0x7FFFFFFF  ///< Prevents enum down-size compiler optimization.
    $ J* N" \7 {* A' K
  155. } osPriority_t;
    1 z0 N: b  L$ a" \5 z+ p; V/ u7 q$ e
  156. : N, X& ?/ M& k% y) ^$ W9 O
  157. /// Entry point of a thread.
    2 u+ l2 E4 Y( I  W' U  s; q
  158. typedef void (*osThreadFunc_t) (void *argument);
    * ^4 X& U! J0 ]$ ?7 A
  159.   d) r* |% p; Q8 Z" j
  160. /// Timer callback function.3 W# {, n0 M* N7 L: w
  161. typedef void (*osTimerFunc_t) (void *argument);
    ! S  c: q' }  b
  162. 6 r# c7 u# ^( ^. y1 `4 d
  163. /// Timer type.& Z1 C3 o( L8 P& ~
  164. typedef enum {
    2 g! I* D# [- j5 U1 O
  165.   osTimerOnce               = 0,          ///< One-shot timer.
    2 |" N6 W: `( n7 a
  166.   osTimerPeriodic           = 1           ///< Repeating timer.) b$ L; O+ v3 |% I0 w2 X$ S- X
  167. } osTimerType_t;
    8 W% C8 n5 i* Z- `+ a% ]) v0 ~

  168. " S6 D/ B' M# e) Z" W$ \; E
  169. // Timeout value.
    + m1 R) v& d; f2 Z3 w
  170. #define osWaitForever         0xFFFFFFFFU ///< Wait forever timeout value.
    8 n) k$ w; h, E  H! ^

  171. ) B0 x' e* _4 F- N( C! u
  172. // Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).1 C5 Z- s- [8 ^0 A( J, k
  173. #define osFlagsWaitAny        0x00000000U ///< Wait for any flag (default).* W7 a6 I0 h; G* C2 r: N
  174. #define osFlagsWaitAll        0x00000001U ///< Wait for all flags.
    & d/ V0 Z  L* j: s" r% ^" d6 B9 n9 h
  175. #define osFlagsNoClear        0x00000002U ///< Do not clear flags which have been specified to wait for.% C( `6 P: c7 @. x: b# W* F% U
  176. 6 r, m& @/ ^" ?
  177. // Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx).
    + w& }! a9 E/ g: v" @" g- q
  178. #define osFlagsError          0x80000000U ///< Error indicator.
    ' d0 J2 v: f3 r7 e
  179. #define osFlagsErrorUnknown   0xFFFFFFFFU ///< osError (-1).
      y9 O8 I: L, @- v
  180. #define osFlagsErrorTimeout   0xFFFFFFFEU ///< osErrorTimeout (-2).
    0 J$ L+ b+ Y% u, _7 O8 c/ m
  181. #define osFlagsErrorResource  0xFFFFFFFDU ///< osErrorResource (-3).
    2 n4 |& D) i! J% {6 f
  182. #define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4).
    - Z0 g  x8 L, {; B" _& _- U
  183. #define osFlagsErrorISR       0xFFFFFFFAU ///< osErrorISR (-6).
    " Z6 V( i2 I9 |4 d8 S

  184. " p' P; b; Z- z5 h0 {* L+ @
  185. // Thread attributes (attr_bits in \ref osThreadAttr_t)." k, E/ G' i, }$ T5 s8 V+ S
  186. #define osThreadDetached      0x00000000U ///< Thread created in detached mode (default): J2 f0 a" B' i/ s) C( G
  187. #define osThreadJoinable      0x00000001U ///< Thread created in joinable mode
    - d* Z% H) @% v# d' m" [& V% x3 `7 k
  188. $ z6 t/ X% V4 E, D, n) l0 X
  189. // Mutex attributes (attr_bits in \ref osMutexAttr_t).  P) I2 V1 d; `( X# h, m. H$ p/ v" C, c' I
  190. #define osMutexRecursive      0x00000001U ///< Recursive mutex.
    ) V7 n" q! `8 r! P
  191. #define osMutexPrioInherit    0x00000002U ///< Priority inherit protocol.
    + |" c- `* y; s6 B
  192. #define osMutexRobust         0x00000008U ///< Robust mutex.# f0 l' }# d. D/ a+ O
  193. ' O  _- r7 d4 K6 B
  194. /// Status code values returned by CMSIS-RTOS functions.3 m, T* p8 w0 ^$ }. Q
  195. typedef enum {- X- J, L+ o% {! t
  196.   osOK                      =  0,         ///< Operation completed successfully.* O' r& k& c1 M6 r4 r
  197.   osError                   = -1,         ///< Unspecified RTOS error: run-time error but no other error message fits.8 F5 f. z, e. E7 m2 D8 T
  198.   osErrorTimeout            = -2,         ///< Operation not completed within the timeout period.
    0 g, b$ c, Q# n, g" c
  199.   osErrorResource           = -3,         ///< Resource not available.. f9 `8 W7 N, i2 u7 P$ O$ S9 b4 ~
  200.   osErrorParameter          = -4,         ///< Parameter error.! r% n! D- a# C- F1 F; W& z. Q% D
  201.   osErrorNoMemory           = -5,         ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.8 ?# L0 F6 ?9 @& U% E* ?
  202.   osErrorISR                = -6,         ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
    6 |' u$ u' d2 R2 _8 x0 p7 c
  203.   osStatusReserved          = 0x7FFFFFFF  ///< Prevents enum down-size compiler optimization.
    ; s) c- P8 C1 ^: Y8 ?% G( a4 N) E! I
  204. } osStatus_t;& ]5 p- l$ n, k( o/ \

  205. 5 T$ z- `5 B5 j! B: K

  206. & O2 R' n% l* n+ p. R' \
  207. /// \details Thread ID identifies the thread.( B9 r6 B3 Y, N  u8 ?* T/ n
  208. typedef void *osThreadId_t;. r# U4 _, v0 S$ p, k* u
  209. + u! B! I) h5 k3 g# Y- u7 L
  210. /// \details Timer ID identifies the timer.2 `7 n+ X. b2 z4 v$ G3 I
  211. typedef void *osTimerId_t;
    % A( J& T* A! y# o

  212. % p# a0 w' U$ d4 j; u
  213. /// \details Event Flags ID identifies the event flags.
    & T6 n- D4 G& M$ [. p
  214. typedef void *osEventFlagsId_t;9 }& B7 L9 m5 T, D: c
  215. + L( P) J  x! U8 T* T
  216. /// \details Mutex ID identifies the mutex.' F, X; c7 h$ @6 t
  217. typedef void *osMutexId_t;
    ' _- Y: V0 m! {1 p. ?% p0 K5 e, t

  218. - ^' z3 Q  C" `
  219. /// \details Semaphore ID identifies the semaphore.+ ?4 R' M2 a, q( _+ C1 M& y, [
  220. typedef void *osSemaphoreId_t;
      o& E3 W- a1 v7 R" c
  221. 3 ^! W% Q+ k9 H8 e
  222. /// \details Memory Pool ID identifies the memory pool.
    ' B! T+ ~+ x, ]0 k: F+ z# `0 j
  223. typedef void *osMemoryPoolId_t;! O: ]3 Q0 p$ g3 M

  224. 8 e7 R: d& g: F7 J
  225. /// \details Message Queue ID identifies the message queue.3 g& S' d, E+ J4 G
  226. typedef void *osMessageQueueId_t;0 q7 R0 ]" ~9 s
  227. " e/ W: i/ a1 J6 s: [7 Z

  228. / A% F  H4 j0 G2 A6 W
  229. #ifndef TZ_MODULEID_T; l5 ?7 a8 \8 n* o4 d* ?' E
  230. #define TZ_MODULEID_T! \, S5 P0 k4 m. [& W$ x0 `) |
  231. /// \details Data type that identifies secure software modules called by a process.
    0 v, ?9 K1 p! q6 t
  232. typedef uint32_t TZ_ModuleId_t;" ~6 t' C& g- }! V% U1 U3 V
  233. #endif6 ^  D. n: @- E/ ?
  234. 8 ]; [7 V, B! J9 L$ l
  235. 3 }. I0 l8 B' z
  236. /// Attributes structure for thread.
    4 P& j4 c! M9 |. C* g* Z
  237. typedef struct {
    3 y7 e* |! _& {& o! H
  238.   const char                   *name;   ///< name of the thread8 s: p7 `$ M. w: ?* k6 R8 I; T. N2 b
  239.   uint32_t                 attr_bits;   ///< attribute bits) D& `- l# Q+ P9 `% N
  240.   void                      *cb_mem;    ///< memory for control block" i! T0 _- B3 Q$ s
  241.   uint32_t                   cb_size;   ///< size of provided memory for control block
    0 y3 ~4 `  Z! J. h, t& E5 Y
  242.   void                   *stack_mem;    ///< memory for stack
    6 g, F8 Q# x$ [( }' o- x" o2 B8 o: _
  243.   uint32_t                stack_size;   ///< size of stack; w* B, I8 C2 E# b
  244.   osPriority_t              priority;   ///< initial thread priority (default: osPriorityNormal)
    " Q7 N* X: x$ o0 m0 J- c' M! t
  245.   TZ_ModuleId_t            tz_module;   ///< TrustZone module identifier
    ! I4 _1 g/ \6 j5 Y  A- S) a. q
  246.   uint32_t                  reserved;   ///< reserved (must be 0)
      \+ ^- B/ p1 \
  247. } osThreadAttr_t;
    7 Q  v4 L: B4 \: e8 q- T4 Y
  248. ! X+ [: \3 V' L. P5 I- [! k
  249. /// Attributes structure for timer.
    ) I4 A% U; P$ U% R1 O3 ^, a
  250. typedef struct {* d, r4 b% g9 p' P5 a0 @3 k: X
  251.   const char                   *name;   ///< name of the timer
    ) {2 A- u" D: X) G" X
  252.   uint32_t                 attr_bits;   ///< attribute bits
    3 f8 e4 e8 g; b9 Q/ p" S% S
  253.   void                      *cb_mem;    ///< memory for control block2 a! ^% ~7 ]; P9 \5 C$ Z' A
  254.   uint32_t                   cb_size;   ///< size of provided memory for control block
      X% I+ v$ e% S( V7 k7 j0 G
  255. } osTimerAttr_t;
    ! L% I9 }. T8 n7 c
  256. & |6 Z* ]' ^, I# H% R5 Q
  257. /// Attributes structure for event flags.
    * x$ \- L8 y+ s7 G
  258. typedef struct {
    9 [  U# p7 W7 ?6 E
  259.   const char                   *name;   ///< name of the event flags5 |3 P, d4 A3 t' {1 ~9 U9 Z% I
  260.   uint32_t                 attr_bits;   ///< attribute bits
    , \6 c. h% N8 `: N0 A) r& H; W
  261.   void                      *cb_mem;    ///< memory for control block
    0 r5 u0 _2 o( B8 x" T$ q1 c
  262.   uint32_t                   cb_size;   ///< size of provided memory for control block
    " A. \4 `' P/ l1 F
  263. } osEventFlagsAttr_t;$ u/ ?3 C' [/ q. }$ ^3 V

  264. . M! [6 H' s$ n4 E
  265. /// Attributes structure for mutex.
    , B5 m  \8 V( o( Y: _
  266. typedef struct {
    0 j( X! f* |3 k9 J: E: Z1 O
  267.   const char                   *name;   ///< name of the mutex
    " Y# D" \4 Y, n/ v. z! B) k7 I# g
  268.   uint32_t                 attr_bits;   ///< attribute bits
    ! i" [; j4 H; J1 u& p5 f6 \
  269.   void                      *cb_mem;    ///< memory for control block4 S# u. o' j7 }
  270.   uint32_t                   cb_size;   ///< size of provided memory for control block
    + @& Y% ~* S* [5 s- w6 q& d6 O
  271. } osMutexAttr_t;
    4 a( Y6 }( T8 p) a

  272. 4 O- r6 X: h6 G) h' x
  273. /// Attributes structure for semaphore.
    2 p; Z6 |, Q$ i
  274. typedef struct {, s. |# C/ g5 |  W/ p
  275.   const char                   *name;   ///< name of the semaphore
    0 [6 I" x- u5 m/ O
  276.   uint32_t                 attr_bits;   ///< attribute bits) L9 z5 l1 C0 [6 D8 H3 l+ L
  277.   void                      *cb_mem;    ///< memory for control block
    ) u5 P2 r3 `8 D
  278.   uint32_t                   cb_size;   ///< size of provided memory for control block
    + A& ]& E( l! V
  279. } osSemaphoreAttr_t;4 Z) Z  K5 E* X$ v* r

  280. " v3 O/ E6 Q( Q3 E' R, V; E
  281. /// Attributes structure for memory pool.
    4 u6 v" g5 |- u3 |
  282. typedef struct {" E' A1 ~0 z" A# ]6 S$ W" ]
  283.   const char                   *name;   ///< name of the memory pool9 h* G# M! G" Z1 a* s* r
  284.   uint32_t                 attr_bits;   ///< attribute bits3 b4 t" y7 A# t; y
  285.   void                      *cb_mem;    ///< memory for control block
    9 o5 v& p4 L$ n" J
  286.   uint32_t                   cb_size;   ///< size of provided memory for control block
    ! \1 g- {. S- v2 M' w# x* o) M
  287.   void                      *mp_mem;    ///< memory for data storage; w4 S2 P, y. ~: }
  288.   uint32_t                   mp_size;   ///< size of provided memory for data storage & u1 Q' a. T" \) R) I  W4 x6 n+ A0 r" a
  289. } osMemoryPoolAttr_t;3 o3 O4 _, y& A* [6 _9 U
  290. ( _8 d6 k* a1 o4 a! K
  291. /// Attributes structure for message queue.
    . J) g6 v# p7 x9 k$ P% R3 O
  292. typedef struct {
    & ?# e% m3 A: ^; I0 r/ L5 I  [% T  b. `+ i
  293.   const char                   *name;   ///< name of the message queue
    # D8 p+ \& K& }
  294.   uint32_t                 attr_bits;   ///< attribute bits. U8 Q8 m- d0 c/ H5 z
  295.   void                      *cb_mem;    ///< memory for control block
    , p0 |$ r7 g: d9 S1 \
  296.   uint32_t                   cb_size;   ///< size of provided memory for control block, t1 C0 F& P7 B% x% V
  297.   void                      *mq_mem;    ///< memory for data storage0 I1 k; Q: O" {: d3 q
  298.   uint32_t                   mq_size;   ///< size of provided memory for data storage 6 p, R  p# M' k& e% O/ S. }
  299. } osMessageQueueAttr_t;
    % [, B* v2 [, U; y

  300. ; I  a- y5 S( X2 c
  301. * V8 `: M6 [# w8 x' }8 X
  302. //  ==== Kernel Management Functions ====% v+ H& w& Q  N! z! X- w5 D6 W
  303. / k  @. ]& W: O( v5 i
  304. /// Initialize the RTOS Kernel.
    . f' N  h) ?$ x) N4 V
  305. /// \return status code that indicates the execution status of the function.
    5 g' t6 q2 S+ f5 @
  306. osStatus_t osKernelInitialize (void);+ ?7 j) i) S6 [( e9 l

  307. ) I; z) B' `0 Q( @5 w' t
  308. ///  Get RTOS Kernel Information.' O- Z3 v3 o  z- e# q6 q1 Z
  309. /// \param[out]    version       pointer to buffer for retrieving version information.. T3 D* W) j* u7 h) k
  310. /// \param[out]    id_buf        pointer to buffer for retrieving kernel identification string.
    , N( J9 A, x& e8 ?  q) J. z
  311. /// \param[in]     id_size       size of buffer for kernel identification string.
    0 k( u$ D9 F4 r
  312. /// \return status code that indicates the execution status of the function.  ~6 E  f9 @9 k0 U" ^0 U3 L- u
  313. osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
    8 z# v) t  B1 S7 N# z# g
  314. 6 q; X7 b3 {: K% D/ V
  315. /// Get the current RTOS Kernel state.7 c! p- m, B+ v6 }
  316. /// \return current RTOS Kernel state.
    8 H8 E6 `* `9 Q( }- N
  317. osKernelState_t osKernelGetState (void);# F, A# o( ^. \* w+ k, p! \

  318. 3 j, x# ^, d2 x: L/ A2 t7 m
  319. /// Start the RTOS Kernel scheduler.2 j4 P, C+ M2 v, W3 _# \! L8 B. x+ n
  320. /// \return status code that indicates the execution status of the function.* f6 C8 s$ x2 h9 [% j5 _* S
  321. osStatus_t osKernelStart (void);
    7 `, A: q! ~2 Z
  322. 4 Z: u9 h! F! s
  323. /// Lock the RTOS Kernel scheduler.: ?5 q1 N8 l9 ~4 W. k
  324. /// \return previous lock state (1 - locked, 0 - not locked, error code if negative).5 |7 g: I( R) q! h! O9 E2 {
  325. int32_t osKernelLock (void);
    $ J) f1 n# R3 A  Q5 i

  326. ; B4 Z. y/ Q8 h3 ?& h' A" }
  327. /// Unlock the RTOS Kernel scheduler.9 c) y. Z7 _, j  {6 Z" [
  328. /// \return previous lock state (1 - locked, 0 - not locked, error code if negative).4 l# I# K7 D3 Z- w5 F' P% ?# i( o& u& |7 G
  329. int32_t osKernelUnlock (void);
    % x! q6 C" \/ i+ X2 G
  330. " L3 S; x0 p7 Q6 S: L
  331. /// Restore the RTOS Kernel scheduler lock state.
    + h! t" N' r9 w' A% k& }' i
  332. /// \param[in]     lock          lock state obtained by \ref osKernelLock or \ref osKernelUnlock.
    ( `6 Z! T) [6 X" {4 I  E/ T
  333. /// \return new lock state (1 - locked, 0 - not locked, error code if negative).; b; O. Y2 Q) c5 l% B& [
  334. int32_t osKernelRestoreLock (int32_t lock);
    7 E; O+ G2 a& a2 H
  335. 6 v; ^4 s- u& d6 Z
  336. /// Suspend the RTOS Kernel scheduler.6 b7 |  _5 |! T* d+ ]. ~/ j
  337. /// \return time in ticks, for how long the system can sleep or power-down.7 X! [" {+ ~6 {7 a/ f! _; s
  338. uint32_t osKernelSuspend (void);8 ?& l  R# _5 `) _
  339. ! r* M' q7 n# k0 u
  340. /// Resume the RTOS Kernel scheduler.3 Z8 B1 \; ^8 H+ J7 ?
  341. /// \param[in]     sleep_ticks   time in ticks for how long the system was in sleep or power-down mode.& ]& O$ Y! o- j) ]
  342. void osKernelResume (uint32_t sleep_ticks);
    * z2 x$ y( G0 G& a

  343. ) {( o* E7 v( m+ ]. z4 s7 u$ n5 ]
  344. /// Get the RTOS kernel tick count.
      I; y# p' f& h
  345. /// \return RTOS kernel current tick count.
    $ d5 u2 d. w  Q/ A9 D' r
  346. uint32_t osKernelGetTickCount (void);- o1 R( x9 U! K

  347. 4 G; i& m) ]2 B7 X  ?1 R( |
  348. /// Get the RTOS kernel tick frequency.
    ! T+ ~7 P* b1 g! v
  349. /// \return frequency of the kernel tick in hertz, i.e. kernel ticks per second.
    6 Z6 y& E8 t2 q9 c
  350. uint32_t osKernelGetTickFreq (void);" `) A* s0 ]& {" f' W/ O) y
  351. 2 x' N* A* {+ D! T& I  r6 s
  352. /// Get the RTOS kernel system timer count.
    & ^/ k# F; {0 v8 ]
  353. /// \return RTOS kernel current system timer count as 32-bit value./ V7 n, Q; H0 b7 {9 n3 j7 J
  354. uint32_t osKernelGetSysTimerCount (void);; @4 s2 d# K3 [7 x0 G0 j* {4 W
  355. 8 j9 @. c8 c' Q: f  V  Q" A1 g
  356. /// Get the RTOS kernel system timer frequency.  w5 E% q8 R8 l3 s& a
  357. /// \return frequency of the system timer in hertz, i.e. timer ticks per second.
    , b+ U- S0 d/ }2 Y
  358. uint32_t osKernelGetSysTimerFreq (void);) a2 s$ b; y2 g- V/ n( t1 c2 V7 l

  359. & R7 }( D2 F7 {& w# Q5 N
  360. 0 Y! J9 h7 k! Q4 O
  361. //  ==== Thread Management Functions ====
    1 A% F- |6 t) l% L5 o7 ~

  362. 4 d1 _0 @) H' R6 H: z+ I
  363. /// Create a thread and add it to Active Threads.
    - i) [# [- Y5 \! {* v% W+ i
  364. /// \param[in]     func          thread function.( L, p! M6 m$ R3 i, x
  365. /// \param[in]     argument      pointer that is passed to the thread function as start argument.
    % G3 I4 V8 V. u( }! V& w% B
  366. /// \param[in]     attr          thread attributes; NULL: default values./ I# v6 ^6 Q* a7 t- v2 g# D# `& o
  367. /// \return thread ID for reference by other functions or NULL in case of error./ k% _! ~# e( ~. q# F
  368. osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr);' e/ {0 q3 O7 p  X4 y( }6 I! R

  369. ( }( F) v# U7 x
  370. /// Get name of a thread.. F6 B9 {- l3 [+ F4 ]9 l
  371. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.1 W3 k0 F. W3 r
  372. /// \return name as NULL terminated string.: p8 n8 q6 }2 }. ^
  373. const char *osThreadGetName (osThreadId_t thread_id);
    ! d1 Z- ?2 O% L4 {% H( A0 c% Q( H
  374. ( F# V& R% \$ b; O& S* |2 N
  375. /// Return the thread ID of the current running thread.% Z  T5 R  ^$ [* _& \( a
  376. /// \return thread ID for reference by other functions or NULL in case of error.
    + ~% g5 `/ p  F
  377. osThreadId_t osThreadGetId (void);
    6 K& a3 W# _# ?& o: l8 K+ z
  378. 3 G- ]& Z) ?6 F% o+ ^0 f
  379. /// Get current thread state of a thread.% X8 E& {- R9 h2 Z" X8 m( ]
  380. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    7 b7 s) z2 d2 z% F  C6 s. `
  381. /// \return current thread state of the specified thread.6 X, [5 B: H% K
  382. osThreadState_t osThreadGetState (osThreadId_t thread_id);8 }: E: E( O- h# E# a

  383. & F1 Y( Q  s" W' N$ g; C9 l
  384. /// Get stack size of a thread.
      O: g8 X, t! W3 a  j, P/ I+ `6 R
  385. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.4 D; A) ]# E! Z9 {/ @6 y! D& ]
  386. /// \return stack size in bytes.
    , r: A% D3 |* W" F
  387. uint32_t osThreadGetStackSize (osThreadId_t thread_id);# ~$ ?- U0 U  ?  q) o

  388. # q% A" c6 h! T$ W0 A
  389. /// Get available stack space of a thread based on stack watermark recording during execution.
    " m  Q3 [% l7 ^8 H, |; `( y
  390. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.7 z+ V8 ?3 p( o
  391. /// \return remaining stack space in bytes.
    ( m- X, F. e5 z
  392. uint32_t osThreadGetStackSpace (osThreadId_t thread_id);
    % q. [: p! q& J. n" \

  393. : T* O$ \  e+ ^- G) [  K; }
  394. /// Change priority of a thread.
    8 [: P* L  e) c/ q0 Q' b9 i. _
  395. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.) n( X( x4 z! j/ _
  396. /// \param[in]     priority      new priority value for the thread function.# y" i3 P" d4 W$ C# ]. `3 u
  397. /// \return status code that indicates the execution status of the function.
    ; A/ B9 r9 x' Y0 @$ o: c# F
  398. osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);# `7 A( \7 l) a! K, Y% r
  399. * |2 E) h( J+ t
  400. /// Get current priority of a thread.0 t1 D- Z: ~$ `; d' v3 A
  401. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId./ N: D: M+ R4 s( G8 E6 Y
  402. /// \return current priority value of the specified thread.
    ) @; z# F/ d8 z; C3 I" e2 R9 x: ?
  403. osPriority_t osThreadGetPriority (osThreadId_t thread_id);
    ' K2 C+ U" G3 W! F4 s* Z( T

  404. 4 K/ m3 M! a& \$ q
  405. /// Pass control to next thread that is in state \b READY.% u8 A: j: E& |3 o5 [" \! f9 q
  406. /// \return status code that indicates the execution status of the function.4 I3 B/ W, `- F, F& J' p
  407. osStatus_t osThreadYield (void);
    6 @9 U2 k, K3 Q: t/ R/ l
  408. 0 l5 Q# S' O( ^
  409. /// Suspend execution of a thread.: T& [0 y+ J* E- c6 a
  410. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.# P) L* K, m+ J; q0 ?0 |+ K
  411. /// \return status code that indicates the execution status of the function.
    ' I5 U1 I" ?* a, [( D
  412. osStatus_t osThreadSuspend (osThreadId_t thread_id);
    3 j8 h2 M3 X  M
  413. ( V! b- l. @5 Y! J- j
  414. /// Resume execution of a thread.# k$ g5 x8 d! D8 g
  415. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    / r3 @+ E7 k8 `; D1 o2 A. U. Q
  416. /// \return status code that indicates the execution status of the function./ J4 ~! U6 }! ^
  417. osStatus_t osThreadResume (osThreadId_t thread_id);
    / d$ o3 g4 a/ n  v

  418. " z5 Z& t# ]* t  m+ J/ I( P
  419. /// Detach a thread (thread storage can be reclaimed when thread terminates).6 A. C# t" M6 n' g, T1 `
  420. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.4 B/ ~  Z! I) G5 b$ D: ^
  421. /// \return status code that indicates the execution status of the function.
    ; |2 E" k5 l* [8 [% x
  422. osStatus_t osThreadDetach (osThreadId_t thread_id);
    1 d. Z' {6 V1 F, w( k1 }: b
  423. $ e6 l$ Y# Z6 `; ]; Q2 R+ L
  424. /// Wait for specified thread to terminate.
    0 n6 i: q0 g; ^  `( f  [
  425. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.3 o! O' y' y. ?. t
  426. /// \return status code that indicates the execution status of the function.
    0 {/ }; b% ?. f) v6 {5 ^6 A
  427. osStatus_t osThreadJoin (osThreadId_t thread_id);
    3 P6 C0 v4 O$ s! t4 w

  428. 8 L. j2 Q$ y8 N8 C, }9 ?2 S
  429. /// Terminate execution of current running thread.
    ! x% V+ m. F. i8 @% K; O  g" \
  430. __NO_RETURN void osThreadExit (void);, Z! C1 ]' x/ I2 e( p

  431. ( n! b! z" v0 }2 J, C0 S% ]
  432. /// Terminate execution of a thread.) k( `# F3 `" \7 q. |  q. r4 r
  433. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
    9 i; M6 o2 n: d* n+ T8 ^
  434. /// \return status code that indicates the execution status of the function.
    4 {6 o9 D0 f6 J3 |/ m; S1 E7 T2 G
  435. osStatus_t osThreadTerminate (osThreadId_t thread_id);
      Y% C* ^5 b2 C% q1 o: _5 x6 n9 Y. ^- |

  436. 0 k6 X) Z: J* ]6 [
  437. /// Get number of active threads.
    3 z8 D3 P$ l' Z- ?5 T0 x% {3 H1 K
  438. /// \return number of active threads.
    / n7 g5 y9 U, l. ^
  439. uint32_t osThreadGetCount (void);
    / C- B) l* C4 J. q

  440. $ j' ?6 E" C+ U  M0 l  G
  441. /// Enumerate active threads., P2 ]) Z, G4 @" S5 o+ u/ h+ y0 @4 K
  442. /// \param[out]    thread_array  pointer to array for retrieving thread IDs.# n% A6 e1 |3 `
  443. /// \param[in]     array_items   maximum number of items in array for retrieving thread IDs.. Q+ x) V% Q; j. u
  444. /// \return number of enumerated threads.2 y$ c/ T+ E' ]1 e& x
  445. uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);' n/ _2 m* B" m) V

  446. 5 P2 x/ _) N6 W  Z2 L

  447. " y& g1 {+ s  X% ]0 p7 B
  448. //  ==== Thread Flags Functions ====
    6 W7 P7 Q; |- X! a1 ?1 K7 n/ u! \6 |
  449. ) N$ h/ e$ {% C5 K) a, G( I
  450. /// Set the specified Thread Flags of a thread.  I5 [# X. u' m/ _& b# Y( {# y( b, r- y
  451. /// \param[in]     thread_id     thread ID obtained by \ref osThreadNew or \ref osThreadGetId.  K% t; b; C) R0 s
  452. /// \param[in]     flags         specifies the flags of the thread that shall be set.9 b9 q  v2 i7 S7 a
  453. /// \return thread flags after setting or error code if highest bit set.6 m, D, N/ D9 ]1 v* c8 e
  454. uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags);; J; `: U- g0 P! F& J+ w
  455. 8 G0 r* [: j% a4 j; B
  456. /// Clear the specified Thread Flags of current running thread.
    % I: K) U) v2 u  l/ D) u6 R
  457. /// \param[in]     flags         specifies the flags of the thread that shall be cleared.$ p0 z7 e0 M/ J' [- Z9 I/ e. d: K! L1 U
  458. /// \return thread flags before clearing or error code if highest bit set.- S' L. K3 I, X! M. Q' w7 [
  459. uint32_t osThreadFlagsClear (uint32_t flags);
    % b+ Y4 i3 b' ?# R* d  i$ K
  460. / O9 x; F% K) H* `; C* f* f
  461. /// Get the current Thread Flags of current running thread.
    , I* n. `2 D6 ^+ f! u% o9 m; x
  462. /// \return current thread flags.
    , i+ i. h  ^( N7 L+ X3 \: V
  463. uint32_t osThreadFlagsGet (void);. g! ~+ w; K" M8 L
  464.   M( E4 j! ~0 i! E8 ^
  465. /// Wait for one or more Thread Flags of the current running thread to become signaled.; j' ]* A9 B, f6 Q+ P1 `2 ]
  466. /// \param[in]     flags         specifies the flags to wait for.. d) e2 M- T7 Q. [5 M$ p/ h4 M' Z
  467. /// \param[in]     options       specifies flags options (osFlagsXxxx).0 @7 G7 \4 B( r* A: s  e
  468. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
    * N) K, D5 |1 [$ X' P0 R# S& ~2 z+ l
  469. /// \return thread flags before clearing or error code if highest bit set.- w' D1 G$ o" E/ t
  470. uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout);
    ! N/ e1 D& x4 R4 ]) ~6 R; I

  471. ) n* A3 s9 Y: w/ W6 j/ B
  472.   z) j* P/ N0 w% F. i: t- Q& r
  473. //  ==== Generic Wait Functions ====. H9 |- C6 ~1 s, V( Q; A3 _* t2 P

  474. ) V/ k0 i" N8 @* G! S, {
  475. /// Wait for Timeout (Time Delay).
    . ~1 a; c: m* W0 X3 q) G
  476. /// \param[in]     ticks         \ref CMSIS_RTOS_TimeOutValue "time ticks" value
    8 G1 V' ?/ b# X( H; J/ `3 a1 v2 U
  477. /// \return status code that indicates the execution status of the function.
    4 ~+ u' C) H2 O) ^/ g4 u. P7 t5 m: t
  478. osStatus_t osDelay (uint32_t ticks);
    : \7 D) y7 S& h" V( Q; U
  479. ; p2 C/ j. S" ^6 K
  480. /// Wait until specified time.
    * B2 N. ?: e& b
  481. /// \param[in]     ticks         absolute time in ticks1 _! {3 }- ~/ T5 ]' {
  482. /// \return status code that indicates the execution status of the function.' o0 P( Q* h) L% l5 F2 S! H
  483. osStatus_t osDelayUntil (uint32_t ticks);
    ' H$ @4 K0 A! m

  484. 5 h" v( ]9 M, S
  485. 0 q+ c9 X, \! e- Z7 v! k
  486. //  ==== Timer Management Functions ====
    / h* G% r% P4 ^3 |9 |/ n" [+ i
  487. ; C( o6 G( A( ~' u; [" q& V+ F
  488. /// Create and Initialize a timer.2 R0 }9 n* s' w5 ?1 j$ n* e  H
  489. /// \param[in]     func          function pointer to callback function.& e& N; R6 u+ Z* }
  490. /// \param[in]     type          \ref osTimerOnce for one-shot or \ref osTimerPeriodic for periodic behavior.
    2 X2 O' b  h8 F# i& ]
  491. /// \param[in]     argument      argument to the timer callback function.
    ' Q6 C& r6 e: @2 g  a
  492. /// \param[in]     attr          timer attributes; NULL: default values.' F# t8 C3 n/ J9 B( h1 Y% f
  493. /// \return timer ID for reference by other functions or NULL in case of error.
    6 h6 @: t  M* M6 u; p
  494. osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);9 W3 m) O8 y4 d7 s1 \; i

  495. 8 I6 R/ @: i( s! {4 O' o
  496. /// Get name of a timer." c% c( U3 e" F2 }
  497. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
    . g3 K  Q! L5 G, k! O
  498. /// \return name as NULL terminated string.1 r6 I. \% y% L1 P5 x' _: I. t
  499. const char *osTimerGetName (osTimerId_t timer_id);
    6 p8 N7 P& Z2 I% |$ Q1 h
  500. , u; S: z7 Q  ~3 u% Q
  501. /// Start or restart a timer.
    + T+ G4 j/ {% u2 [$ ^% s+ @
  502. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.; g6 ^# A4 @& P+ s3 ^4 ~7 ~, c! f
  503. /// \param[in]     ticks         \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer.& K) c4 R  S# F4 x  w4 T' u
  504. /// \return status code that indicates the execution status of the function.
    : F8 R: t' y2 L2 {2 Z. d' p, Y
  505. osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
    & s% y2 L; Q. i, J
  506. 0 B! i4 t  M' ~8 i/ v0 [3 O
  507. /// Stop a timer.
    7 ?% j; j0 M- m4 w' N
  508. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.5 s4 s- ^2 m7 a5 X1 i% l
  509. /// \return status code that indicates the execution status of the function.
    - j6 a3 s4 ^4 W- p9 P
  510. osStatus_t osTimerStop (osTimerId_t timer_id);
    6 g* a6 o' n3 I( L" T/ u# L$ c5 E3 Y

  511. : [/ L. a+ k: C5 `
  512. /// Check if a timer is running.
    $ F( ~' h$ x! N2 O& Z
  513. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.& q4 |$ z2 ]* K% Y, V
  514. /// \return 0 not running, 1 running.
    6 k. s7 l  ~& g9 u
  515. uint32_t osTimerIsRunning (osTimerId_t timer_id);
    ( Q; y: T! M9 I% g8 t' s3 }. h

  516. 6 M: V7 ^$ B) `. i" C1 k% A( J- C
  517. /// Delete a timer.. Y7 a! [6 C+ \' l( L; Y
  518. /// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
    + B6 e& G0 `  {6 j- H
  519. /// \return status code that indicates the execution status of the function.
    : I# Z* Z9 _9 x% x$ B% ~7 i! h5 Z
  520. osStatus_t osTimerDelete (osTimerId_t timer_id);1 B, q- w) x9 Z/ n* I3 l" ~

  521. , S& j+ A0 l5 b2 ^! j2 P  g, C

  522. . }6 |0 j  q8 l* Z/ A
  523. //  ==== Event Flags Management Functions ====
    3 e( O* z3 c: C

  524. * O7 u0 W1 z1 z  a8 m
  525. /// Create and Initialize an Event Flags object.9 v6 C& Y! u9 x
  526. /// \param[in]     attr          event flags attributes; NULL: default values.
    # ~0 [! y& p0 B1 ^: x" G6 `
  527. /// \return event flags ID for reference by other functions or NULL in case of error.
    / y$ [: g; l% |( I; B  R
  528. osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);5 C, a/ z0 [) T5 L2 z

  529. # I) S3 T% ^2 v, a  g; @6 {
  530. /// Get name of an Event Flags object.
    $ m7 u% n- e/ O) V
  531. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.2 n3 [  @% ~+ N5 i
  532. /// \return name as NULL terminated string.) k1 c9 o$ F# P/ P1 S9 ^9 B8 Q
  533. const char *osEventFlagsGetName (osEventFlagsId_t ef_id);
      B4 N/ M5 x, R% G6 M9 A7 b7 J; H) U
  534. 3 P0 U( `8 m8 {/ s( C
  535. /// Set the specified Event Flags.  D: ~/ C, F( n1 t
  536. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.
    1 ]) D0 Y, U: g
  537. /// \param[in]     flags         specifies the flags that shall be set.
    & |/ N9 P% N& p8 J
  538. /// \return event flags after setting or error code if highest bit set.6 R; ]" U/ Z% v6 S1 h
  539. uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags);5 _, g, @/ E6 x; q. L/ u6 k

  540. % w4 h2 b4 [! K: ~% O3 L' K! o& W: v* V+ p
  541. /// Clear the specified Event Flags.
    8 h& u+ h& U4 w2 [
  542. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.+ l' F5 _, ^' _% \) _. ]
  543. /// \param[in]     flags         specifies the flags that shall be cleared.
    ! _" J0 o1 b' t
  544. /// \return event flags before clearing or error code if highest bit set.
    1 ?6 o5 i% p( j7 M: B; a8 f
  545. uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags);
    , |- m# `5 V3 D5 P4 J! E# s2 @

  546. 5 ]* n% z) N; J
  547. /// Get the current Event Flags.% l! r1 T7 v( e
  548. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew., N  J; R+ q# W# Y% s/ a0 A
  549. /// \return current event flags.
    1 b$ Z4 `, ~' W* n7 W
  550. uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);$ |2 m- r, N8 b
  551. * Z9 M5 @8 ]5 P3 g5 F5 h5 {, u' P1 c- m
  552. /// Wait for one or more Event Flags to become signaled.% T+ d* [! F# V! Y
  553. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.
    " Z! s; n6 a! `- f$ Z: Y# e
  554. /// \param[in]     flags         specifies the flags to wait for.
    ( |! [3 P; ]4 g8 r
  555. /// \param[in]     options       specifies flags options (osFlagsXxxx)./ `# y! k2 s" W
  556. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.: l/ F( k4 L+ ~, S- o
  557. /// \return event flags before clearing or error code if highest bit set.; v' O( V$ v1 [: t) E" A3 N- ~
  558. uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout);
    - T- q2 d# d8 E! e
  559. # {& f- q  O6 D7 {
  560. /// Delete an Event Flags object.
    ( W: j. Y: p! Y1 C: k# m( U
  561. /// \param[in]     ef_id         event flags ID obtained by \ref osEventFlagsNew.: q. Z, k$ G6 _
  562. /// \return status code that indicates the execution status of the function.( Q0 e- S8 I5 y7 d; S3 W( Z* M
  563. osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
    1 Q' q! O: T& C- X
  564. % z1 u) o" Y( J% v
  565. . n" c- m; W$ ^. D7 I
  566. //  ==== Mutex Management Functions ====
    8 O$ n/ X% a) S+ u9 N- ]; m
  567. , ]& P  A0 D# A) F: P8 l" h
  568. /// Create and Initialize a Mutex object.0 N! U* @) h, R: ^& [& K
  569. /// \param[in]     attr          mutex attributes; NULL: default values.
    ' P; l: a" Q9 E/ U: g/ F
  570. /// \return mutex ID for reference by other functions or NULL in case of error.& n; h- {: F& d. r  f
  571. osMutexId_t osMutexNew (const osMutexAttr_t *attr);
    + J- G* N$ t$ `. S, m2 T
  572. 3 {4 F$ R6 H: n) g
  573. /// Get name of a Mutex object./ }4 w& ?  l8 C; v
  574. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.. O# y  D$ O$ k& Q! @8 N+ O$ i
  575. /// \return name as NULL terminated string.
    0 Z% W( N. x/ `$ N  k/ ]6 G2 s& ~& w
  576. const char *osMutexGetName (osMutexId_t mutex_id);
    ; S( e8 C$ [$ }  `" e+ X7 N

  577. , J! T( Q5 h% A! g
  578. /// Acquire a Mutex or timeout if it is locked.: i2 c  ]8 U* u3 B" V7 Q
  579. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.' U" X6 S1 C9 C' H7 o+ B
  580. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.. @. F5 c5 E0 O" g2 q) D+ Z
  581. /// \return status code that indicates the execution status of the function.
    ' A& v, t8 Q; d6 @9 a1 b. v
  582. osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);9 a5 s4 ~9 Q3 {, S8 I

  583. / D+ F, a  j. }, B) t. n
  584. /// Release a Mutex that was acquired by \ref osMutexAcquire.
    8 w0 g- I' N( S' T% {9 P- M
  585. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.
    5 t5 K5 z. c$ [
  586. /// \return status code that indicates the execution status of the function.9 n8 z1 Y9 A( i; G" h7 r: T
  587. osStatus_t osMutexRelease (osMutexId_t mutex_id);' h- G- E* H0 K1 l  J$ q! K% @

  588. - s$ @* L/ f- b
  589. /// Get Thread which owns a Mutex object.
    ) O- |& H; P7 F& ]1 Z
  590. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.
    9 }' ]" E8 `4 e' v% V
  591. /// \return thread ID of owner thread or NULL when mutex was not acquired.
    6 \- Z; F  k, @- v" W0 E9 i
  592. osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
    0 o! }7 C! F$ |- V6 h- R

  593. . C$ y; Q7 F. C$ E
  594. /// Delete a Mutex object.9 \" O. t$ f# {
  595. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexNew.% T. |- F# d( _1 z: V
  596. /// \return status code that indicates the execution status of the function.
      s+ ?2 ^" X* g3 F( F! j2 O0 Y3 A
  597. osStatus_t osMutexDelete (osMutexId_t mutex_id);
    : A- \. {( ~% O6 F$ `$ y) d

  598. 7 X) Y- Q: W. P8 g6 M* \7 n
  599. . z3 s, A' K' S! X) H+ V' D$ P+ h5 }
  600. //  ==== Semaphore Management Functions ====# Z9 E, b$ F% m! @

  601. # N* x3 ?3 h' I. [! P0 M1 |
  602. /// Create and Initialize a Semaphore object.
    ; ^! E) R* ]& |% F1 o* |
  603. /// \param[in]     max_count     maximum number of available tokens.) ^$ S3 |# P, Y2 k+ v  ^- T
  604. /// \param[in]     initial_count initial number of available tokens.
    * K) r$ I# K1 ?9 F* p
  605. /// \param[in]     attr          semaphore attributes; NULL: default values.
    - L% b: F( K# K! S
  606. /// \return semaphore ID for reference by other functions or NULL in case of error.  s) v6 F  w6 g$ Z1 K
  607. osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);& ]" {* f" j& {+ t1 S1 \2 c
  608. & z5 t3 |/ q) m7 b$ q0 ^
  609. /// Get name of a Semaphore object.- r6 b4 u& X+ E1 z7 ~* r) P
  610. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.
    " }! ], y# `) m. l) v
  611. /// \return name as NULL terminated string.
    ( t" S" T& T6 ^
  612. const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);# G. A) |. F8 Q
  613. $ ]1 R# _8 v' N, t* X
  614. /// Acquire a Semaphore token or timeout if no tokens are available.
    6 M$ {$ [+ o! h9 q7 H
  615. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.
    : M% {6 r+ [% g
  616. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
      w1 k5 A( C' _' [% x9 u
  617. /// \return status code that indicates the execution status of the function.
    " X0 J/ f5 h7 F. o
  618. osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout);
    . A) }* J8 |% Y+ B# i) ~# N, J; U
  619. ) r% m$ n+ q# I! h8 i( z% I. O( v5 U$ L
  620. /// Release a Semaphore token up to the initial maximum count.
    7 X5 ^* V9 ?7 V# J: o6 }
  621. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.
      l, q5 B; G  N0 e4 H) z
  622. /// \return status code that indicates the execution status of the function." j9 M+ o6 B6 g5 Y- [3 t# C5 H
  623. osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
    " \' ]# z! N; n1 K
  624. 1 h3 \1 J* U3 t! b! x9 [
  625. /// Get current Semaphore token count.# T3 P, Y) C0 t1 a1 Y
  626. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.) P$ J$ N3 S& f7 k
  627. /// \return number of tokens available.5 s3 Y! ^( K, n2 F+ W
  628. uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
    7 X) I3 t8 P2 t  p# F1 N  {9 G
  629. 0 d8 ?# x1 W% P% j. {9 J
  630. /// Delete a Semaphore object.
    ) \" d# U- I1 K1 V' O0 l
  631. /// \param[in]     semaphore_id  semaphore ID obtained by \ref osSemaphoreNew.
    . i" h; V' }. w+ V, D. B
  632. /// \return status code that indicates the execution status of the function.( ]$ w8 p5 {5 }2 h
  633. osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
    " w1 s( B; J& y) f# L

  634. , k* c5 t5 T# Y) P6 s

  635.   ^( ~9 s. h: t' {2 s5 X
  636. //  ==== Memory Pool Management Functions ====
    " H. {2 v3 G' O4 `8 A  E2 n/ b
  637. 3 N. e/ j9 p  z4 N
  638. /// Create and Initialize a Memory Pool object.2 H$ B0 u! k( s
  639. /// \param[in]     block_count   maximum number of memory blocks in memory pool.( @4 G4 [" T! @) D" ~
  640. /// \param[in]     block_size    memory block size in bytes.
    * D) W& ^0 h) R6 A
  641. /// \param[in]     attr          memory pool attributes; NULL: default values., Q4 ^/ x- F$ {: L, [8 z6 ^6 p
  642. /// \return memory pool ID for reference by other functions or NULL in case of error.
    / G& i1 A- z* `' D
  643. osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
    ; s. W& z% T" o! O0 M

  644. 0 F) W/ ^4 B( t8 `  x; S, [
  645. /// Get name of a Memory Pool object., u4 G, H/ S. Y1 `4 U0 N- ?" }
  646. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.
    6 ?" Q  @  A5 s
  647. /// \return name as NULL terminated string.) c* I: f" z( r6 {$ @: T5 {
  648. const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id);
    : r7 A$ e* u+ l# T3 P6 H. ^6 w

  649. ! U( O. @/ q4 d) ^0 s
  650. /// Allocate a memory block from a Memory Pool.% P8 C) K/ {% y8 r  l7 J9 _; l3 X
  651. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.0 g1 I$ k# d7 ?9 J; ]
  652. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.3 R- R$ X1 y/ |. R
  653. /// \return address of the allocated memory block or NULL in case of no memory is available.
    1 [5 ~: o5 z% V# |. Q7 d3 k* h5 R+ ^
  654. void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout);3 x# F( R, }, w- ~

  655. " @) B8 D( C0 X8 C; C
  656. /// Return an allocated memory block back to a Memory Pool.. x2 o! P4 H5 f- G$ P! K
  657. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.
    2 [# f* A4 U$ H, P9 q0 `. ~7 o
  658. /// \param[in]     block         address of the allocated memory block to be returned to the memory pool.* D( ]# ?& B  A" T& ?
  659. /// \return status code that indicates the execution status of the function.. I9 Z& ?1 b, Q7 G
  660. osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
    ' p1 }/ z" O# J

  661. 5 @8 M5 ]# r' W1 _* z9 _7 O
  662. /// Get maximum number of memory blocks in a Memory Pool.9 T/ F7 n- U7 d2 s. [7 {
  663. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.+ R: r) I& a7 M7 S# M5 Q9 M
  664. /// \return maximum number of memory blocks.
    4 Z) ^( A- O0 K; C; F5 J
  665. uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);6 ]' v- y( }8 N0 U
  666. * U( T- Q1 O8 i/ ~
  667. /// Get memory block size in a Memory Pool.( Q8 h( M+ w$ x( H) y! S0 e
  668. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.$ h5 o- e! V1 ]+ X( M2 w6 G  H
  669. /// \return memory block size in bytes.
    5 g) e- j4 z4 T! d1 x
  670. uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);/ M8 |9 N/ [& F2 P1 b0 @
  671. 0 d" i6 N% C& d. L
  672. /// Get number of memory blocks used in a Memory Pool.
    5 g& k& W" f6 D
  673. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.6 T' W! J4 X0 u! ]+ h
  674. /// \return number of memory blocks used.! o8 j% A7 b9 @8 T8 }5 I' R$ I' H
  675. uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
    ; h+ z8 H& V) l# \; k' Z

  676. , z3 I2 D5 C- c7 ]  ?. |
  677. /// Get number of memory blocks available in a Memory Pool.
    , z5 e+ U9 N- n7 A2 g1 ^
  678. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.
    0 O% B$ S3 q0 G: E" G/ J) F/ N
  679. /// \return number of memory blocks available.& A8 H: |  ^+ B8 u8 u/ @& }
  680. uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);. l0 L4 V5 [6 i& B; p

  681. / c( ], S, I* O) v5 P/ m. A
  682. /// Delete a Memory Pool object.$ o6 i, [% T* D
  683. /// \param[in]     mp_id         memory pool ID obtained by \ref osMemoryPoolNew.) e6 p5 B* V* ?4 @
  684. /// \return status code that indicates the execution status of the function.
    ( N& F! k, ], b
  685. osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);* N: \5 c, |& A4 F/ g+ W
  686. . k1 {/ F' n4 N! X! \7 E: F

  687. - Z) _# @/ Q  W7 l  W
  688. //  ==== Message Queue Management Functions ====% Q0 I4 d' {' c$ A4 [0 a
  689. ' z9 p* D: ~" Y- k$ O* R- K4 o4 F( z
  690. /// Create and Initialize a Message Queue object.
    ! D, T* c0 x/ _- ^
  691. /// \param[in]     msg_count     maximum number of messages in queue.2 I' ^! H  V7 u6 }1 q. D
  692. /// \param[in]     msg_size      maximum message size in bytes.
    $ N/ ^: ]' ?; @# [
  693. /// \param[in]     attr          message queue attributes; NULL: default values.
    0 t, O$ F1 q% t! }) e" A. m
  694. /// \return message queue ID for reference by other functions or NULL in case of error.
    7 N( f2 U, i3 q1 G  q7 {0 A
  695. osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
    4 R0 W9 V; g; J/ e# D5 c

  696. ' |; Z# z# e4 `* j) J
  697. /// Get name of a Message Queue object.
    5 L, Y. O4 i: K: E
  698. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.5 u9 u0 F: U, |9 F' z  }- i
  699. /// \return name as NULL terminated string.
    % M+ l& L$ i( d9 d
  700. const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
    1 N+ M. B# ~3 ]$ s, t3 V
  701. 9 y& _( ~: b* i+ z
  702. /// Put a Message into a Queue or timeout if Queue is full.' o2 f5 R3 P( @/ g$ e
  703. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.* N2 E, M/ x2 n' O: v
  704. /// \param[in]     msg_ptr       pointer to buffer with message to put into a queue.8 R! m# j9 M0 g
  705. /// \param[in]     msg_prio      message priority.; U3 Y! t& N7 K. G
  706. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
    - T  ?3 x7 z5 s  w; s# g- w
  707. /// \return status code that indicates the execution status of the function.
    6 }+ k$ [; C5 n1 b# i' f
  708. osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);7 E. j* }) W, K% h  K5 y
  709. , w' y7 g: P/ n. x
  710. /// Get a Message from a Queue or timeout if Queue is empty.
    : S, F: ^( q# m: K. C1 Z
  711. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.
    ! U* K" S4 ^% C4 V- O
  712. /// \param[out]    msg_ptr       pointer to buffer for message to get from a queue.
    : V# z+ T7 i8 W. c; \' H
  713. /// \param[out]    msg_prio      pointer to buffer for message priority or NULL.
    + V1 G' z1 V  |
  714. /// \param[in]     timeout       \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
    - Q, v5 j. K4 @% a/ g: u/ W
  715. /// \return status code that indicates the execution status of the function.
    8 K( {. @; Z, I4 u9 H3 j2 s3 D+ T
  716. osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);
    0 I% ]& N3 P9 p/ k' }

  717. + F4 l/ v# j* R3 e) U1 {( U
  718. /// Get maximum number of messages in a Message Queue.
    ( B0 I/ q, {' V( s, N. T6 c
  719. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.  i& |7 j1 A8 v/ X1 l1 X
  720. /// \return maximum number of messages.
      ?4 V- T' ]8 I1 B6 @4 h- D/ N' x
  721. uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);0 ]3 U. J  |  Z+ b. {* }# X$ p
  722. 7 q* c' m- A; s2 d1 m! B, K1 R
  723. /// Get maximum message size in a Memory Pool.! ~: q! O, f! c. p3 i9 S- c
  724. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.# U% e& w3 [6 Q8 I" y
  725. /// \return maximum message size in bytes.
    5 @- ~% E8 C2 c9 V8 `' q8 O
  726. uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);1 A$ ]& T' s& i8 n+ p, ?
  727.   {1 T+ y6 N- u3 @* d+ y( s" r
  728. /// Get number of queued messages in a Message Queue.- [( m8 N- B$ @# p! \6 n
  729. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.
    ) l; c0 r: Z; u5 F% t
  730. /// \return number of queued messages." r: \' A# h- U( h. q, l
  731. uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);5 Y4 |1 h7 X& \& B+ a. p
  732. * |2 U/ W* y7 U
  733. /// Get number of available slots for messages in a Message Queue./ c: k) r/ m" x% \. p1 ^! f
  734. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.) L, M. D7 ~" Y6 Q5 [+ `4 G5 }
  735. /// \return number of available slots for messages.( C* [9 ]/ |5 Z% A9 P
  736. uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
    , S) p  g  D) K5 m9 n

  737. 3 `# d, ~5 P' t$ l1 u0 T% A
  738. /// Reset a Message Queue to initial empty state.$ N! x, s" I& E% U  `4 T
  739. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.
    8 }' J  U: z: i
  740. /// \return status code that indicates the execution status of the function.
    ' t+ y- o! d: i$ Z* g  \3 `  a
  741. osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
    9 O) ?# B# y* I& t3 V7 s# ]

  742. / t2 j/ y0 G4 s" d" |, Y. J( G- U
  743. /// Delete a Message Queue object.
    # x  B( ]' @7 y2 q
  744. /// \param[in]     mq_id         message queue ID obtained by \ref osMessageQueueNew.( z% Q0 d# M- f, G0 m2 R9 s4 Z
  745. /// \return status code that indicates the execution status of the function.
    & r3 _( i2 u9 d; k6 c% q' }# z( Y$ k
  746. osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
    ! E; b# P/ j4 r+ M

  747. 7 a. w- r# k8 g! S% j1 N- }/ B5 A
  748. # N. J6 z3 i5 d! L: j' Y9 n
  749. #ifdef  __cplusplus
    + n( _9 m4 I0 J: k
  750. }
    - J* I" m/ q( T
  751. #endif) k/ T% K* h% J, Y  x" B

  752. 1 s! \2 a9 @4 r* d
  753. #endif  // CMSIS_OS2_H_
复制代码
1 ^& C4 I3 K/ y3 U, Y
归档链接:$ U7 m4 J- `+ S8 k
CMSIS-RTOS2 文档翻译 之 简介" h7 q. B/ I+ }! I" r
CMSIS-RTOS2 文档翻译 之 修订记录
' T2 p& k& L0 sCMSIS-RTOS2 文档翻译 之 功能概述
7 A0 \1 g$ q2 e. q  f, M4 @) p. rCMSIS-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
/ [& d4 t! r" n: M支持,我现在用的是cmsis_os接口

6 m1 o( |( h2 b* W! @. k  c; i就是相关的教程和文档比较少,用的人比较少,你很有前瞻性啊。
黑皮男 回答时间:2018-4-22 09:42:30
XinLiYF 发表于 2018-4-22 09:14
; W2 e+ A( _4 D' H就是相关的教程和文档比较少,用的人比较少,你很有前瞻性啊。

) Z3 V) ^2 C1 M8 }: a9 p" A- q2 }之前都是自己封装RTOS的接口,发现cmsis_os后,既然都有统一的接口,干脆就拿来用了,比自己封装的要好很多
XinLiYF 回答时间:2018-4-22 10:26:00
黑皮男 发表于 2018-4-22 09:42  b+ l* v( ]' A# N0 C  r& C
之前都是自己封装RTOS的接口,发现cmsis_os后,既然都有统一的接口,干脆就拿来用了,比自己封装的要好很 ...
: i7 S$ U4 i- e
刚去你 GitHub 逛啦一圈 ,你肯定是一个外表粗犷内心细腻的人 ,GitHub 上关注你了
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版