-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRTOS_interface.h
281 lines (259 loc) · 9.59 KB
/
RTOS_interface.h
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
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
222
223
224
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
* RTOS_interface.h
*
* Created on: 14 Sep 2019
* Author: Yahia
*/
#ifndef RTOS_INTERFACE_H_
#define RTOS_INTERFACE_H_
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Task Control Block (TCB) */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
typedef struct{
void(*task_name)(void); /* This field contains the address of the first line of the task */
uint32 period; /* This field contains the periodic time of the task
updating this value during run time may cause undefined behaviour
*/
sint32 release_time; /* This field contains the release time of the task
This value is updated automatically by the OS based on each task's priority*/
uint8 PendOn; /* This field indicates what the task is pending on and contains one of these values
OSTaskPendOnNothing
OSTaskPendOnMutex
OSTaskPendOnEvent
This value must be OSTaskPendOnNothing if the task is not in the pending state
*/
uint8 priority; /* This field contains the priority of the task
Priority must be unique for each task
Priority must not exceed the value of MaxTaskNum-1 in RTOS_config.h
*/
uint8 state; /* This field indicates the current state of a task and contains one of these values
OSTaskStateReady
OSTaskStateBlocked
OSTaskStateRunning
OSTaskStatePending
*/
uint8 Blocker; /* This field indicates the ID of the Blocker
If the task is not in the blocked state this value must be BLOCKER_NoBlocker
This field contains one of these values
BLOCKER_USER
BLOCKER_MUTEX
BLOCKER_NoBlocker
*/
}TCB;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Mutex Struscture */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
typedef struct{
uint8 MutID; /* This field contains mutex id
MutID must be unique for each mutex
MutID must not exceed the value of NumOfMutex in RTOS_config.h
*/
uint8 MutStatus; /* This field indicates the current state of a mutex and contains one of these values
MutReady
MutTaken
*/
uint8 ServiceID; /* This field contains the Service Id of the mutex service
This field is updated by the OS
*/
void(*MutTask)(void); /* This field contains the address of the task that takes the task*/
}MutexStruct;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Task states */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef OSTaskStateReady
#define OSTaskStateReady 0
#endif
#ifndef OSTaskStateBlocked
#define OSTaskStateBlocked 1
#endif
#ifndef OSTaskStateRunning
#define OSTaskStateRunning 2
#endif
#ifndef OSTaskStatePending
#define OSTaskStatePending 3
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Blocker states */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef BLOCKER_USER
#define BLOCKER_USER 0
#endif
#ifndef BLOCKER_MUTEX
#define BLOCKER_MUTEX 1
#endif
#ifndef BLOCKER_NoBlocker
#define BLOCKER_NoBlocker 0xFF
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Pend on states */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef OSTaskPendOnNothing
#define OSTaskPendOnNothing 0
#endif
#ifndef OSTaskPendOnMutex
#define OSTaskPendOnMutex 1
#endif
#ifndef OSTaskPendOnEvent
#define OSTaskPendOnEvent 2
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Priority values */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define PRIORITY_0 0
#define PRIORITY_1 1
#define PRIORITY_2 2
#define PRIORITY_3 3
#define PRIORITY_4 4
#define PRIORITY_5 5
#define PRIORITY_6 6
#define PRIORITY_7 7
#define PRIORITY_8 8
#define PRIORITY_9 9
#define PRIORITY_10 10
#define PRIORITY_11 11
#define PRIORITY_12 12
#define PRIORITY_13 13
#define PRIORITY_14 14
#define PRIORITY_15 15
#define PRIORITY_16 16
#define PRIORITY_17 17
#define PRIORITY_18 18
#define PRIORITY_19 19
#define PRIORITY_20 20
#define PRIORITY_21 21
#define PRIORITY_22 22
#define PRIORITY_23 23
#define PRIORITY_24 24
#define PRIORITY_25 25
#define PRIORITY_26 26
#define PRIORITY_27 27
#define PRIORITY_28 28
#define PRIORITY_29 29
#define PRIORITY_30 30
#define PRIORITY_31 31
#define PRIORITY_32 32
#define PRIORITY_33 33
#define PRIORITY_34 34
#define PRIORITY_35 35
/* RTOS_Init
* Function Description: Initialise OS
* Parameters(In): None.
* Parameters(Out): None.
* Return Value: None.
* Sync/Async: Synchronous.
* Reentrancy: Reentrant.
* */
void RTOS_Init(void);
/* Start_OS
* Function Description: starting OS
* Parameters(In): None.
* Parameters(Out): None.
* Return Value: None.
* */
void Start_OS(void);
/* CreatePeriodicTask
* Function Description: create periodic task
* Parameters(In): Task_name --> Pointer to task
Task_period --> Task period in ms
Task_priority --> Task_priority: integer from 0 to MaxTaskNum-1
you can use one value from Priority values in RTOS_interface.h file.
Task_state --> contains one of these values
OSTaskStateReady
OSTaskStateBlocked
OSTaskStatePending
using OSTaskStateRunning in this field will generate an error.
Task_release_time --> Task release time in ms.
* Parameters(Out): None.
* Return Value: None.
* */
void CreatePeriodicTask(void(*Task_name)(void), uint32 Task_period, uint8 Task_priority, uint8 Task_state, sint32 Task_release_time);
/* OS_DelayMS
* Function Description: this function is used to make delay
* Parameters(In): milliseconds --> number of milliseconds.
* Parameters(Out): None.
* Return Value: None.
* */
void OS_DelayMS(uint32 milliseconds);
/* DeleteTask
* Function Description: this function is used to delete a task
* Parameters(In): Task_name --> Pointer to task.
* Parameters(Out): None.
* Return Value: None.
* */
void DeleteTask(void(*Task_name)(void));
/* ChangePriority
* Function Description: this function is used to delete a task
* Parameters(In): Task_name --> Pointer to task.
Prior --> the new priority of the task
* Parameters(Out): None.
* Return Value: None.
* */
void ChangePriority(void(*Task_name)(void), uint8 Prior);
/* BlockTask
* Function Description: this function is used to block a task
* Parameters(In): Task_name --> Pointer to task.
BlockerID --> the blocker of the task
while using this task by user this value must be USER
* Parameters(Out): None.
* Return Value: None.
* */
void BlockTask(void(*Task_name)(void), uint8 BlockerID);
/* UnblockTask
* Function Description: this function is used to unblock a task to the ready state
* Parameters(In): Task_name --> Pointer to task.
* Parameters(Out): None.
* Return Value: None.
* */
void UnblockTask(void(*Task_name)(void));
/* OSTaskCreatePending
* Function Description: this function is used to put the task in the pending state
if you created a task as pending you must use this function before starting OS.
* Parameters(In): Task_name --> Pointer to task.
PTRtoService --> Pointer to the service you want to pend on
you can use these values
OSTaskPendOnMutex
OSTaskPendOnMutexEvent
* Parameters(Out): None.
* Return Value: None.
* */
void OSTaskCreatePending(void(*Task_name)(void), uint8* PTRtoService);
/* MutexCreate
* Function Description: this function is used to create a mutex
* Parameters(In): MutexIndex --> unique value of mutex from 0 to NumOfMutex-1.
Pointer to MutexStruct --> Pointer to the created mutex.
* Parameters(Out): None.
* Return Value: Pointer to MutexStruct --> Pointer to the created mutex..
* */
MutexStruct* MutexCreate(uint8 MutexIndex);
/* MutexTake
* Function Description: this function is used to acquire a mutex
if the mutex is already, the task will be blocked until the task that took it release the mutex
* Parameters(In): PtrToMut --> Pointer to mutex that you want to take.
* Parameters(Out): None.
* Return Value: None.
* */
void MutexTake(MutexStruct* PtrToMut);
/* MutexRelease
* Function Description: this function is used to release the mutex
the task that took the mutex is the only task that can release it
* Parameters(In): PtrToMut --> Pointer to mutex that you want to take.
* Parameters(Out): None.
* Return Value: None.
* */
void MutexRelease(MutexStruct* PtrToMut);
/* OSSchedulerOn
* Function Description: this function is used to turn the scheduler on
the scheduler in on by default unless you turn it off
* Parameters(In): None.
* Parameters(Out): None.
* Return Value: None.
* */
void OSSchedulerOn(void);
/* OSSchedulerOff
* Function Description: this function is used to turn the scheduler off
* Parameters(In): None.
* Parameters(Out): None.
* Return Value: None.
* */
void OSSchedulerOff(void);
#endif /* RTOS_INTERFACE_H_ */