ucos_ii.h

定位到uCOS-II/Source/目录,这部分是系统的核心代码。先看ucos_ii.h文件:

1. 宏定义类型以及头文件包含

#define OS_VERSION  29207u  //定义版本号

#include <app_cfg.h>
#include <os_cfg.h>
#include <os_cpu.h>

#ifdef   OS_GLOBALS
#define  OS_EXT
#else
#define  OS_EXT  extern
#endif

#ifndef  OS_FALSE
#define  OS_FALSE       0u
#endif

#ifndef  OS_TRUE
#define  OS_TRUE        1u
#endif

#define  OS_ASCII_NUL   (INT8U)0
#define  OS_PRIO_SELF   0xFFu   /* Indicate SELF priority */

OS_PRIO_SELF被宏定义为0xFF,从注释上看OS_PRIO_SELF代表的是任务自身的优先级。为什么是0xff?这宏是适用于当你不知道任务的优先级但是又要操作任务的优先级的时候,uCOS-II的内部函数会将其转换为真正优先级的代码。例如你想用OSTaskDel()删除当前任务但是你又不知道当前任务的优先级,可以写为:

OSTaskDel(OS_PRIO_SELF);
#if OS_TASK_STAT_EN > 0
#define  OS_N_SYS_TASKS 2u      /* Number of system tasks */
#else
#define  OS_N_SYS_TASKS 1u
#endif

OS_TASK_STAT_EN是一个配置宏,OS_TASK_STAT_EN > 0表示使用系统中的统计任务。统计任务是属于系统任务,默认开启且无法被删除的系统任务还有一个空闲任务。当使能了系统统计任务,那么OS_N_SYS_TASKS=2,反之OS_N_SYS_TASKS=1。

#define  OS_TASK_STAT_PRIO  (OS_LOWEST_PRIO - 1)
#define  OS_TASK_IDLE_PRIO  (OS_LOWEST_PRIO) 

OS_TASK_STAT_PRIO、OS_TASK_IDLE_PRIO分别是统计任务、空闲任务的优先级,OS_LOWEST_PRIO为系统任务的最低优先级。假设系统为最多支持32个任务,那么任务的最低优先级为31(优先级数值越大,优先级越低)。倒数两个低优先级分别赋给统计任务和空闲任务。OS_TASK_STAT_PRIO = 30,OS_TASK_IDLE_PRIO = 29。统计任务用于统计系统各种状态参数,如内存/CPU使用率等,空闲任务在系统中无任务可执行时才轮到它执行。

#if OS_LOWEST_PRIO <= 63
#define  OS_EVENT_TBL_SIZE ((OS_LOWEST_PRIO) / 8 + 1)   /* Size of event table */
#define  OS_RDY_TBL_SIZE   ((OS_LOWEST_PRIO) / 8 + 1)   /* Size of ready table */
#else
#define  OS_EVENT_TBL_SIZE ((OS_LOWEST_PRIO) / 16 + 1)  /* Size of event table */
#define  OS_RDY_TBL_SIZE   ((OS_LOWEST_PRIO) / 16 + 1)  /* Size of ready table */
#endif

OS_RDY_TBL_SIZE是任务就绪表的下标取值范围,OS_LOWEST_PRIO=31, 这里计算得出OS_RDY_TBL_SIZE等于4,即下标取值为0~3。OS_EVENT_TBL_SIZE同理。

#define  OS_TASK_IDLE_ID    65535u  /* ID numbers for Idle, Stat and Timer tasks */
#define  OS_TASK_STAT_ID    65534u
#define  OS_TASK_TMR_ID     65533u

Idle、Stat、Timer任务的ID,为什么是65535?因为uCOS-II最多支持2^16个任务,其ID最大为65535。在uCOS-II中id值并没什么用处。

#define  OS_EVENT_EN  (((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0) || (OS_SEM_EN > 0) || (OS_MUTEX_EN > 0))
#define  OS_TCB_RESERVED ((OS_TCB *)1)

OS_EVENT_EN为1表示开启系统的事件功能机制。

#define  OS_STAT_RDY        0x00u    /* Ready to run (就绪态) */
#define  OS_STAT_SEM        0x01u    /* Pending on semaphore (因等待信号量而被挂起) */
#define  OS_STAT_MBOX       0x02u    /* Pending on mailbox (因等效MBox而被挂起) */
#define  OS_STAT_Q          0x04u    /* Pending on queue (因等待消息队列而被挂起) */
#define  OS_STAT_SUSPEND    0x08u    /* Task is suspended (挂起态) */
#define  OS_STAT_MUTEX      0x10u    /* Pending on mutual exclusion semaphore (因等待Mutex而被挂起) */
#define  OS_STAT_FLAG       0x20u    /* Pending on event flag group (因等待flag而被挂起) */
#define  OS_STAT_MULTI      0x80u    /* Pending on multiple events (因等待MULTI而被挂起,MULTI指代所有事件类型的综合) */
#define  OS_STAT_PEND_ANY   (OS_STAT_SEM | OS_STAT_MBOX | OS_STAT_Q | OS_STAT_MUTEX | OS_STAT_FLAG)

