1 /*-------------------------------------------------------------------------
2
3 软件主体
4
5
6 -------------------------------------------------------------------------*/
7
8 #include "os.h"
9 #include "kernel.h"
10 #include "config.h"
11
12 extern void SysTickInit(void);
13
14 static OS_TCB taskStartTCB;
15 static CPU_STK startTaskStk[STARTUP_TASK_STK_SIZE]; //启动任务的程序空间
16
17 static OS_TCB task1TCB;
18 static CPU_STK task1_stk[TASK1_STK_SIZE];
19
20 static OS_TCB task2TCB;
21 static CPU_STK task2_stk[TASK2_STK_SIZE];
22
23 static OS_TCB task3TCB;
24 static CPU_STK task3_stk[TASK3_STK_SIZE];
25
26 static volatile OS_SEM taskSem;
27 static volatile OS_ERR err;
28
29 /*******************************************************************************
30 * Function Name :void StartTask(void)
31 * Description :启动任务
32 * Input :
33 * Output :
34 * Other :
35 * Date :2012.04.18 11:48:23
36 *******************************************************************************/
37 void StartTask(void)
38 {
39
40 led_init();
41 SysTickInit();
42
43 OSTaskCreate( (OS_TCB *)&task1TCB,
44 (CPU_CHAR *)"task1",
45 (OS_TASK_PTR)task1,
46 (void *)0,
47 (OS_PRIO )TASK1_PRIO,
48 (CPU_STK *)&task1_stk[0],
49 (CPU_STK_SIZE)TASK1_STK_SIZE / 10,
50 (CPU_STK_SIZE)TASK1_STK_SIZE,
51 (OS_MSG_QTY )0,
52 (OS_TICK )0,
53 (void *)0,
54 (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
55 (OS_ERR *)&err);
56
57 OSTaskCreate( (OS_TCB *)&task2TCB,
58 (CPU_CHAR *)"task2",
59 (OS_TASK_PTR)task2,
60 (void *)0,
61 (OS_PRIO ) TASK2_PRIO,
62 (CPU_STK *)&task2_stk[0],
63 (CPU_STK_SIZE)TASK2_STK_SIZE / 10,
64 (CPU_STK_SIZE)TASK2_STK_SIZE,
65 (OS_MSG_QTY)0,
66 (OS_TICK )0,
67 (void *)0,
68 (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
69 (OS_ERR *)&err);
70
71
72 OSTaskCreate( (OS_TCB *)&task3TCB,
73 (CPU_CHAR *)"task3",
74 (OS_TASK_PTR)task3,
75 (void *)0,
76 (OS_PRIO )TASK3_PRIO,
77 (CPU_STK *)&task3_stk[0],
78 (CPU_STK_SIZE)TASK3_STK_SIZE / 10,
79 (CPU_STK_SIZE)TASK3_STK_SIZE,
80 (OS_MSG_QTY)0,
81 (OS_TICK )0,
82 (void *)0,
83 (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
84 (OS_ERR *)&err);
85
86 OSSemCreate( (OS_SEM *)&taskSem,
87 (CPU_CHAR *)"taskSem",
88 (OS_SEM_CTR)0,
89 (OS_ERR *)err);
90
91 OSTaskDel( (OS_TCB *)&taskStartTCB,
92 (OS_ERR *)&err);
93 }
94
95 static void task1(void *p_arg)
96 {
97
98 while (1)
99 {
100 led_on(LED_4);
101 OSTimeDly( (OS_TICK )200,
102 (OS_OPT )OS_OPT_TIME_DLY,
103 (OS_ERR *)&err);
104
105 led_off(LED_4);
106 OSTimeDly( (OS_TICK )200,
107 (OS_OPT )OS_OPT_TIME_DLY,
108 (OS_ERR *)&err);
109
110 OSSemPost( (OS_SEM *)&taskSem,
111 (OS_OPT )OS_OPT_POST_ALL,
112 (OS_ERR *)&err);
113
114 }
115 }
116
117 static void task2(void *p_arg)
118 {
119 while (1)
120 {
121 led_on(LED_5);
122 OSSemPend( (OS_SEM *)&taskSem,
123 (OS_TICK )10000,
124 (OS_OPT )OS_OPT_PEND_BLOCKING,
125 (CPU_TS *)0,
126 (OS_ERR *)&err);
127
128 led_off(LED_5);
129 OSSemPend( (OS_SEM *)&taskSem,
130 (OS_TICK )10000,
131 (OS_OPT )OS_OPT_PEND_BLOCKING,
132 (CPU_TS *)0,
133 (OS_ERR *)&err);
134
135 }
136 }
137
138 static void task3(void *p_arg)
139 {
140
141 while (1)
142 {
143 led_on(LED_3);
144 OSTimeDly( (OS_TICK )100,
145 (OS_OPT )OS_OPT_TIME_DLY,
146 (OS_ERR *)&err);
147
148 led_off(LED_3);
149 OSTimeDly( (OS_TICK )100,
150 (OS_OPT )OS_OPT_TIME_DLY,
151 (OS_ERR *)&err);
152
153 }
154 }
155
156
157 /*******************************************************************************
158 * Function Name :void KeranlTask(void)
159 * Description :启动任务
160 * Input :
161 * Output :
162 * Other :
163 * Date :2012.04.18 11:05:47
164 *******************************************************************************/
165 void KeranlTask(void)
166 {
167 CPU_Init();
168 OSInit((OS_ERR *)&err);
169
170 OSTaskCreate( (OS_TCB *)&taskStartTCB,
171 (CPU_CHAR *)"task_start",
172 (OS_TASK_PTR)StartTask,
173 (void *)0,
174 (OS_PRIO ) STARTUP_TASK_PRIO,
175 (CPU_STK *)&startTaskStk[0],
176 (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE / 10,
177 (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE,
178 (OS_MSG_QTY)0,
179 (OS_TICK )0,
180 (void *)0,
181 (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
182 (OS_ERR *)&err);
183
184 OSStart((OS_ERR *)&err);
185 }