?? test.c
字號(hào):
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2003, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* EXAMPLE #1
*
* Notes: 1) You can run this code on a PC running DOS 4.xx
* 2) This test file has been tested on the JK Microsystems, Inc. FlashLite-186 board which contains
* contains an Intel 80186 CPU running at 33.33 MHz. The board doesn't come with a VGA display
* controller but you can write to the console port using 'printf' statements. The console
* keyboard simulates a PC's keyboard.
*********************************************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <setjmp.h>
#include <ucos_ii.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define TEST_TASK_STK_SIZE 400 /* Size of each task's stacks (# of WORDs) */
#define TEST_N_TASKS 10 /* Number of identical tasks */
#define VECT_TICK 0x08 /* Vector number for 82C54 timer tick */
#define VECT_DOS_CHAIN 0x81 /* Vector number used to chain DOS */
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK TestStartStk[TEST_TASK_STK_SIZE]; /* Tasks stacks */
OS_STK TestTaskStk[TEST_N_TASKS][TEST_TASK_STK_SIZE];
OS_EVENT *TestRandomSem;
char TestTaskData[TEST_N_TASKS]; /* Parameters to pass to each task */
INT16U TestDly;
INT16U TestLoops;
static BOOLEAN PC_ExitFlag;
static jmp_buf PC_JumpBuf;
void (*PC_TickISR)(void);
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void TestStart(void *p_arg); /* Function prototypes of Startup task */
static void TestTask(void *p_arg);
static void TestCreateTasks(void);
static void TestDisp(void);
static void PC_DOSReturn(void); /* PC related functions */
static void PC_DOSSaveReturn(void);
static BOOLEAN PC_GetKey(INT16S *c);
static void PC_SetTickRate(INT16U freq);
static void *PC_VectGet(INT8U vect);
static void PC_VectSet(INT8U vect, void (*isr)(void));
/*$PAGE*/
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
void main (void)
{
INT8U err;
INT8U prio;
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 */
printf("\n\n");
printf("Micrium, Inc.\n");
printf("uC/OS-II, The Real-Time Kernel\n");
printf("JK microsystems' FlashLite-186 (Large Model)\n\n");
prio = 0;
OSTaskCreateExt(TestStart,
(void *)0,
&TestStartStk[TEST_TASK_STK_SIZE - 1],
prio,
prio,
&TestStartStk[0],
TEST_TASK_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CLR + OS_TASK_OPT_STK_CHK);
OSStart(); /* Start multitasking */
}
/*
*********************************************************************************************************
* STARTUP TASK
*********************************************************************************************************
*/
static void TestStart (void *p_arg)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
char s[100];
INT16S key;
INT16U ctr;
p_arg = p_arg; /* Prevent compiler warning */
OS_ENTER_CRITICAL();
PC_VectSet(0x08, OSTickISR); /* Install uC/OS-II's clock tick ISR */
OS_EXIT_CRITICAL();
printf("Press the +/- keys on the terminal to INC/DEC the Task Execution RATE.\n");
printf("Press the U/D keys on the terminal to INC/DEC the Task Execution TIME.\n");
printf("\n\n");
TestCreateTasks(); /* Create all the application tasks */
TestDly = 100;
TestLoops = 10;
ctr = 0;
while (TRUE) {
if (PC_GetKey(&key) == TRUE) { /* See if key has been pressed */
switch (key) {
case 0x1B: /* See if it's the ESCAPE key */
PC_DOSReturn(); /* Return to DOS */
break;
case '+': /* Increase task execution rate */
case '=':
if (TestDly > 10) {
TestDly -= 5;
} else if (TestDly > 0) {
TestDly--;
}
break;
/* Decrease task execution rate */
case '-':
case '_':
if (TestDly < 10) {
TestDly++;
} else if (TestDly <= 95) {
TestDly += 5;
}
break;
case 'U': /* Increase task execution time */
case 'u':
if (TestLoops <= 990) {
TestLoops += 10;
}
break;
case 'D': /* Decrease task execution time */
case 'd':
if (TestLoops > 10) {
TestLoops -= 10;
}
break;
}
}
printf("%05u #Tasks:%2u Dly:%3u Loops:%3u\n", ctr, OSTaskCtr, TestDly, TestLoops);
ctr++;
OSTimeDly(OS_TICKS_PER_SEC);
}
}
/*$PAGE*/
/*
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -