-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
124 lines (106 loc) · 4.38 KB
/
main.c
File metadata and controls
124 lines (106 loc) · 4.38 KB
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
// 是的,每次编译前都要写 Makefile!(不过这次,Makefile 已经帮你写好了)
#include "ucos_ii.h"
#include "key_led.h"
#include "timer0.h"
#include "globals.h"
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define TASK_STK_SIZE 128 /* Size of each task's stacks (# of WORDs) */
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
// OS_STK TaskKeyStk[TASK_STK_SIZE]; /* Tasks stacks */
OS_STK TaskLedStk[3][TASK_STK_SIZE];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
// void TaskKey(void *pdata); /* Function prototypes of input tasks */
void TaskLed(void *pdata); /* Function prototypes of led task */
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
OS_FLAG_GRP *MyFlag;
int main (void)
{
INT8U err;
OSInit(); /* Initialize uC/OS-II */
timer0_init();
KeyLedInit();
uart0_init();
init_irq();
OSTaskCreate(TaskLed,
(void *)1, // pdata = 1
&TaskLedStk[0][TASK_STK_SIZE - 1],
0 // Task priority = 0
);
OSTaskCreate(TaskLed,
(void *)2, // pdata = 2
&TaskLedStk[1][TASK_STK_SIZE - 1],
1 // Task priority = 0
);
OSTaskCreate(TaskLed,
(void *)4, // pdata = 4
&TaskLedStk[2][TASK_STK_SIZE - 1],
2 // Task priority = 2
);
// OSTaskCreate(TaskKey,
// (void *)3,
// &TaskKeyStk[TASK_STK_SIZE - 1],
// 0 /* Task priority = 3 */
// );
MyFlag = OSFlagCreate(0,&err);
OSStart(); /* Start multitasking */
return 0;
}
/*
*********************************************************************************************************
* TASK
*********************************************************************************************************
*/
void TaskLed (void *pdata)
{
INT8U err;
OS_FLAGS flag;
flag = (OS_FLAGS)pdata;
for (;;) {
OSFlagPend(MyFlag, flag, OS_FLAG_CONSUME|OS_FLAG_WAIT_SET_ALL, 0, &err);
LightOn(flag);
OSTimeDly(3*OS_TICKS_PER_SEC);
LightOff(flag);
}
}
/*
*********************************************************************************************************
* TASKS
*********************************************************************************************************
*/
// void TaskKey (void *pdata)
// {
// INT8U err,KeyValue,KeyState;
// pdata = pdata; /* Prevent compiler warning */
// timer0_enable();
// KeyState = 0;
// while(1)
// {
// KeyValue = KeyGet();
// if(KeyValue)
// {
// if(KeyState == 0){
// KeyState = KeyValue;
// OSFlagPost(MyFlag,KeyValue,OS_FLAG_SET,&err);
// }
// }
// else
// KeyState = 0;
// OSTimeDly(OS_TICKS_PER_SEC/20);
// }
// }