/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* EXAMPLE #3
*********************************************************************************************************
*/
#include "includes.h"
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define TASK_STK_SIZE 512 /* Size of each task‘s stacks (# of WORDs) */
#define TASK_START_ID 0 /* Application tasks */
#define TASK_CLK_ID 1
#define TASK_1_ID 2
#define TASK_2_ID 3
#define TASK_3_ID 4
#define TASK_4_ID 5
#define TASK_5_ID 6
#define TASK_6_ID 7
#define TASK_7_ID 8
#define TASK_8_ID 9
#define TASK_9_ID 10
#define TASK_START_PRIO 10 /* Application tasks priorities */
#define TASK_CLK_PRIO 11
#define TASK_1_PRIO 12
#define TASK_2_PRIO 13
#define TASK_3_PRIO 14
#define TASK_4_PRIO 15
#define TASK_5_PRIO 16
#define TASK_6_PRIO 17
#define TASK_7_PRIO 18
#define TASK_8_PRIO 19
#define TASK_9_PRIO 20
#define MSG_QUEUE_SIZE 20 /* Size of message queue used in example */
#define OSSemquery_en 1
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef struct {
char TaskName[30];
INT16U TaskCtr;
INT16U TaskExecTime;
INT32U TaskTotExecTime;
} TASK_USER_DATA;
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK TaskStartStk[TASK_STK_SIZE]; /* Startup task stack */
OS_STK TaskClkStk[TASK_STK_SIZE]; /* Clock task stack */
OS_STK Task1Stk[TASK_STK_SIZE]; /* Task #1 task stack */
OS_STK Task2Stk[TASK_STK_SIZE]; /* Task #2 task stack */
OS_STK Task3Stk[TASK_STK_SIZE]; /* Task #3 task stack */
OS_STK Task4Stk[TASK_STK_SIZE]; /* Task #4 task stack */
OS_STK Task5Stk[TASK_STK_SIZE]; /* Task #5 task stack */
OS_STK Task6Stk[TASK_STK_SIZE]; /* Task #6 task stack */
OS_STK Task7Stk[TASK_STK_SIZE]; /* Task #7 task stack */
OS_STK Task8Stk[TASK_STK_SIZE]; /* Task #8 task stack */
OS_STK Task9Stk[TASK_STK_SIZE]; /* Task #9 task stack */
TASK_USER_DATA TaskUserData[11];
OS_EVENT *MsgQueue,*SEMaphore; /* Message queue pointer */
void *MsgQueueTbl[20]; /* Storage for messages */
INT8U sem_debuger;
INT8U str[10];
INT8U readywait[64];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void TaskStart(void *data); /* Function prototypes of tasks */
static void TaskStartCreateTasks(void);
static void TaskStartDispInit(void);
static void TaskStartDisp(void);
void TaskClk(void *data);
void Task1(void *data);
void Task2(void *data);
void Task3(void *data);
void Task4(void *data);
void Task5(void *data);
void DispTaskStat(INT8U id);
void Task6(void *data);
void Task7(void *data);
void Task8(void *data);
void Task9(void *data);
void OS_SCHED_HOOK(void);
#if OSSemquery_en>0
void OSSemquery_HOOK(OS_EVENT *pevent,INT8U semaphore_data);
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
void main (void)
{
PC_DispClrScr(DISP_BGND_BLACK); /* Clear the screen */
OSInit(); /* Initialize uC/OS-II */
PC_DOSSaveReturn(); /* Save environment to return to DOS */
PC_VectSet(uCOS, OSCtxSw); /* Install uC/OS-II‘s context switch vector */
PC_ElapsedInit(); /* Initialized elapsed time measurement */
strcpy(TaskUserData[TASK_START_ID].TaskName, "StartTask");
OSTaskCreateExt(TaskStart,
(void *)0,
&TaskStartStk[TASK_STK_SIZE - 1],
TASK_START_PRIO,
TASK_START_ID,
&TaskStartStk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_START_ID],
0);
OSStart(); /* Start multitasking */
}
/*$PAGE*/
/*
*********************************************************************************************************
* STARTUP TASK
*********************************************************************************************************
*/
void TaskStart (void *pdata)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT16S key;
pdata = pdata; /* Prevent compiler warning */
TaskStartDispInit(); /* Setup the display */
OS_ENTER_CRITICAL(); /* Install uC/OS-II‘s clock tick ISR */
PC_VectSet(0x08, OSTickISR);
PC_SetTickRate(OS_TICKS_PER_SEC); /* Reprogram tick rate */
OS_EXIT_CRITICAL();
OSStatInit(); /* Initialize uC/OS-II‘s statistics */
MsgQueue = OSQCreate(&MsgQueueTbl[0], MSG_QUEUE_SIZE); /* Create a message queue */
SEMaphore=OSSemCreate(2);
TaskStartCreateTasks();
for (;;) {
TaskStartDisp(); /* Update the display */
if (PC_GetKey(&key)) { /* See if key has been pressed */
if (key == 0x1B) { /* Yes, see if it‘s the ESCAPE key */
PC_DOSReturn(); /* Yes, return to DOS */
}
}
OSCtxSwCtr = 0; /* Clear the context switch counter */
OSTimeDly(OS_TICKS_PER_SEC); /* Wait one second */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*********************************************************************************************************
*/
void TaskStartCreateTasks (void)
{
strcpy(TaskUserData[TASK_CLK_ID].TaskName, "Clock Task");
OSTaskCreateExt(TaskClk,
(void *)0,
&TaskClkStk[TASK_STK_SIZE - 1],
TASK_CLK_PRIO,
TASK_CLK_ID,
&TaskClkStk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_CLK_ID],
0);
strcpy(TaskUserData[TASK_1_ID].TaskName, "MsgQ Rx Task");
OSTaskCreateExt(Task1,
(void *)0,
&Task1Stk[TASK_STK_SIZE - 1],
TASK_1_PRIO,
TASK_1_ID,
&Task1Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_1_ID],
0);
strcpy(TaskUserData[TASK_2_ID].TaskName, "MsgQ Tx Task #2");
OSTaskCreateExt(Task2,
(void *)0,
&Task2Stk[TASK_STK_SIZE - 1],
TASK_2_PRIO,
TASK_2_ID,
&Task2Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_2_ID],
0);
strcpy(TaskUserData[TASK_3_ID].TaskName, "MsgQ Tx Task #3");
OSTaskCreateExt(Task3,
(void *)0,
&Task3Stk[TASK_STK_SIZE - 1],
TASK_3_PRIO,
TASK_3_ID,
&Task3Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_3_ID],
0);
strcpy(TaskUserData[TASK_4_ID].TaskName, "MsgQ Tx Task #4");
OSTaskCreateExt(Task4,
(void *)0,
&Task4Stk[TASK_STK_SIZE - 1],
TASK_4_PRIO,
TASK_4_ID,
&Task4Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_4_ID],
0);
strcpy(TaskUserData[TASK_5_ID].TaskName, "TimeDlyTask");
OSTaskCreateExt(Task5,
(void *)0,
&Task5Stk[TASK_STK_SIZE - 1],
TASK_5_PRIO,
TASK_5_ID,
&Task5Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_5_ID],
0);
strcpy(TaskUserData[TASK_6_ID].TaskName, "Task6");
OSTaskCreateExt(Task6,
(void *)0,
&Task6Stk[TASK_STK_SIZE - 1],
TASK_6_PRIO,
TASK_6_ID,
&Task6Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_6_ID],
0);
strcpy(TaskUserData[TASK_7_ID].TaskName, "Task7");
OSTaskCreateExt(Task7,
(void *)0,
&Task7Stk[TASK_STK_SIZE - 1],
TASK_7_PRIO,
TASK_7_ID,
&Task7Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_7_ID],
0);
strcpy(TaskUserData[TASK_8_ID].TaskName, "Task8");
OSTaskCreateExt(Task8,
(void *)0,
&Task8Stk[TASK_STK_SIZE - 1],
TASK_8_PRIO,
TASK_8_ID,
&Task8Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_8_ID],
0);
strcpy(TaskUserData[TASK_9_ID].TaskName, "Task9");
OSTaskCreateExt(Task9,
(void *)0,
&Task9Stk[TASK_STK_SIZE - 1],
TASK_9_PRIO,
TASK_9_ID,
&Task9Stk[0],
TASK_STK_SIZE,
&TaskUserData[TASK_9_ID],
0);
}
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE THE DISPLAY
*********************************************************************************************************
*/
static void TaskStartDispInit (void)
{
/* 1111111111222222222233333333334444444444555555555566666666667777777777 */
/* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */
PC_DispStr( 0, 0, " uC/OS-II, The Real-Time Kernel ", DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);
PC_DispStr( 0, 1, " Jean J. Labrosse ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 2, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 3, " EXAMPLE #3 ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 9, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 10, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 6, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 7, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 8, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 4, "Task Name Counter Exec.Time(uS) Tot.Exec.Time(uS) %Tot. ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 5, "----------------- ------- ------------- ----------------- ----- ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 11, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 12, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 13, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 14, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 15, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 16, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 17, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 18, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 19, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 20, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 21, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 22, "#Tasks : CPU Usage: % ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 23, "#Task switch/sec: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 24, " <-PRESS ‘ESC‘ TO QUIT-> ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY + DISP_BLINK);
PC_DispStr( 0, 25, "--------------------------------Tasks osched------------------------------------", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 26, "#Current Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 27, "#Be going to Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 28, "Task execute order: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 29, "#post Message Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 30, "#Waiting Message Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 31, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 32, "#post Message queue Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 33, "#Waiting Message queue Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 34, "#Waiting semaphore Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 35, "#semaphore value: #resource: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 36, "#posting semaphore Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 37, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 38, "#Waiting MUTUAL semaphore Task: ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 39, "#waiting tasks queue: ", DISP_FGND_BLACK +DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 40, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 41, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 42, " ", DISP_FGND_BLACK +DISP_BGND_RED);
/* 1111111111222222222233333333334444444444555555555566666666667777777777 */
/* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */
}
/*$PAGE*/%C
/*
*********************************************************************************************************
* UPDATE THE DISPLAY
*********************************************************************************************************
*/
static void TaskStartDisp (void)
{
char s[80];
sprintf(s, "%5d", OSTaskCtr); /* Display #tasks running */
PC_DispStr(18, 22, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
#if OS_TASK_STAT_EN > 0
sprintf(s, "%3d", OSCPUUsage); /* Display CPU usage in % */
PC_DispStr(36, 22, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
#endif
sprintf(s, "%5d", OSCtxSwCtr); /* Display #context switches per second */
PC_DispStr(18, 23, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
sprintf(s, "V%1d.%02d", OSVersion() / 100, OSVersion() % 100); /* Display uC/OS-II‘s version number */
PC_DispStr(75, 24, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
switch (_8087) { /* Display whether FPU present */
case 0:
&
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。