/* ********************************************************************************************************* * CREATE TASKS ********************************************************************************************************* */
static void TaskStartCreateTasks (void) { OSTaskCreateExt(TaskClk, (void *)0, &TaskClkStk[TASK_STK_SIZE - 1], TASK_CLK_PRIO, TASK_CLK_ID, &TaskClkStk[0], TASK_STK_SIZE, (void *)0, OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreateExt(Task1, (void *)0, &Task1Stk[TASK_STK_SIZE - 1], TASK_1_PRIO, TASK_1_ID, &Task1Stk[0], TASK_STK_SIZE, (void *)0, OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreateExt(Task2, (void *)0, &Task2Stk[TASK_STK_SIZE - 1], TASK_2_PRIO, TASK_2_ID, &Task2Stk[0], TASK_STK_SIZE, (void *)0, OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreateExt(Task3, (void *)0, &Task3Stk[TASK_STK_SIZE - 1], TASK_3_PRIO, TASK_3_ID, &Task3Stk[0], TASK_STK_SIZE, (void *)0, OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreateExt(Task4, (void *)0, &Task4Stk[TASK_STK_SIZE-1], TASK_4_PRIO, TASK_4_ID, &Task4Stk[0], TASK_STK_SIZE, (void *)0, OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreateExt(Task5, (void *)0, &Task5Stk[TASK_STK_SIZE-1], TASK_5_PRIO, TASK_5_ID, &Task5Stk[0], TASK_STK_SIZE, (void *)0, OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); }
/*$PAGE*/ /* ********************************************************************************************************* * TASK #1 * * Description: This task executes every 100 mS and measures the time it task to perform stack checking * for each of the 5 application tasks. Also, this task displays the statistics related to * each task's stack usage. ********************************************************************************************************* */
void Task1 (void *pdata) { INT8U err; OS_STK_DATA data; /* Storage for task stack data */ INT16U time; /* Execution time (in uS) */ INT8U i; char s[80];
pdata = pdata; for (;;) { for (i = 0; i < 7; i++) { PC_ElapsedStart(); err = OSTaskStkChk(TASK_START_PRIO+i, &data); time = PC_ElapsedStop(); if (err == OS_NO_ERR) { sprintf(s, "%4ld %4ld %4ld %6d", data.OSFree + data.OSUsed, data.OSFree, data.OSUsed, time); PC_DispStr(19, 12+i, s, DISP_FGND_YELLOW); } } OSTimeDlyHMSM(0, 0, 0, 100); /* Delay for 100 mS */ } } /*$PAGE*/ /* ********************************************************************************************************* * TASK #2 * * Description: This task displays a clockwise rotating wheel on the screen. ********************************************************************************************************* */
void Task2 (void *data) { data = data; for (;;) { PC_DispChar(70, 15, '|', DISP_FGND_WHITE + DISP_BGND_RED); OSTimeDly(10); PC_DispChar(70, 15, '/', DISP_FGND_WHITE + DISP_BGND_RED); OSTimeDly(10); PC_DispChar(70, 15, '-', DISP_FGND_WHITE + DISP_BGND_RED); OSTimeDly(10); PC_DispChar(70, 15, '\\', DISP_FGND_WHITE + DISP_BGND_RED); OSTimeDly(10); } } /*$PAGE*/ /* ********************************************************************************************************* * TASK #3 * * Description: This task displays a counter-clockwise rotating wheel on the screen. * * Note(s) : I allocated 100 bytes of storage on the stack to artificially 'eat' up stack space. ********************************************************************************************************* */
void Task3 (void *data) { char dummy[500]; INT16U i;
data = data; for (i = 0; i < 499; i++) { /* Use up the stack with 'junk' */ dummy = '?'; } for (;;) { PC_DispChar(70, 16, '|', DISP_FGND_WHITE + DISP_BGND_BLUE); OSTimeDly(20); PC_DispChar(70, 16, '\\', DISP_FGND_WHITE + DISP_BGND_BLUE); OSTimeDly(20); PC_DispChar(70, 16, '-', DISP_FGND_WHITE + DISP_BGND_BLUE); OSTimeDly(20); PC_DispChar(70, 16, '/', DISP_FGND_WHITE + DISP_BGND_BLUE); OSTimeDly(20); } } /*$PAGE*/ /* ********************************************************************************************************* * TASK #4 * * Description: This task sends a message to Task #5. The message consist of a character that needs to * be displayed by Task #5. This task then waits for an acknowledgement from Task #5 * indicating that the message has been displayed. ********************************************************************************************************* */
void Task4 (void *data) { char txmsg; /*这儿为什么用char来定义数据类型呢?*/ INT8U err;
data = data; txmsg = 'A'; for (;;) { while (txmsg <= 'Z') { OSMboxPost(TxMbox, (void *)&txmsg); /* Send message to Task #5 */ OSMboxPend(AckMbox, 0, &err); /* Wait for acknowledgement from Task #5 */ txmsg++; /* Next message to send */ } txmsg = 'A'; /* Start new series of messages */ } } /*$PAGE*/
|