UCOS_TI_LM3S_Keil
 全部 结构体 文件 函数 变量 类型定义 宏定义 
app.c
浏览该文件的文档.
1 /*
2 *********************************************************************************************************
3 * EXAMPLE CODE
4 *
5 * (c) Copyright 2009; Micrium, Inc.; Weston, FL
6 *
7 * All rights reserved. Protected by international copyright laws.
8 * Knowledge of the source code may not be used to write a similar
9 * product. This file may only be used in accordance with a license
10 * and should not be redistributed in any way.
11 *********************************************************************************************************
12 */
13 
14 /*
15 *********************************************************************************************************
16 *
17 * EXAMPLE CODE
18 *
19 * LUMINARY MICRO LM3S1968 on the EK-LM3S1968
20 *
21 * Filename : app.c
22 * Version : V1.02
23 * Programmer(s) : BAN
24 *********************************************************************************************************
25 */
26 
27 
28 /*
29 *********************************************************************************************************
30 * INCLUDE FILES
31 *********************************************************************************************************
32 */
33 
34 #include <includes.h>
35 
36 
37 /*
38 *********************************************************************************************************
39 * LOCAL DEFINES
40 *********************************************************************************************************
41 */
42 
43 #define APP_LCD_ROW0_Y 0x00u
44 #define APP_LCD_ROW0_5_Y 0x08u
45 #define APP_LCD_ROW1_Y 0x10u
46 #define APP_LCD_ROW1_5_Y 0x18u
47 #define APP_LCD_ROW2_Y 0x20u
48 #define APP_LCD_ROW2_5_Y 0x28u
49 #define APP_LCD_ROW3_Y 0x30u
50 #define APP_LCD_ROW3_5_Y 0x38u
51 #define APP_LCD_ROW4_Y 0x40u
52 #define APP_LCD_ROW4_5_Y 0x48u
53 #define APP_LCD_ROW5_Y 0x50u
54 #define APP_LCD_ROW5_5_Y 0x58u
55 
56 #define APP_USER_IF_MAX 4u
57 
58 
59 /*
60 *********************************************************************************************************
61 * LOCAL GLOBAL VARIABLES
62 *********************************************************************************************************
63 */
64 
68 
76 
82 
88 
89 
90 /*
91 *********************************************************************************************************
92 * LOCAL MACRO'S
93 *********************************************************************************************************
94 */
95 
96 #define APP_TASK_STOP(); { while (DEF_ON) { \
97  ; \
98  } \
99  }
100 
101 
102 #define APP_TEST_ERR(err_var, err_code) { if ((err_var) != (err_code)) { \
103  APP_TRACE_DBG((" %s() error #%05d @ line #%05d\n\r", __func__, (err_var), __LINE__)); \
104  } \
105  }
106 
107 #define APP_TEST_FAULT(err_var, err_code) { APP_TEST_ERR(err_var, err_code); \
108  if ((err_var) != (err_code)) { \
109  APP_TASK_STOP(); \
110  } \
111  }
112 
113 
114 /*
115 *********************************************************************************************************
116 * LOCAL FUNCTION PROTOTYPES
117 *********************************************************************************************************
118 */
119 
120 static void App_TaskStart (void *p_arg);
121 static void App_TaskCreate (void);
122 static void App_EventCreate (void);
123 
124 static void App_TaskKbd (void *p_arg);
125 static void App_TaskUserIF (void *p_arg);
126 
127 static void App_DispScr_SignOn (void);
128 static void App_DispScr_VersionTickRateCPU(void);
129 static void App_DispScr_CtxSw (void);
130 static void App_DispScr_Inputs (void);
131 
132 
133 /*
134 *********************************************************************************************************
135 * LOCAL CONFIGURATION ERRORS
136 *********************************************************************************************************
137 */
138 
139 
140 /*
141 *********************************************************************************************************
142 * main()
143 *
144 * Description : This is the standard entry point for C code. It is assumed that your code will call
145 * main() once you have performed all necessary initialization.
146 *
147 * Argument(s) : none.
148 *
149 * Return(s) : none.
150 *********************************************************************************************************
151 */
152 
153 int main (void)
154 {
155  INT8U os_err;
156 #if (CPU_CFG_NAME_EN == DEF_ENABLED)
157  CPU_ERR cpu_err;
158 #endif
159 
160 
161  BSP_IntDisAll(); /* Disable all ints until we are ready to accept them. */
162 
163  BSP_Init(); /* Initialize BSP. */
164  CPU_Init(); /* Initialize CPU. */
165 #if (CPU_CFG_NAME_EN == DEF_ENABLED)
166  CPU_NameSet("LM3S1968", &cpu_err);
167 #endif
168 
169  OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel". */
170 
171  os_err = OSTaskCreateExt((void (*)(void *)) App_TaskStart, /* Create the start task. */
172  (void * ) 0,
175  (INT16U ) APP_TASK_START_PRIO,
176  (OS_STK * )&App_TaskStartStk[0],
178  (void * )0,
180 
181  APP_TEST_FAULT(os_err, OS_ERR_NONE);
182 
183 #if (OS_TASK_NAME_EN > 0)
184  OSTaskNameSet(APP_TASK_START_PRIO, (INT8U *)"Start Task", &os_err);
185 #endif
186 
187  OSStart(); /* Start multitasking (i.e. give control to uC/OS-II). */
188 
189  return (0);
190 }
191 
192 
193 /*
194 *********************************************************************************************************
195 * App_TaskStart()
196 *
197 * Description : The startup task. The uC/OS-II ticker should only be initialize once multitasking starts.
198 *
199 * Argument(s) : p_arg Argument passed to 'App_TaskStart()' by 'OSTaskCreate()'.
200 *
201 * Return(s) : none.
202 *
203 * Caller(s) : This is a task.
204 *
205 * Note(s) : none.
206 *********************************************************************************************************
207 */
208 
209 static void App_TaskStart (void *p_arg)
210 {
211  CPU_INT32U cnts;
212 
213 
214  (void)p_arg; /* Prevent compiler warning. */
215 
216 
217  /* ------------------- INIT MODULES ------------------- */
219  OS_CPU_SysTickInit(cnts); /* Initialize the SysTick. */
220 
221  Mem_Init(); /* Initialize mem mgmt module. */
222  Math_Init(); /* Initialize math module. */
223 
224 #if (OS_TASK_STAT_EN > 0)
225  OSStatInit(); /* Determine CPU capacity. */
226 #endif
227 
228  BSP_SerInit(BSP_SER_ID_UART0, 115200u);
229 
230 
231 
232  /* --------------------- INIT APP --------------------- */
233  App_EventCreate(); /* Create application events. */
234  App_TaskCreate(); /* Create application tasks. */
235 
236 
237 
238  /* -------------------- START TASK -------------------- */
239  while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
240  BSP_LED_Toggle(1);
242  }
243 }
244 
245 
246 /*
247 *********************************************************************************************************
248 * App_EventCreate()
249 *
250 * Description : Create the application events.
251 *
252 * Argument(s) : none.
253 *
254 * Return(s) : none.
255 *
256 * Caller(s) : App_TaskStart().
257 *
258 * Note(s) : none.
259 *********************************************************************************************************
260 */
261 
262 static void App_EventCreate (void)
263 {
264 #if (OS_EVENT_NAME_EN > 0)
265  INT8U os_err;
266 #endif
267 
268 
269  App_UserIFMbox = OSMboxCreate((void *)0); /* Create MBOX for communication between Kbd and UserIF.*/
270 
271  if (App_UserIFMbox == (OS_EVENT *)0) {
272  APP_TASK_STOP();
273  }
274 
275 #if (OS_EVENT_NAME_EN > 0)
276  OSEventNameSet(App_UserIFMbox, "User IF Mbox", &os_err);
277 #endif
278 }
279 
280 
281 /*
282 *********************************************************************************************************
283 * App_TaskCreate()
284 *
285 * Description : Create the application tasks.
286 *
287 * Argument(s) : none.
288 *
289 * Return(s) : none.
290 *
291 * Caller(s) : App_TaskStart().
292 *
293 * Note(s) : none.
294 *********************************************************************************************************
295 */
296 
297 static void App_TaskCreate (void)
298 {
299  INT8U os_err;
300 
301 
302  /* ---------------- CREATE USER IF TASK --------------- */
303  os_err = OSTaskCreateExt((void (*)(void *)) App_TaskUserIF,
304  (void * ) 0,
307  (INT16U ) APP_TASK_USER_IF_PRIO,
308  (OS_STK * )&App_TaskUserIFStk[0],
310  (void * ) 0,
312 
313  APP_TEST_FAULT(os_err, OS_ERR_NONE);
314 
315 #if (OS_TASK_NAME_EN > 0)
316  OSTaskNameSet(APP_TASK_USER_IF_PRIO, (INT8U *)"User IF", &os_err);
317 #endif
318 
319 
320 
321  /* ------------------ CREATE KBD TASK ----------------- */
322  os_err = OSTaskCreateExt((void (*)(void *)) App_TaskKbd,
323  (void * ) 0,
326  (INT16U ) APP_TASK_KBD_PRIO,
327  (OS_STK * )&App_TaskKbdStk[0],
329  (void * ) 0,
331 
332  APP_TEST_FAULT(os_err, OS_ERR_NONE);
333 
334 #if (OS_TASK_NAME_EN > 0)
335  OSTaskNameSet(APP_TASK_KBD_PRIO, (INT8U *)"Kbd", &os_err);
336 #endif
337 }
338 
339 
340 /*
341 *********************************************************************************************************
342 * App_TaskKbd()
343 *
344 * Description : Monitor the state of the push buttons and passes messages to AppTaskUserIF()
345 *
346 * Argument(s) : p_arg Argument passed to 'AppTaskKbd()' by 'OSTaskCreate()'.
347 *
348 * Return(s) : none.
349 *
350 * Caller(s) : This is a task.
351 *
352 * Note(s) : none.
353 *********************************************************************************************************
354 */
355 static void App_TaskKbd (void *p_arg)
356 {
357  CPU_BOOLEAN b1_prev;
358  CPU_BOOLEAN b2_prev;
359  CPU_BOOLEAN b3_prev;
360  CPU_BOOLEAN b4_prev;
361  CPU_BOOLEAN b5_prev;
362  CPU_INT08U key;
363 
364 
365  (void)p_arg;
366 
367  key = 2u;
368 
369  b1_prev = DEF_FALSE;
370  b2_prev = DEF_FALSE;
371  b3_prev = DEF_FALSE;
372  b4_prev = DEF_FALSE;
373  b5_prev = DEF_FALSE;
374 
375  App_B1 = DEF_FALSE;
376  App_B2 = DEF_FALSE;
377  App_B3 = DEF_FALSE;
378  App_B4 = DEF_FALSE;
379  App_B5 = DEF_FALSE;
380 
381  while (DEF_TRUE) {
387 
388  if ((App_B1 == DEF_TRUE) && (b1_prev == DEF_FALSE)) {
389  App_B1Counts++;
390 
391  if (key == APP_USER_IF_MAX) {
392  key = 1;
393  } else {
394  key++;
395  }
396  OSMboxPost(App_UserIFMbox, (void *)key);
397  }
398 
399  if ((App_B2 == DEF_TRUE) && (b2_prev == DEF_FALSE)) {
400  App_B2Counts++;
401  }
402 
403  if ((App_B3 == DEF_TRUE) && (b3_prev == DEF_FALSE)) {
404  App_B3Counts++;
405  }
406 
407  if ((App_B4 == DEF_TRUE) && (b4_prev == DEF_FALSE)) {
408  App_B4Counts++;
409  }
410 
411  if ((App_B5 == DEF_TRUE) && (b5_prev == DEF_FALSE)) {
412  App_B5Counts++;
413  }
414 
415  b1_prev = App_B1;
416  b2_prev = App_B2;
417  b3_prev = App_B3;
418  b4_prev = App_B4;
419  b5_prev = App_B5;
421  }
422 }
423 
424 
425 /*
426 *********************************************************************************************************
427 * App_TaskUserIF()
428 *
429 * Description : Updates LCD.
430 *
431 * Argument(s) : p_arg Argument passed to 'AppTaskUserIF()' by 'OSTaskCreate()'.
432 *
433 * Return(s) : none.
434 *
435 * Caller(s) : This is a task.
436 *
437 * Note(s) : none.
438 *********************************************************************************************************
439 */
440 
441 static void App_TaskUserIF (void *p_arg)
442 {
443  CPU_INT08U *msg;
444  CPU_INT08U err;
445  CPU_INT32U nstate;
446  CPU_INT32U pstate;
447 
448 
449  (void)p_arg;
450 
453  pstate = 1;
454  nstate = 2;
455 
456 
457  while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
458  msg = (CPU_INT08U *)(OSMboxPend(App_UserIFMbox, OS_TICKS_PER_SEC / 10, &err));
459  if (err == OS_ERR_NONE) {
460  nstate = (CPU_INT32U)msg;
461  }
462 
463  if (nstate != pstate) {
464  RIT128x96x4Clear();
465  pstate = nstate;
466  }
467 
468  switch (nstate) {
469  case 2:
471  break;
472 
473  case 3:
475  break;
476 
477  case 4:
479  break;
480 
481  case 1:
482  default:
484  break;
485  }
486  }
487 }
488 
489 
490 /*
491 *********************************************************************************************************
492 * DISPLAY SCREENS
493 *
494 * Descrition : Display one of the screens used in the demonstration.
495 *
496 * Argument(s) : none.
497 *
498 * Return(s) : none.
499 *
500 * Caller(s) : App_TaskUserIF().
501 *
502 * Note(s) : none.
503 *********************************************************************************************************
504 */
505 
506 static void App_DispScr_SignOn (void)
507 {
508  static CPU_INT08U count = 0;
509 
510 
511  Str_Copy(App_UserIFLine1, " Micrium ");
512  Str_Copy(App_UserIFLine2, "uC/OS-II uC-Probe");
515  Str_Copy(App_UserIFLine5, "on the LuminaryMicro");
516  Str_Copy(App_UserIFLine6, " EK-LM3S1968 ");
517 
518  RIT128x96x4StringDraw((char *)App_UserIFLine1, 0, APP_LCD_ROW0_5_Y, 15);
519  if (count < 5) {
520  RIT128x96x4StringDraw("uC/OS-II", 0, APP_LCD_ROW1_5_Y, 15);
521  RIT128x96x4StringDraw("uC/Probe", 72, APP_LCD_ROW1_5_Y, 10);
522  } else if (count < 10) {
523  RIT128x96x4StringDraw("uC/OS-II", 0, APP_LCD_ROW1_5_Y, 10);
524  RIT128x96x4StringDraw("uC/Probe", 72, APP_LCD_ROW1_5_Y, 15);
525  }
526 
527  count++;
528 
529  if (count >= 10) {
530  count = 0;
531  }
532 
533  RIT128x96x4StringDraw((char *)App_UserIFLine5, 0, APP_LCD_ROW3_5_Y, 5);
534  RIT128x96x4StringDraw((char *)App_UserIFLine6, 0, APP_LCD_ROW4_5_Y, 5);
535  RIT128x96x4LineDraw(0, 0x00, 128, 15, DEF_TRUE);
536  RIT128x96x4LineDraw(0, 0x26, 128, 15, DEF_TRUE);
537 }
538 
540 {
541  CPU_INT32U value;
542 
543 
544  Str_Copy(App_UserIFLine1, " uC/OS-II ");
546 
547  Str_Copy(App_UserIFLine3, " uC/OS-II: Vx.yy ");
548  value = (CPU_INT32U)OSVersion();
549  App_UserIFLine3[14] = ((value % 1000) / 100) + '0';
550  App_UserIFLine3[16] = ((value % 100) / 10) + '0';
551  App_UserIFLine3[17] = ((value % 10) / 1) + '0';
552 
553  Str_Copy(App_UserIFLine4, " TickRate: xxxx Hz");
554  value = (CPU_INT32U)OS_TICKS_PER_SEC;
556 
557  Str_Copy(App_UserIFLine5, " CPU Usage: xxx % ");
558  value = (CPU_INT32U)OSCPUUsage;
559  App_UserIFLine5[13] = ((value % 1000) / 100) + '0';
560  App_UserIFLine5[14] = ((value % 100) / 10) + '0';
561  App_UserIFLine5[15] = ((value % 10) / 1) + '0';
562 
563  Str_Copy(App_UserIFLine6, " CPU Speed: xx MHz ");
564  value = (CPU_INT32U)SysCtlClockGet() / 1000000L;
565  App_UserIFLine6[13] = (value / 10) + '0';
566  App_UserIFLine6[14] = (value % 10) + '0';
567 
568  RIT128x96x4StringDraw((char *)App_UserIFLine1, 0, APP_LCD_ROW0_5_Y, 15);
569  RIT128x96x4StringDraw((char *)App_UserIFLine3, 0, APP_LCD_ROW2_Y, 5);
570  RIT128x96x4StringDraw((char *)App_UserIFLine4, 0, APP_LCD_ROW3_Y, 8);
571  RIT128x96x4StringDraw((char *)App_UserIFLine5, 0, APP_LCD_ROW4_Y, 5);
572  RIT128x96x4StringDraw((char *)App_UserIFLine6, 0, APP_LCD_ROW5_Y, 8);
573 
574  RIT128x96x4LineDraw(0, 0x00, 128, 15, DEF_TRUE);
575  RIT128x96x4LineDraw(0, 0x16, 128, 15, DEF_TRUE);
576 }
577 
578 
579 static void App_DispScr_CtxSw (void)
580 {
581  CPU_INT32U value;
582 
583 
584  Str_Copy(App_UserIFLine1, " uC/OS-II ");
586 
587  Str_Copy(App_UserIFLine3, " Number of Ticks: ");
588 
589  Str_Copy(App_UserIFLine4, " xxxxxxxx ");
590  value = (CPU_INT32U)OSTime;
592 
593  Str_Copy(App_UserIFLine5, "Num. of Context Sw.:");
594 
595  Str_Copy(App_UserIFLine6, " xxxxxxxx ");
596  value = (CPU_INT32U)OSCtxSwCtr;
598 
599  RIT128x96x4StringDraw((char *)App_UserIFLine1, 0, APP_LCD_ROW0_5_Y, 15);
600  RIT128x96x4StringDraw((char *)App_UserIFLine3, 0, APP_LCD_ROW2_Y, 8);
601  RIT128x96x4StringDraw((char *)App_UserIFLine4, 0, APP_LCD_ROW3_Y, 5);
602  RIT128x96x4StringDraw((char *)App_UserIFLine5, 0, APP_LCD_ROW4_Y, 8);
603  RIT128x96x4StringDraw((char *)App_UserIFLine6, 0, APP_LCD_ROW5_Y, 5);
604 
605  RIT128x96x4LineDraw(0, 0x00, 128, 15, DEF_TRUE);
606  RIT128x96x4LineDraw(0, 0x16, 128, 15, DEF_TRUE);
607 }
608 
609 
610 static void App_DispScr_Inputs (void)
611 {
612  CPU_INT32U value;
613  CPU_CHAR str[4];
614 
615 
616  Str_Copy(App_UserIFLine1, " Board Inputs ");
618 
619  Str_Copy(App_UserIFLine3, " Button Status: ");
620 
621  Str_Copy(App_UserIFLine4, " xxx ");
622  value = (CPU_INT32U)App_B2Counts;
624 
625  Str_Copy(App_UserIFLine5, " yyy xxx zzz ");
626  value = (CPU_INT32U)App_B4Counts;
628  value = (CPU_INT32U)App_B1Counts;
630  value = (CPU_INT32U)App_B5Counts;
632 
633  Str_Copy(App_UserIFLine6, " xxx ");
634  value = (CPU_INT32U)App_B3Counts;
636 
637  RIT128x96x4StringDraw((char *)App_UserIFLine1, 0, APP_LCD_ROW0_5_Y, 15);
638  RIT128x96x4StringDraw((char *)App_UserIFLine3, 0, APP_LCD_ROW2_Y, 8);
639 
640  if (App_B2 == DEF_TRUE) {
641  RIT128x96x4StringDraw((char *)App_UserIFLine4, 0, APP_LCD_ROW3_Y, 8);
642  } else {
643  RIT128x96x4StringDraw((char *)App_UserIFLine4, 0, APP_LCD_ROW3_Y, 2);
644  }
645 
646  Str_Copy(str, " ");
647  value = (CPU_INT32U)App_B4Counts;
648  Str_FmtNbr_Int32U(value, 3, 10, ASCII_CHAR_SPACE, DEF_FALSE, DEF_FALSE, &str[0]);
649 
650  if (App_B4 == DEF_TRUE) {
651  RIT128x96x4StringDraw((char *)str, 6 * 3, APP_LCD_ROW4_Y, 8);
652  } else {
653  RIT128x96x4StringDraw((char *)str, 6 * 3, APP_LCD_ROW4_Y, 2);
654  }
655 
656  Str_Copy(str, " ");
657  value = (CPU_INT32U)App_B1Counts;
658  Str_FmtNbr_Int32U(value, 3, 10, ASCII_CHAR_SPACE, DEF_FALSE, DEF_FALSE, &str[0]);
659 
660  if (App_B1 == DEF_TRUE) {
661  RIT128x96x4StringDraw((char *)str, 6 * 9, APP_LCD_ROW4_Y, 8);
662  } else {
663  RIT128x96x4StringDraw((char *)str, 6 * 9, APP_LCD_ROW4_Y, 2);
664  }
665 
666  Str_Copy(str, " ");
667  value = (CPU_INT32U)App_B5Counts;
668  Str_FmtNbr_Int32U(value, 3, 10, ASCII_CHAR_SPACE, DEF_FALSE, DEF_FALSE, &str[0]);
669 
670  if (App_B5 == DEF_TRUE) {
671  RIT128x96x4StringDraw((char *)str, 6 * 15, APP_LCD_ROW4_Y, 8);
672  } else {
673  RIT128x96x4StringDraw((char *)str, 6 * 15, APP_LCD_ROW4_Y, 2);
674  }
675 
676  if (App_B3 == DEF_TRUE) {
677  RIT128x96x4StringDraw((char *)App_UserIFLine6, 0, APP_LCD_ROW5_Y, 8);
678  } else {
679  RIT128x96x4StringDraw((char *)App_UserIFLine6, 0, APP_LCD_ROW5_Y, 2);
680  }
681 
682  RIT128x96x4LineDraw(0, 0x00, 128, 15, DEF_TRUE);
683  RIT128x96x4LineDraw(0, 0x16, 128, 15, DEF_TRUE);
684 }