ucosii操作系统内核源码学习第一篇

根据书本理论介绍以及实际看内核源代码得出:

1. 操作系统默认定义了64个TCB块(为全局变量,编译时候以及分配了,创建一个任务就使用一个,删除一个任务就归还一个)(为什么最大只支持64个任务呢,我们可能想到去更改OS_MAX_TASKS宏的值,但是任务就绪表OSRdyTbl[8]既然已经这样定义了,说明此系统初衷只能最大管理64个任务,而且为了加快查找最高优先级任务定义的OSUnMapTbl[ ]数组(这个数组比较难理解)也是专门为64个任务二设定的,所以要想修改系统支持的最大任务数,就得修改多处,自己慢慢琢磨吧!),每个TCB里面包括了所有的属性,所以会占用大量的单片机ram空间,包括OS_STK *ptos这个指针变量,只是这个任务自己的堆栈指针没有指向任何分配的空间(这个空间由我们创建任务时候才自己定义一个大数组,这个更浪费ram空间)。

2. 此时的64个TCB块还是孤立的,只是在一个OSTCBTbl[64]数组里面而已。在main函数里面第一行代码就是OSInit( )函数,这个函数进行了所有系统变量(都是全局变量,比如当前运行控制块指针等)初始化,其中调用了OS_InitTCBList( )函数,在这函数里面,首先把这64个TCB块(由于此时还没有任何任务运行,所以这时都称为)进行了双向链表连接起来,使得OSTBFreeList空控制块链表头指针指向&OSTCBTbl[0],此时OSTCBList已经分配任务的TCB双向链表头指针这里只是置为(OS_TCB *)0;而已,以为此时还没有任何任务create,所以这个指针确实应该为0

比较重要的函数:    

 INT8U OSTaskCreat( void (*task)(void *pd) , void *pdata, OS_STK *ptos, INT8U prio )

{

        // 这个函数对当前创建任务的堆栈内容(ptos所指向的数组空间)赋值(cpu内部寄存器所有内容暂存起来),包括cpu内部的psw状态寄存器,通用寄存器R0-R15(个人觉得这些都没必要,因为这里只是创建任务,下次切换回来这个任务的时候,也不需要这时候保存的内部寄存器内容呀),还有任务的传递参数pdata,任务函数的首地址等等内容,然后返回这个堆栈的顶部指针(注:不同cpu可能堆栈增长方向不同,我看51单片机是向着低地址方向增长的)(注:由于我们在定义一个任务时候,定义的堆栈默认为 OS_STK MyTaskStk[MyTaskStkN]; 看了一下源码,这个OS_STK是typedef为unsigned char 类型,MyTaskStkN宏定义默认为64(由于堆栈增长时候不会检测是否大于64字节空间(可能后面检测了吧,现在先认为没有检测吧),所以有可能会产生数组越界现象,造成系统崩掉,那么特别注意这里定义堆栈空间时候一定要考虑好需要多大,宁愿大一点),也就是说每定义一个任务,就多需要64字节ram内存,51单片机为啥很难跑起来这个操作系统,应该就是因为这样耗费ram太大,51单片机ram一般就几百字节)

        OS_STK *OSTaskStkInit( void (*task)( void *pd) , void *pdato , OS_STK *ptos , INT16U opt );

        // 这个函数里面填充好当前任务TCB的各个属性值,例如优先级,堆栈大小等,其中最重要的是,还使用头插法把当前任务快插入了双向任务链表(如果这是第一个任务,那就创建这个双向任务链边),即新的TCB控制块是往左边插入的,此时OSTCBList指向链表左边的第一个节点

        INT8U OSTCBInit(INT8U prio , OS_STK *ptos , OS_STK *pbos , INT16U id, INT16U stk_size , void *pext , INT16U opt );

}

\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-II 2.52版本的源码源码分析,不用下了源码再去找源码分析了。 \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、付费专栏及课程。

余额充值