uCOS-II应用代码的编写

当移植好OS后,后面的事情就是编写任务和底层的驱动代码了。为了能更好的编写应用代码,推荐阅读《基于嵌入式实时操作系统的程序设计技术》一书,此书讲解了在uCOS-II下代码的编写。下面就谈谈应用代码编写下应该注意的东西。

 

   编写用户代码的步骤如下:

①.定义任务堆栈的长度。   

#define Task0StkLengh   64

②.定义任务的堆栈。       

OS_STK  Task0Stk[Task0StkLengh];

③.声明任务函数。       

    void Task0(void *pdata);

④.在适当的地方创建任务。

    OSTaskCreate(Task0, (void *)0, &Task0Stk[Task0StkLengh-1], 2);

⑤.编写任务代码。

        void Task0(void *pdata)

{

    While (1)

    {

        ……

}

}

 

任务建立

 

OSTaskCreate (void(*task)(void *pd), // 指向任务的指针

            void *pdata,          // 任务开始执行时,传递给任务的参数的指针

            OS_STK *ptos,         // 分配给任务的堆栈的栈顶指针

            INT8U prio           // 分配给任务的优先级

            );

 

任务格式,必须是下面两种中的一种:

① void YourTask (void *pdata) 

    for (;;) { 
        /* 用户代码 */ 
        调用μC/OS-Ⅱ的服务例程之一:
        OSMboxPend();
        OSQPend();
        OSSemPend();
        OSTaskDel(OS_PRIO_SELF);
        OSTaskSuspend(OS_PRIO_SELF); 
        OSTimeDly();
        OSTimeDlyHMSM();

        OSTaskDel(OS_PRIO_SELF);
        /* 用户代码 */
    } 
}

② void YourTask (void *pdata) 
{

     /* 用户代码 */
        OSTaskDel(OS_PRIO_SELF);

}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
\SOFTWARE The main directory from the root where all software-related files are placed. \SOFTWARE\BLOCKS The main directory where all ‘Building Blocks’ are located. With μC/OS-II, I included a ‘building block’ that handles DOS-type compatible functions that are used by the example code. \SOFTWARE\BLOCKS\TO This directory contains the files for the TO utility (see Appendix E, TO). The source file is TO.C and is found in the \SOFTWARE\TO\SOURCE directory. The DOS executable file (TO.EXE) is found in the \SOFTWARE\TO\EXE directory. Note that TO requires a file called TO.TBL which must reside on your root directory. An example of TO.TBL is also found in the \SOFTWARE\TO\EXE directory. You will need to move TO.TBL to the root directory if you are to use TO.EXE. \SOFTWARE\uCOS-II The main directory where all μC/OS-II files are located. \SOFTWARE\uCOS-II\EX1_x86L This directory contains the source code for EXAMPLE #1 (see section 1.07, Example #1) which is intended to run under DOS (or a DOS window under Windows 95). \SOFTWARE\uCOS-II\EX2_x86L This directory contains the source code for EXAMPLE #2 (see section 1.08, Example #2) which is intended to run under DOS (or a DOS window under Windows 95). \SOFTWARE\uCOS-II\EX3_x86L This directory contains the source code for EXAMPLE #3 (see section 1.09, Example #3) which is intended to run under DOS (or a DOS window under Windows 95). \SOFTWARE\uCOS-II\Ix86L This directory contains the source code for the processor dependent code (a.k.a. the port) of μC/OS-II for an 80x86 Real-Mode, Large Model processor. \SOFTWARE\uCOS-II\SOURCE This directory contains the source code for processor independent portion of μC/OS-II. This code is fully portable to other processor architectures.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值