?? test.c
字號:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-1999, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* V2.00
*
* EXAMPLE #2
*********************************************************************************************************
*/
#include "includes.h"
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define TASK_STK_SIZE 512 /* Size of each task's stacks (# of WORDs) */
#define TASK_START_ID 0 /* Application tasks IDs */
#define TASK_CLK_ID 1
#define TASK_1_ID 2
#define TASK_2_ID 3
#define TASK_START_PRIO 10 /* Application tasks priorities */
#define TASK_CLK_PRIO 11
#define TASK_1_PRIO 12
#define TASK_2_PRIO 13
/*
*********************************************************************************************************
* 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_EVENT *AckMbox; /* Message mailboxes for Tasks #4 and #5 */
OS_EVENT *TxMbox;
OS_FLAG_GRP *StatusFlag;
INT16U TaskFPUFlag;
INT16S key;
int i = 0,
j = 0;
int flag = 0, /* ISR flag */
inpFlag = 0, /* Input Flag */
inpM = 0, /* Input M Value */
inpC = 0, /* Input C Value */
inpK = 0; /* Input K Value */
float PI = 3.14159; /* Radius */
float M = 10, /* Damper Coefficient */
C = 1, /* Mass Of Object */
K = 50, /* Spring Coefficient */
T = 0.005, /* Sampling Time */
Ts = 0.0; /* Total Time */
float x1_k = 0.0, /* x1(k) */
x1_k1 = 0.0, /* x1(k+1) */
x2_k = 0.0, /* x2(k) */
x2_k1 = 0.0, /* x2(k+1) */
f_k = 20.0; /* f(t) */
int counter = 0;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void TaskStart(void *data); /* Function prototypes of tasks */
static void TaskStartCreateTasks(void);
static void TaskStartDispInit(void);
static void TaskStartDisp(void);
static void TestInitModules(void);
void TaskClk(void *data);
void Task1(void *data);
void Task2(void *data);
/*$PAGE*/
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
void main (void)
{
OS_STK *ptos;
OS_STK *pbos;
INT32U size;
INT8U err;
PC_DispClrScr(DISP_FGND_WHITE); /* 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 */
ptos = &TaskStartStk[TASK_STK_SIZE - 1];
pbos = &TaskStartStk[0];
size = TASK_STK_SIZE;
OSTaskStkInit_FPE_x86(&ptos, &pbos, &size); /* TaskStart() will use Floating-Point */
StatusFlag=OSFlagCreate(0x00,&err);
OSTaskCreateExt(TaskStart,
(void *)0,
ptos,
TASK_START_PRIO,
TASK_START_ID,
pbos,
size,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
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
char s[100];
pdata = pdata; /* Prevent compiler warning */
TaskStartDispInit(); /* Initialize the display */
OS_ENTER_CRITICAL();
PC_VectSet(0x08, OSTickISR); /* Install uC/OS-II's clock tick ISR */
PC_SetTickRate(OS_TICKS_PER_SEC); /* Reprogram tick rate */
OS_EXIT_CRITICAL();
OSStatInit(); /* Initialize uC/OS-II's statistics */
TaskStartCreateTasks(); /* Create all the application tasks */
for (;;)
{
TaskStartDisp(); /* Update the display */
if (PC_GetKey(&key) == TRUE)
{ /* See if key has been pressed */
if (key == 0x1B)
{ /* Yes, see if it's the ESCAPE key */
PC_DOSReturn(); /* Return to DOS */
}
if (key == 'm'||key == 'M')
{
printf("Mass(M):"); /* See if key 'M' has been pressed */
scanf("%d",&inpM);
M = inpM;
inpFlag = 1;
}
if (key == 'c'||key == 'C')
{
printf("Damper Constant(C):"); /* See if key 'c' has been pressed */
scanf("%d",&inpC);
C = inpC;
inpFlag = 1;
}
if (key == 'k'||key == 'K')
{
printf("Spring Constant(K):"); /* See if key 'k' has been pressed */
scanf("%d",&inpK);
K = inpK;
inpFlag = 1;
}
}
OSCtxSwCtr = 0; /* Clear context switch counter */
OSTimeDlyHMSM(0, 0, 1, 0); /* Wait one second */
}
}
/*$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, " 93618011 Xu Bang Lei's HomeWork2 ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 2, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 3, " You can input M,C,K to modify it's value!! ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 4, " ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 5, " Now F(t) is Squarewave!! ", 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, " |-> F(t) ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 9, " ___| |-> X ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 10, " | | M___| ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 11, " |-|| | | ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 12, " | | C _ | | ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 13, " |-||--|_|--| | ", DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 0, 14, " | | K | | ", 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);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -