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