国庆放假,早上6点起来学习uCOS II,上一周通过朱老师的课程学习了Core.c部分的代码,早上起来全部重新看了一遍,感觉都能梳理函数的功能了,也基本了解了各个之间的关系,主要关注了TCB task这块的功能,event还没怎么关注!
下面将理解比较深刻的地方做个小笔记,试了一下代码粘贴功能,很差,还是不粘贴了
1.void OSInit (void)
该函数主要完成了全局变量的初始化,以及建立了空闲链表和就绪链表,以及建立空闲任务和统计任务,学习链表的建立
*********************************************************************************************************
* INITIALIZATION
*
* Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
* creating any uC/OS-II object and, prior to calling OSStart().
* 内部函数,必须在uC/OS-II任务之前调用,被OSStart()调用
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void OSInit (void)
OSTCBList = (OS_TCB *)0;
for (i = 0; i < (OS_LOWEST_PRIO + 1); i++) { /* 先将 OSTCBPrioTbl清零;Clear the priority table */
OSTCBPrioTbl[i] = (OS_TCB *)0;
}
ptcb1 = &OSTCBTbl[0];
ptcb2 = &OSTCBTbl[1];
for (i = 0; i < (OS_MAX_TASKS + OS_N_SYS_TASKS - 1); i++) { /*再用for循环依次 OSTCBPrioTbl连接成链表 Init. list of free TCBs */
ptcb1->OSTCBNext = ptcb2;
ptcb1++;
ptcb2++;
}
ptcb1->OSTCBNext = (OS_TCB *)0; /*链表的最后一个指向0(NULL) Last OS_TCB */
OSTCBFreeList = &OSTCBTbl[0];
2.void OSIntEnter (void)和OSIntExit()成对使用,ISR
*********************************************************************************************************
* ENTER ISR
*
* Description: This function is used to notify uC/OS-II that you are about to service an interrupt
* service routine (ISR). This allows uC/OS-II to keep track of interrupt nesting and thus
* only perform rescheduling at the last nested ISR.
*
* Arguments : none
*
* Returns : none
*
* Notes : 1) Your ISR can directly increment OSIntNesting without calling this function because
* OSIntNesting has been declared 'global'. You MUST, however, be sure that the increment
* is performed 'indivisibly' by your processor to ensure proper access to this critical
* resource.
你的ISR中断服务函数可以不通过调用这个函数直接增加OSIntNesting,因此OSIntNesting是全部变量,
你必须,无论如何,保证增加OSIntNesting是"不可分割的"执行的,通过处理器保证这一临界资源适当的
访问
* 2) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
您仍然必须调用OSIntExit(),即使您直接增加了OSIntNesting嵌套
* 3) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
* to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
* end of the ISR.
您必须成对地调用OSIntEnter()和OSIntExit()。换句话说,对于ISR开头的每一个OSIntEnter()调用,
您必须在ISR结尾有一个对应OSIntExit()的调用。
*********************************************************************************************************
*/
void OSIntEnter (void)
3.任务锁的和解锁函数,任务锁开启后,关闭了系统调度
4.TCB的初始化
这里是双向链表的头插入
OS_ENTER_CRITICAL();
OSTCBPrioTbl[prio] = ptcb;
ptcb->OSTCBNext = OSTCBList; /* 链表的头插入法 Link into TCB chain */
ptcb->OSTCBPrev = (OS_TCB *)0;
if (OSTCBList != (OS_TCB *)0) {
OSTCBList->OSTCBPrev = ptcb;
}
OSTCBList = ptcb;
OSRdyGrp |= ptcb->OSTCBBitY; /* 创建完任务就将其置为就绪态 Make task ready to run */
OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
总结下:学习uCOS需要用到的知识
1.C 指针,结构体指针等
2.数组 最基础,应该都ok
3.结构体 不熟悉结构体的肯定看不懂
4.链表 不熟悉链表也看不懂,想当初我最开始了解ucos,也是只学习了一下结构体就去看代码了,发现TCB 那个结构体内部还有指向自己的结构体指针,我就看不懂了,学习了链表,才发现这是链表的标准定义。所以学习就像建房子,慢慢的基础的单位都在变大
5.位图,位操作 这个应该都ok、搞过单片机的都会位操作,但位图的思路可能并不深刻
目前就了解这么多,另外操作系统的概念思路就是不停的保存和恢复寄存器,当然很多细节