-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathos.c
88 lines (64 loc) · 1.28 KB
/
os.c
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
/*
* os.c
*
* Created on: 2012-01-11
* Author: Mustapha Mekhatria
*/
#include "osHeader.h"
void startOS()
{
//Call Sched
Sched();
}
void Sched()
{
int iIndex;
//Select task with high priority
iHighPriorityTask = 10;
for (iIndex = 0; iIndex < iTaskcount ; iIndex++)
{
if ((arrTaskTable[iIndex].Priority <= iHighPriorityTask) &&
(arrTaskTable[iIndex].Ready ==1 ))
{
iHighPriorityTask = arrTaskTable[iIndex].Priority;
iIndexPriority = iIndex;
}
}
//call task with high priority
(*arrTaskTable[iIndexPriority].ptrTask)();
}
void createTask(void (*ptrTask)(void), int iPriority, int iTaskId )
{
//Save priotiy
arrTaskTable[iTaskcount].Priority = iPriority;
//Save task address
arrTaskTable[iTaskcount].ptrTask = ptrTask;
//Save task ID
arrTaskTable[iTaskcount].TaskId = iTaskId;
//Make the task ready
arrTaskTable[iTaskcount].Ready = 1;
//Increment iTaskcount
iTaskcount ++;
}
void waitTask()
{
arrTaskTable[iIndexPriority].Ready = 0;
//Call Sched
Sched();
}
void startTask(int TaskId)
{
int iIndex;
for (iIndex = 0; iIndex <iTaskcount; iIndex ++ )
{
if (TaskId == arrTaskTable[iIndex].TaskId)
{
arrTaskTable[iIndex].Ready = 1;
}
}
//Call Sched
Sched();
}
void ContextSwitch(void)
{
}