关于OS_PRIO_SELF的说明

在看ucosii 中关于删除任务的函数 OSTaskDel 时看到

if (prio == OS_PRIO_SELF) {                                 /* See if requesting to delete self    */
     prio = OSTCBCur->OSTCBPrio;                             /* Set priority to delete to current   */
    }

这样一段代码,一开始不太理解,自己仔细想了想,下面说一下自己的理解。

我先查了一下 OS_PRIO_SELF 是在uCOS_II.H中定义的:

#define  OS_PRIO_SELF           0xFF                    /* Indicate SELF priority                      */

 

即 OS_PRIO_SELF 是一个全局变量,且值是0xFF 。那么这个数字有什么用那?

我是这样理解的,这个常量使用在有关ucos中任务处理的函数上的,用它来代表一个任务自己的优先级,你可能要问了OS_PRIO_SELF的值不是0xff 吗,他怎么代表当前任务自己的优先级那。是这样的,在每一个函数内部都有我上面用红的字体表示出的代码,把当前真实的优先级赋给prio。这样当你不知道当前任务的优先级时,你就可以用OS_PRIO_SELF来代替了。反正它函数内部有转换成真正的优先级的代码。

这样对我们编程者来说更方便。

例如:你想用OSTaskDel ()这个函数删除当前的任务,一种方法是你给函数传当前任务的优先级(前提是你自己知道)即OSTaskDel (24)【假设当前任务的优先级就是24 】,另一种方法是直接写 OSTaskDel (OS_PRIO_SELF )。反正在函数内部会把真正的当前任务优先级赋给prio的。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
********************************************************************************************************* * 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(). * * Arguments : none * * Returns : none ********************************************************************************************************* */ void OSInit (void) { INT16U i; INT8U *prdytbl; OS_TCB *ptcb1; OS_TCB *ptcb2; #if (OS_EVENT_EN > 0) && (OS_MAX_EVENTS > 1) OS_EVENT *pevent1; OS_EVENT *pevent2; #endif #if OS_VERSION >= 204 OSInitHookBegin(); /* Call port specific initialization code */ #endif #if OS_TIME_GET_SET_EN > 0 OSTime = 0L; /* Clear the 32-bit system clock */ #endif OSIntNesting = 0; /* Clear the interrupt nesting counter */ OSLockNesting = 0; /* Clear the scheduling lock counter */ OSTaskCtr = 0; /* Clear the number of tasks */ OSRunning = FALSE; /* Indicate that multitasking not started */ OSIdleCtr = 0L; /* Clear the 32-bit idle counter */ #if (OS_TASK_STAT_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0) OSIdleCtrRun = 0L; OSIdleCtrMax = 0L; OSStatRdy = FALSE; /* Statistic task is not ready */ #endif OSCtxSwCtr = 0; /* Clear the context switch counter */ OSRdyGrp = 0x00; /* Clear the ready list */ prdytbl = &OSRdyTbl[0]; for (i = 0; i < OS_RDY_TBL_SIZE; i++) { *prdytbl++ = 0x00; } OSPrioCur = 0; OSPrioHighRdy = 0; OSTCBHighRdy = (OS_TCB *)0; /* TCB Initialization */ OSTCBCur = (OS_TCB *)0; OSTCBList = (OS_TCB *)0; for (i = 0; i < (OS_LOWEST_PRIO + 1); i++) { /* 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++) { /* Init. list of free TCBs */ ptcb1->OSTCBNext = ptcb2; ptcb1++; ptcb2++; } ptcb1->OSTCBNext = (OS_TCB *)0; /* Last OS_TCB */ OSTCBFreeList = &OSTCBTbl[0]; #if (OS_EVENT_EN > 0) && (OS_MAX_EVENTS > 0) #if OS_MAX_EVENTS == 1 OSEventFreeList = &OSEventTbl[0]; /* Only have ONE event control block */ OSEventFreeList->OSEventType = OS_EVENT_TYPE_UNUSED; OSEventFreeList->OSEventPtr = (OS_EVENT *)0; #else pevent1 = &OSEventTbl[0]; pevent2 = &OSEventTbl[1]; for (i = 0; i < (OS_MAX_EVENTS - 1); i++) { /* Init. list of free EVENT control blocks */ pevent1->OSEventType = OS_EVENT_TYPE_UNUSED; pevent1->OSEventPtr = pevent2; pevent1++; pevent2++; } pevent1->OSEventType = OS_EVENT_TYPE_UNUSED; pevent1->OSEventPtr = (OS_EVENT *)0; OSEventFreeList = &OSEventTbl[0]; #endif #endif #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0) OS_FlagInit(); /* Initialize the event flag structures */ #endif #if (OS_Q_EN > 0) && (OS_MAX_QS > 0) OS_QInit(); /* Initialize the message queue structures */ #endif #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0) OS_MemInit(); /* Initialize the memory manager */ #endif /* ------------------------------------- CREATION OF 'IDLE' TASK --------------------------------------- */ #if OS_TASK_CREATE_EXT_EN > 0 #if OS_STK_GROWTH == 1 (void)OSTaskCreateExt(OS_TaskIdle, (void *)0, /* No arguments passed to OS_TaskIdle() */ &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Top-Of-Stack */ OS_IDLE_PRIO, /* Lowest priority level */ OS_TASK_IDLE_ID, &OSTaskIdleStk[0], /* Set Bottom-Of-Stack */ OS_TASK_IDLE_STK_SIZE, (void *)0, /* No TCB extension */ OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack */ #else (void)OSTaskCreateExt(OS_TaskIdle, (void *)0, /* No arguments passed to OS_TaskIdle() */ &OSTaskIdleStk[0], /* Set Top-Of-Stack */ OS_IDLE_PRIO, /* Lowest priority level */ OS_TASK_IDLE_ID, &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Bottom-Of-Stack */ OS_TASK_IDLE_STK_SIZE, (void *)0, /* No TCB extension */ OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack */ #endif #else #if OS_STK_GROWTH == 1 (void)OSTaskCreate(OS_TaskIdle, (void *)0, &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], OS_IDLE_PRIO); #else (void)OSTaskCreate(OS_TaskIdle, (void *)0, &OSTaskIdleStk[0], OS_IDLE_PRIO); #endif #endif /* ------------------------------- CREATION OF 'STATISTIC' TASK ---------------------------------- */ #if OS_TASK_STAT_EN > 0 #if OS_TASK_CREATE_EXT_EN > 0 #if OS_STK_GROWTH == 1 (void)OSTaskCreateExt(OS_TaskStat, (void *)0, /* No args passed to OS_TaskStat()*/ &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1], /* Set Top-Of-Stack */ OS_STAT_PRIO, /* One higher than the idle task */ OS_TASK_STAT_ID, &OSTaskStatStk[0], /* Set Bottom-Of-Stack */ OS_TASK_STAT_STK_SIZE, (void *)0, /* No TCB extension */ OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); /* Enable stack checking + clear */ #else (void)OSTaskCreateExt(OS_TaskStat, (void *)0, /* No args passed to OS_TaskStat()*/ &OSTaskStatStk[0], /* Set Top-Of-Stack */ OS_STAT_PRIO, /* One higher than the idle task */ OS_TASK_STAT_ID, &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1], /* Set Bottom-Of-Stack */ OS_TASK_STAT_STK_SIZE, (void *)0, /* No TCB extension */ OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); /* Enable stack checking + clear */ #endif #else #if OS_STK_GROWTH == 1 (void)OSTaskCreate(OS_TaskStat, (void *)0, /* No args passed to OS_TaskStat()*/ &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1], /* Set Top-Of-Stack */ OS_STAT_PRIO); /* One higher than the idle task */ #else (void)OSTaskCreate(OS_TaskStat, (void *)0, /* No args passed to OS_TaskStat()*/ &OSTaskStatStk[0], /* Set Top-Of-Stack */ OS_STAT_PRIO); /* One higher than the idle task */ #endif #endif #endif #if OS_VERSION >= 204 OSInitHookEnd(); /* Call port specific init. code */ #endif } /*$PAGE*/ /*

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值