Chinaunix首页 | 论坛 | 博客
  • 博客访问: 588735
  • 博文数量: 169
  • 博客积分: 2656
  • 博客等级: 少校
  • 技术积分: 1685
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-30 13:03
文章分类

全部博文(169)

文章存档

2011年(1)

2010年(135)

2009年(33)

我的朋友

分类: 嵌入式

2010-05-22 17:51:30

主 要 代 码 :

/******************************Test*******************************/

#include "includes.h"

#define  TASK_STK_SIZE   512             //任务堆栈长度

OS_STK   T0TaskStk[TASK_STK_SIZE];      //定义任务堆栈区

OS_STK   T1TaskStk[TASK_STK_SIZE];

OS_STK   T2TaskStk[TASK_STK_SIZE];      //定义任务堆栈区

INT16S   key;                               //用于退出uCOS_II的键

INT8U   x=0,y=0;                           //字符显示位置

void  T0Task(void *data);                       //声明任务

void  T1Task(void *data);

void  T2Task(void *data);                   //声明任务

/************************主函数*********************************/

void  main (void)

{

    char* s_M="";                           //定义要显示的字符

    OSInit( );                                  //初始化uCOS_II

    PC_DOSSaveReturn( );                        //保存Dos环境

    PC_VectSet(uCOS, OSCtxSw);              //安装uCOS_II中断

    OSTaskCreate(

T0Task,                             //创建任务MyTask

        s_M,                                //给任务传递参数

        &T0TaskStk[TASK_STK_SIZE - 1],      //设置任务堆栈栈顶指针

                                         //任务的优先级别为0

);

    OSStart( );                             //启动多任务管理

}

/*******************任务T0Task**********************************/

void  T0Task (void *pdata)

{

    char* s_Y="LiHanjing";

    char* s_H="05062202 08";                            //定义要显示的字符

#if OS_CRITICAL_METHOD == 3

    OS_CPU_SR  cpu_sr;

#endif

    printf("OSCtxSwCtr=%d",OSCtxSwCtr);

    printf("OSIntNesting=%d",OSIntNesting);

    printf("OSLockNesting=%d",OSLockNesting);

    printf("OSPrioCur=%d\n",OSPrioCur);

    printf("OSPrioHighRdy=%d",OSPrioHighRdy);

    printf("OSRdyGrp=%d",OSRdyGrp);

    printf("OSRdyTbl[OS_RDY_TBL_SIZE]=%d",OSRdyTbl[OS_RDY_TBL_SIZE]);

    printf("OSRunning=%d\n",OSRunning);

    printf("OSTaskCtr=%d",OSTaskCtr);

    printf("OSIdleCtr=%d",OSIdleCtr);

    printf("*OSTCBCur=%d",*OSTCBCur);

    printf("*OSTCBFreeList=%d\n",*OSTCBFreeList);

    printf("*OSTCBHighRdy=%d",*OSTCBHighRdy);

    printf("*OSTCBList=%d",*OSTCBList);

    printf("*OSTCBPrioTbl[OS_LOWEST_PRIO+1]=%d\n",*OSTCBPrioTbl[OS_LOWEST_PRIO+1]);

    pdata = pdata;

    OS_ENTER_CRITICAL( );

    PC_VectSet(0x08, OSTickISR);                //安装时钟中断向量

    PC_SetTickRate(OS_TICKS_PER_SEC);       //设置时钟频率

    OS_EXIT_CRITICAL( );

    OSStatInit( );                              //初始化统计任务

    OSTaskCreate(

T1Task,                             //创建任务MyTask

            s_Y,                                    //给任务传递参数

            &T1TaskStk[TASK_STK_SIZE - 1],  //设置任务堆栈栈顶指针

                                             // MyTask的优先级别为2

);

    OCTaskCreate(

T2Task,                             //创建任务MyTask

            s_H,                                    //给任务传递参数

            &T2TaskStk[TASK_STK_SIZE - 1],  //设置任务堆栈栈顶指针

                                             // MyTask的优先级别为2

);

    for (;;)

    {

        if (x>50)

        {

            x=0;

            y+=2;

        }

        PC_DispStr(x, y,                    //字符的显示位置

      (char*)pdata,

        DISP_BGND_BLACK+DISP_FGND_WHITE );

            x += 1;

        //如果按下Esc键则退出uCOS_II

        if (PC_GetKey(&key) == TRUE)

        {

            if (key == 0x1B)

            {

                PC_DOSReturn( );                //恢复Dos环境

            }

        }

        OSTimeDlyHMSM(0, 0, 3, 0);          //等待3秒

}

}

/************************任务T1Task******************************/

void  T1Task (void *pdata)

  OS_TCB *Ph;

#if OS_CRITICAL_METHOD == 3

    OS_CPU_SR  cpu_sr;

#endif

    pdata = pdata;

    for (;;)

    {

        if (x>50)

            {

                x=0;

                y+=2;

    }

        PC_DispStr(

x, y,                   //字符的显示位置

                  (char*)pdata,

                    DISP_BGND_BLACK+DISP_FGND_WHITE

);

            OSTaskQuery(2,Ph);

            printf("OSTCBDly=%d",Ph->OSTCBDly);

            printf("OSTCBStat=%d",Ph->OSTCBStat);

            printf("OSTCBPrio=%d",Ph->OSTCBPrio);

            printf("OSTCBX=%d",Ph->OSTCBX);

            printf("OSTCBY=%d",Ph->OSTCBY);

            printf("OSTCBBitX=%d",Ph->OSTCBBitX);

            printf("OSTCBBitY=%d\n",Ph->OSTCBBitY);

            x += 8;

        OSTimeDlyHMSM(0, 0, 1, 0);      //等待1秒

    }

}

/************************任务T2Task******************************/

void  T2Task (void *pdata)

OS_TCB  *Pb;

#if OS_CRITICAL_METHOD == 3

    OS_CPU_SR  cpu_sr;

#endif

    pdata = pdata;

    for (;;)

    {

        if (x>50)

            {

                x=0;

                y+=2;

    }

        PC_DispStr(

x, y,                   //字符的显示位置

                  (char*)pdata,

                    DISP_BGND_BLACK+DISP_FGND_WHITE

);

            OSTaskQuery(3,Pb);

            printf("OSTCBDly=%d",Pb->OSTCBDly);

            printf("OSTCBStat=%d",Pb->OSTCBStat);

            printf("OSTCBPrio=%d",Pb->OSTCBPrio);

            printf("OSTCBX=%d",Pb->OSTCBX);

            printf("OSTCBY=%d",Pb->OSTCBY);

            printf("OSTCBBitX=%d",Pb->OSTCBBitX);

            printf("OSTCBBitY=%d\n",Pb->OSTCBBitY);

                if (PC_GetKey(&key) == TRUE)

        {

            if (key == 0x1B)

            {

                PC_DOSReturn( );                //恢复Dos环境

            }

        }

            x += 8;

        OSTimeDlyHMSM(0, 0, 1, 0);      //等待1秒

    }

}

/************************End************************************/

阅读(850) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~