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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
168
169
170
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
289
290
291
292
293
294
300
301
302
303
309
310
311
312
318
319
320
321
326
327
328
329
330
331
332
333
335
336
337
338
339
340
341
346
347
348
349
350
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
412
427
428
429
430
431
432
433
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
488
489
490
491
492
493
494
495
496
497
498
501
515
516
517
518
519
520
521
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
586
599
600
601
602
603
604
605
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
646
658
659
660
661
662
663
664
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
710
714
715
716
717
718
719
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
757
758
759
760
761
764
778
779
780
781
782
783
784
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
827
832
833
834
835
836
837
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
890
891
892
893
899
900
901
902
903
904
905
906
907
908
909
910
911
912
917
918
919
924
925
926
930
931
932
936
937
938
939
940
941
942
943
944
945
946
947
948
953
954
955
962
963
964
970
971
972
977
978
979
984
985
986
991
992
993
998
999
1000
1005
1006
1007
1013
1014
1015
1020
1021
1022
1023
1024
1025
1026
/* ... */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "queue.h"
#include "semphr.h"
#include "event_groups.h"
6 includes
/* ... */
#ifndef _CMSIS_OS_H
#define _CMSIS_OS_H
#define osCMSIS 0x10002
#define osCMSIS_KERNEL 0x10000
#define osKernelSystemId "KERNEL V1.00"
#define osFeature_MainThread 1
#define osFeature_Pool 1
#define osFeature_MailQ 1
#define osFeature_MessageQ 1
#define osFeature_Signals 8
#define osFeature_Semaphore 1
#define osFeature_Wait 0
#define osFeature_SysTick 1
12 defines
#ifdef __cplusplus
extern "C"
{/* ... */
#endif
typedef enum {
osPriorityIdle = -3,
osPriorityLow = -2,
osPriorityBelowNormal = -1,
osPriorityNormal = 0,
osPriorityAboveNormal = +1,
osPriorityHigh = +2,
osPriorityRealtime = +3,
osPriorityError = 0x84
...} osPriority;
#define osWaitForever 0xFFFFFFFF
typedef enum {
osOK = 0,
osEventSignal = 0x08,
osEventMessage = 0x10,
osEventMail = 0x20,
osEventTimeout = 0x40,
osErrorParameter = 0x80,
osErrorResource = 0x81,
osErrorTimeoutResource = 0xC1,
osErrorISR = 0x82,
osErrorISRRecursive = 0x83,
osErrorPriority = 0x84,
osErrorNoMemory = 0x85,
osErrorValue = 0x86,
osErrorOS = 0xFF,
os_status_reserved = 0x7FFFFFFF
...} osStatus;
#if ( INCLUDE_eTaskGetState == 1 )
typedef enum {
osThreadRunning = 0x0,
osThreadReady = 0x1 ,
osThreadBlocked = 0x2,
osThreadSuspended = 0x3,
osThreadDeleted = 0x4,
osThreadError = 0x7FFFFFFF
...} osThreadState;/* ... */
#endif
typedef enum {
osTimerOnce = 0,
osTimerPeriodic = 1
...} os_timer_type;
typedef void (*os_pthread) (void const *argument);
typedef void (*os_ptimer) (void const *argument);
typedef TaskHandle_t osThreadId;
typedef TimerHandle_t osTimerId;
typedef SemaphoreHandle_t osMutexId;
typedef SemaphoreHandle_t osSemaphoreId;
typedef struct os_pool_cb *osPoolId;
typedef QueueHandle_t osMessageQId;
typedef struct os_mailQ_cb *osMailQId;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
typedef StaticTask_t osStaticThreadDef_t;
typedef StaticTimer_t osStaticTimerDef_t;
typedef StaticSemaphore_t osStaticMutexDef_t;
typedef StaticSemaphore_t osStaticSemaphoreDef_t;
typedef StaticQueue_t osStaticMessageQDef_t;
/* ... */
#endif
typedef struct os_thread_def {
char *name;
os_pthread pthread;
osPriority tpriority;
uint32_t instances;
uint32_t stacksize;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
uint32_t *buffer;
osStaticThreadDef_t *controlblock; /* ... */
#endif
...} osThreadDef_t;
typedef struct os_timer_def {
os_ptimer ptimer;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
osStaticTimerDef_t *controlblock;
#endif
...} osTimerDef_t;
typedef struct os_mutex_def {
uint32_t dummy;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
osStaticMutexDef_t *controlblock;
#endif
...} osMutexDef_t;
typedef struct os_semaphore_def {
uint32_t dummy;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
osStaticSemaphoreDef_t *controlblock;
#endif
...} osSemaphoreDef_t;
typedef struct os_pool_def {
uint32_t pool_sz;
uint32_t item_sz;
void *pool;
...} osPoolDef_t;
typedef struct os_messageQ_def {
uint32_t queue_sz;
uint32_t item_sz;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
uint8_t *buffer;
osStaticMessageQDef_t *controlblock; /* ... */
#endif
...} osMessageQDef_t;
typedef struct os_mailQ_def {
uint32_t queue_sz;
uint32_t item_sz;
struct os_mailQ_cb **cb;
...} osMailQDef_t;
typedef struct {
osStatus status;
union {
uint32_t v;
void *p;
int32_t signals;
...} value;
union {
osMailQId mail_id;
osMessageQId message_id;
...} def;
...} osEvent;
osStatus osKernelInitialize (void);
osStatus osKernelStart (void);
int32_t osKernelRunning(void);
#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0))
uint32_t osKernelSysTick (void);
#define osKernelSysTickFrequency (configTICK_RATE_HZ)
#define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000)
/* ... */
#endif
#if defined (osObjectsExternal)
#define osThreadDef(name, thread, priority, instances, stacksz) \
extern const osThreadDef_t os_thread_def_##name...
/* ... */#else
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
#define osThreadDef(name, thread, priority, instances, stacksz) \
const osThreadDef_t os_thread_def_##name = \
{ #name, (thread), (priority), (instances), (stacksz), NULL, NULL }...
#define osThreadStaticDef(name, thread, priority, instances, stacksz, buffer, control) \
const osThreadDef_t os_thread_def_##name = \
{ #name, (thread), (priority), (instances), (stacksz), (buffer), (control) }...
/* ... */#else
#define osThreadDef(name, thread, priority, instances, stacksz) \
const osThreadDef_t os_thread_def_##name = \
{ #name, (thread), (priority), (instances), (stacksz)}...
/* ... */#endif/* ... */
#endif
#define osThread(name) \
&os_thread_def_##name...
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);
osThreadId osThreadGetId (void);
osStatus osThreadTerminate (osThreadId thread_id);
osStatus osThreadYield (void);
osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
osPriority osThreadGetPriority (osThreadId thread_id);
osStatus osDelay (uint32_t millisec);
#if (defined (osFeature_Wait) && (osFeature_Wait != 0))
osEvent osWait (uint32_t millisec);
/* ... */
#endif
#if defined (osObjectsExternal)
#define osTimerDef(name, function) \
extern const osTimerDef_t os_timer_def_##name...
/* ... */#else
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
#define osTimerDef(name, function) \
const osTimerDef_t os_timer_def_##name = \
{ (function), NULL }...
#define osTimerStaticDef(name, function, control) \
const osTimerDef_t os_timer_def_##name = \
{ (function), (control) }...
/* ... */#else
#define osTimerDef(name, function) \
const osTimerDef_t os_timer_def_##name = \
{ (function) }...
/* ... */#endif/* ... */
#endif
#define osTimer(name) \
&os_timer_def_##name...
osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);
osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
osStatus osTimerStop (osTimerId timer_id);
osStatus osTimerDelete (osTimerId timer_id);
int32_t osSignalSet (osThreadId thread_id, int32_t signals);
int32_t osSignalClear (osThreadId thread_id, int32_t signals);
osEvent osSignalWait (int32_t signals, uint32_t millisec);
#if defined (osObjectsExternal)
#define osMutexDef(name) \
extern const osMutexDef_t os_mutex_def_##name...
/* ... */#else
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
#define osMutexDef(name) \
const osMutexDef_t os_mutex_def_##name = { 0, NULL }...
#define osMutexStaticDef(name, control) \
const osMutexDef_t os_mutex_def_##name = { 0, (control) }...
/* ... */#else
#define osMutexDef(name) \
const osMutexDef_t os_mutex_def_##name = { 0 }...
/* ... */
#endif
/* ... */
#endif
#define osMutex(name) \
&os_mutex_def_##name...
osMutexId osMutexCreate (const osMutexDef_t *mutex_def);
osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
osStatus osMutexRelease (osMutexId mutex_id);
osStatus osMutexDelete (osMutexId mutex_id);
#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0))
#if defined (osObjectsExternal)
#define osSemaphoreDef(name) \
extern const osSemaphoreDef_t os_semaphore_def_##name...
/* ... */#else
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
#define osSemaphoreDef(name) \
const osSemaphoreDef_t os_semaphore_def_##name = { 0, NULL }...
#define osSemaphoreStaticDef(name, control) \
const osSemaphoreDef_t os_semaphore_def_##name = { 0, (control) }...
/* ... */
#else
#define osSemaphoreDef(name) \
const osSemaphoreDef_t os_semaphore_def_##name = { 0 }...
/* ... */#endif/* ... */
#endif
#define osSemaphore(name) \
&os_semaphore_def_##name...
osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);
int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
/* ... */
#endif
#if (defined (osFeature_Pool) && (osFeature_Pool != 0))
#if defined (osObjectsExternal)
#define osPoolDef(name, no, type) \
extern const osPoolDef_t os_pool_def_##name...
/* ... */#else
#define osPoolDef(name, no, type) \
const osPoolDef_t os_pool_def_##name = \
{ (no), sizeof(type), NULL }...
/* ... */#endif
#define osPool(name) \
&os_pool_def_##name...
osPoolId osPoolCreate (const osPoolDef_t *pool_def);
void *osPoolAlloc (osPoolId pool_id);
void *osPoolCAlloc (osPoolId pool_id);
osStatus osPoolFree (osPoolId pool_id, void *block);
/* ... */
#endif
#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0))
#if defined (osObjectsExternal)
#define osMessageQDef(name, queue_sz, type) \
extern const osMessageQDef_t os_messageQ_def_##name...
/* ... */#else
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
#define osMessageQDef(name, queue_sz, type) \
const osMessageQDef_t os_messageQ_def_##name = \
{ (queue_sz), sizeof (type), NULL, NULL }...
#define osMessageQStaticDef(name, queue_sz, type, buffer, control) \
const osMessageQDef_t os_messageQ_def_##name = \
{ (queue_sz), sizeof (type) , (buffer), (control)}...
/* ... */#else
#define osMessageQDef(name, queue_sz, type) \
const osMessageQDef_t os_messageQ_def_##name = \
{ (queue_sz), sizeof (type) }...
/* ... */
#endif/* ... */
#endif
#define osMessageQ(name) \
&os_messageQ_def_##name...
osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);
osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
/* ... */
#endif
#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0))
#if defined (osObjectsExternal)
#define osMailQDef(name, queue_sz, type) \
extern struct os_mailQ_cb *os_mailQ_cb_##name \
extern osMailQDef_t os_mailQ_def_##name...
/* ... */#else
#define osMailQDef(name, queue_sz, type) \
struct os_mailQ_cb *os_mailQ_cb_##name; \
const osMailQDef_t os_mailQ_def_##name = \
{ (queue_sz), sizeof (type), (&os_mailQ_cb_##name) }...
/* ... */#endif
#define osMailQ(name) \
&os_mailQ_def_##name...
osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);
void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
osStatus osMailPut (osMailQId queue_id, void *mail);
osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
osStatus osMailFree (osMailQId queue_id, void *mail);
/* ... */
#endif
/* ... */
void osSystickHandler(void);
#if ( INCLUDE_eTaskGetState == 1 )
/* ... */
osThreadState osThreadGetState(osThreadId thread_id);/* ... */
#endif
#if ( INCLUDE_eTaskGetState == 1 )
/* ... */
osStatus osThreadIsSuspended(osThreadId thread_id);
/* ... */
#endif
/* ... */
osStatus osThreadSuspend (osThreadId thread_id);
/* ... */
osStatus osThreadResume (osThreadId thread_id);
/* ... */
osStatus osThreadSuspendAll (void);
/* ... */
osStatus osThreadResumeAll (void);
/* ... */
osStatus osDelayUntil (uint32_t *PreviousWakeTime, uint32_t millisec);
/* ... */
osStatus osAbortDelay(osThreadId thread_id);
/* ... */
osStatus osThreadList (uint8_t *buffer);
/* ... */
osEvent osMessagePeek (osMessageQId queue_id, uint32_t millisec);
/* ... */
uint32_t osMessageWaiting(osMessageQId queue_id);
/* ... */
uint32_t osMessageAvailableSpace(osMessageQId queue_id);
/* ... */
osStatus osMessageDelete (osMessageQId queue_id);
/* ... */
osMutexId osRecursiveMutexCreate (const osMutexDef_t *mutex_def);
/* ... */
osStatus osRecursiveMutexRelease (osMutexId mutex_id);
/* ... */
osStatus osRecursiveMutexWait (osMutexId mutex_id, uint32_t millisec);
/* ... */
uint32_t osSemaphoreGetCount(osSemaphoreId semaphore_id);
#ifdef __cplusplus
}extern "C" { ... }
#endif
/* ... */
#endif