1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
80
81
82
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
259
260
261
267
268
269
275
276
277
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
/* ... */
#ifndef CMSIS_OS2_H_
#define CMSIS_OS2_H_
#ifndef __NO_RETURN
#if defined(__CC_ARM)
#define __NO_RETURN __declspec(noreturn)
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#define __NO_RETURN __attribute__((__noreturn__))
#elif defined(__GNUC__)
#define __NO_RETURN __attribute__((__noreturn__))
#elif defined(__ICCARM__)
#define __NO_RETURN __noreturn
#else
#define __NO_RETURN
#endif/* ... */
#endif
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{/* ... */
#endif
typedef struct {
uint32_t api;
uint32_t kernel;
...} osVersion_t;
typedef enum {
osKernelInactive = 0,
osKernelReady = 1,
osKernelRunning = 2,
osKernelLocked = 3,
osKernelSuspended = 4,
osKernelError = -1,
osKernelReserved = 0x7FFFFFFF
...} osKernelState_t;
typedef enum {
osThreadInactive = 0,
osThreadReady = 1,
osThreadRunning = 2,
osThreadBlocked = 3,
osThreadTerminated = 4,
osThreadError = -1,
osThreadReserved = 0x7FFFFFFF
...} osThreadState_t;
typedef enum {
osPriorityNone = 0,
osPriorityIdle = 1,
osPriorityLow = 8,
osPriorityLow1 = 8+1,
osPriorityLow2 = 8+2,
osPriorityLow3 = 8+3,
osPriorityLow4 = 8+4,
osPriorityLow5 = 8+5,
osPriorityLow6 = 8+6,
osPriorityLow7 = 8+7,
osPriorityBelowNormal = 16,
osPriorityBelowNormal1 = 16+1,
osPriorityBelowNormal2 = 16+2,
osPriorityBelowNormal3 = 16+3,
osPriorityBelowNormal4 = 16+4,
osPriorityBelowNormal5 = 16+5,
osPriorityBelowNormal6 = 16+6,
osPriorityBelowNormal7 = 16+7,
osPriorityNormal = 24,
osPriorityNormal1 = 24+1,
osPriorityNormal2 = 24+2,
osPriorityNormal3 = 24+3,
osPriorityNormal4 = 24+4,
osPriorityNormal5 = 24+5,
osPriorityNormal6 = 24+6,
osPriorityNormal7 = 24+7,
osPriorityAboveNormal = 32,
osPriorityAboveNormal1 = 32+1,
osPriorityAboveNormal2 = 32+2,
osPriorityAboveNormal3 = 32+3,
osPriorityAboveNormal4 = 32+4,
osPriorityAboveNormal5 = 32+5,
osPriorityAboveNormal6 = 32+6,
osPriorityAboveNormal7 = 32+7,
osPriorityHigh = 40,
osPriorityHigh1 = 40+1,
osPriorityHigh2 = 40+2,
osPriorityHigh3 = 40+3,
osPriorityHigh4 = 40+4,
osPriorityHigh5 = 40+5,
osPriorityHigh6 = 40+6,
osPriorityHigh7 = 40+7,
osPriorityRealtime = 48,
osPriorityRealtime1 = 48+1,
osPriorityRealtime2 = 48+2,
osPriorityRealtime3 = 48+3,
osPriorityRealtime4 = 48+4,
osPriorityRealtime5 = 48+5,
osPriorityRealtime6 = 48+6,
osPriorityRealtime7 = 48+7,
osPriorityISR = 56,
osPriorityError = -1,
osPriorityReserved = 0x7FFFFFFF
...} osPriority_t;
typedef void (*osThreadFunc_t) (void *argument);
typedef void (*osTimerFunc_t) (void *argument);
typedef enum {
osTimerOnce = 0,
osTimerPeriodic = 1
...} osTimerType_t;
#define osWaitForever 0xFFFFFFFFU
#define osFlagsWaitAny 0x00000000U
#define osFlagsWaitAll 0x00000001U
#define osFlagsNoClear 0x00000002U
#define osFlagsError 0x80000000U
#define osFlagsErrorUnknown 0xFFFFFFFFU
#define osFlagsErrorTimeout 0xFFFFFFFEU
#define osFlagsErrorResource 0xFFFFFFFDU
#define osFlagsErrorParameter 0xFFFFFFFCU
#define osFlagsErrorISR 0xFFFFFFFAU
#define osThreadDetached 0x00000000U
#define osThreadJoinable 0x00000001U
#define osMutexRecursive 0x00000001U
#define osMutexPrioInherit 0x00000002U
#define osMutexRobust 0x00000008U
15 defines
typedef enum {
osOK = 0,
osError = -1,
osErrorTimeout = -2,
osErrorResource = -3,
osErrorParameter = -4,
osErrorNoMemory = -5,
osErrorISR = -6,
osStatusReserved = 0x7FFFFFFF
...} osStatus_t;
typedef void *osThreadId_t;
typedef void *osTimerId_t;
typedef void *osEventFlagsId_t;
typedef void *osMutexId_t;
typedef void *osSemaphoreId_t;
typedef void *osMemoryPoolId_t;
typedef void *osMessageQueueId_t;
#ifndef TZ_MODULEID_T
#define TZ_MODULEID_T
typedef uint32_t TZ_ModuleId_t;/* ... */
#endif
typedef struct {
const char *name;
uint32_t attr_bits;
void *cb_mem;
uint32_t cb_size;
void *stack_mem;
uint32_t stack_size;
osPriority_t priority;
TZ_ModuleId_t tz_module;
uint32_t reserved;
...} osThreadAttr_t;
typedef struct {
const char *name;
uint32_t attr_bits;
void *cb_mem;
uint32_t cb_size;
...} osTimerAttr_t;
typedef struct {
const char *name;
uint32_t attr_bits;
void *cb_mem;
uint32_t cb_size;
...} osEventFlagsAttr_t;
typedef struct {
const char *name;
uint32_t attr_bits;
void *cb_mem;
uint32_t cb_size;
...} osMutexAttr_t;
typedef struct {
const char *name;
uint32_t attr_bits;
void *cb_mem;
uint32_t cb_size;
...} osSemaphoreAttr_t;
typedef struct {
const char *name;
uint32_t attr_bits;
void *cb_mem;
uint32_t cb_size;
void *mp_mem;
uint32_t mp_size;
...} osMemoryPoolAttr_t;
typedef struct {
const char *name;
uint32_t attr_bits;
void *cb_mem;
uint32_t cb_size;
void *mq_mem;
uint32_t mq_size;
...} osMessageQueueAttr_t;
osStatus_t osKernelInitialize (void);
osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
osKernelState_t osKernelGetState (void);
osStatus_t osKernelStart (void);
int32_t osKernelLock (void);
int32_t osKernelUnlock (void);
int32_t osKernelRestoreLock (int32_t lock);
uint32_t osKernelSuspend (void);
void osKernelResume (uint32_t sleep_ticks);
uint32_t osKernelGetTickCount (void);
uint32_t osKernelGetTickFreq (void);
uint32_t osKernelGetSysTimerCount (void);
uint32_t osKernelGetSysTimerFreq (void);
osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr);
const char *osThreadGetName (osThreadId_t thread_id);
osThreadId_t osThreadGetId (void);
osThreadState_t osThreadGetState (osThreadId_t thread_id);
uint32_t osThreadGetStackSize (osThreadId_t thread_id);
uint32_t osThreadGetStackSpace (osThreadId_t thread_id);
osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);
osPriority_t osThreadGetPriority (osThreadId_t thread_id);
osStatus_t osThreadYield (void);
osStatus_t osThreadSuspend (osThreadId_t thread_id);
osStatus_t osThreadResume (osThreadId_t thread_id);
osStatus_t osThreadDetach (osThreadId_t thread_id);
osStatus_t osThreadJoin (osThreadId_t thread_id);
__NO_RETURN void osThreadExit (void);
osStatus_t osThreadTerminate (osThreadId_t thread_id);
uint32_t osThreadGetCount (void);
uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);
uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags);
uint32_t osThreadFlagsClear (uint32_t flags);
uint32_t osThreadFlagsGet (void);
uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout);
osStatus_t osDelay (uint32_t ticks);
osStatus_t osDelayUntil (uint32_t ticks);
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
const char *osTimerGetName (osTimerId_t timer_id);
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
osStatus_t osTimerStop (osTimerId_t timer_id);
uint32_t osTimerIsRunning (osTimerId_t timer_id);
osStatus_t osTimerDelete (osTimerId_t timer_id);
osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
const char *osEventFlagsGetName (osEventFlagsId_t ef_id);
uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags);
uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags);
uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);
uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout);
osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
osMutexId_t osMutexNew (const osMutexAttr_t *attr);
const char *osMutexGetName (osMutexId_t mutex_id);
osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
osStatus_t osMutexRelease (osMutexId_t mutex_id);
osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
osStatus_t osMutexDelete (osMutexId_t mutex_id);
osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);
osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout);
osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id);
void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout);
osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);
uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);
osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);
osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);
uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
#ifdef __cplusplus
}extern "C" { ... }
#endif
/* ... */
#endif