如上宏表示任务当前的运行状态,是TCB中OSTCBStat成员的取值选项。

#define  OS_STAT_PEND_OK              0u  /* 已经挂起结束或没有挂起 */
#define  OS_STAT_PEND_TO              1u  /* 在有超时机制的挂起状态中 */
#define  OS_STAT_PEND_ABORT           2u  /* 挂起出错 */

如上宏表示任务当前的挂起状态,也是TCB中OSTCBStatPend成员的取值选项。

#define  OS_EVENT_TYPE_UNUSED         0u
#define  OS_EVENT_TYPE_MBOX           1u
#define  OS_EVENT_TYPE_Q              2u
#define  OS_EVENT_TYPE_SEM            3u
#define  OS_EVENT_TYPE_MUTEX          4u
#define  OS_EVENT_TYPE_FLAG           5u

#define  OS_TMR_TYPE                  100u

如上宏表示系统中的事件类型。

#define  OS_FLAG_WAIT_CLR_ALL         0u    /* Wait for ALL    the bits specified to be CLR (i.e. 0)   */
#define  OS_FLAG_WAIT_CLR_AND         0u

#define  OS_FLAG_WAIT_CLR_ANY         1u    /* Wait for ANY of the bits specified to be CLR (i.e. 0)   */
#define  OS_FLAG_WAIT_CLR_OR          1u

#define  OS_FLAG_WAIT_SET_ALL         2u    /* Wait for ALL    the bits specified to be SET (i.e. 1)   */
#define  OS_FLAG_WAIT_SET_AND         2u

#define  OS_FLAG_WAIT_SET_ANY         3u    /* Wait for ANY of the bits specified to be SET (i.e. 1)   */
#define  OS_FLAG_WAIT_SET_OR          3u

#define  OS_FLAG_CONSUME           0x80u    /* Consume the flags if condition(s) satisfied             */
#define  OS_FLAG_CLR                  0u
#define  OS_FLAG_SET                  1u

跟flag事件相关的宏定义。

#if OS_TICK_STEP_EN > 0
#define  OS_TICK_STEP_DIS             0u    /* Stepping is disab
\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.
Ucos_II2.52 是一份非常完美的嵌入式开发系统,在学习ARM 的基础上,嵌入ucos 系统并增加自己的源码是一件不错的选择,目前在市面上已经有了大量的ucos 嵌入案例,特别是在arm 和dsp 的应用当中,已经成为一种主流,虽然和其它的嵌入式系统相比,ucos 不是很完善,如没有内存分配、任务级别不多;但却是一个代码简短、条理清晰、实时性及安全性能很高的嵌入式操作系统。 Ucos_II2.52 对比2.8 版的256 个任务而言,任务数量相比过少,但却是目前应用量最大的一个版本,相对而言,能够满足我们的基本要求,而且增加了很多消息处理,特别是在优先级别方面,具有不可比拟的优势;我曾试图阅读ecos源码,但还是失败了,还有挑战linux0.01 版源码的想法,最终我不能不被屈服;对于Ucos 而言,很多入门者是一个福音,因为它的代码非常的少,而且能够对应贝贝老师的书本直接参考,他的书本对结构方面讲解的极为xian 详细。 在学习Ucos 的整个过程中,E 文的理解是一个致命的打击,原因是我的E 文水平很差,不过Ucos 还是给了我尝试的动力,在作者的原基础上增加中文译码,也许是一件非常不错的选择,相信在中国和我这种水平的人多不胜数,中文的注解对源码而言,能够具有极高的理解价值,可以在极短的时间内,能够充分了解ucos 的真正含义。整个翻译过程历时4 个月,每每在寒冬腊月坐在计算机前面,不断的查阅贝贝老师的书来对整个Ucos 进行理解,对每个源码进行逐条翻译,也是一件非常需要勇气的事情,但E 文的翻译过程中很多变量是不能完全理解的,所以在翻译过程中不乏错误译文很多,于此带来的错误还请读者纠正,相信克服种种困难一定会有所了解的。对于经济窘迫的我来说,曾试图希望卖一点资料来养家糊口,但这种做法根本不现实,很多的读者可能和我一样,习惯了拿不收费的资料,并对变相收费有一种深恶痛绝的感觉;想了很多决定还是把它贡献出来,让更多的人来(更容易)了解ucos,贡献自己的一点力量。希望更多的人能加入这种高尚的学习氛围当中来,共同的来把一套完整的U 系列源码译文 早一日与我们分享,祝愿大家能够早日实现自己的梦想。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值