嵌入式学习小组
直播中

王琴

7年用户 165经验值
私信 关注

请问ucos运行OS_TASK_SW()是否直接跳转任务?

下面两个系统调度函数运行完切换函数XX——SW(),是否就直接跳转任务啦,因为任务切换函数是用的BX LR,直接跳转啦。那么后面还有一句OS_EXIT_CRItiCAL();退出临界区函数还没执行?
请问具体的操作顺序是什么样的?
void  OS_Sched (void)
{
#if OS_CRITICAL_METHOD == 3u                           /* Allocate storage for CPU status register     */
    OS_CPU_SR  cpu_sr = 0u;
#endif
    OS_ENTER_CRITICAL();
    if (OSIntNesting == 0u) {                          /* Schedule only if all ISRs done and ...       */
        if (OSLockNesting == 0u) {                     /* ... scheduler is not locked                  */
            OS_SchedNew();
            OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
            if (OSPrioHighRdy != OSPrioCur) {          /* No Ctx Sw if current task is highest rdy     */
#if OS_TASK_PROFILE_EN > 0u
                OSTCBHighRdy->OSTCBCtxSwCtr++;         /* Inc. # of context switches to this task      */
#endif
                OSCtxSwCtr++;                          /* Increment context switch counter             */
                OS_TASK_SW();                          /* Perform a context switch                     */
            }
        }
    }
    OS_EXIT_CRITICAL();
}
void  OSIntExit (void)
{
#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr = 0u;
#endif
    if (OSRunning == OS_TRUE) {
        OS_ENTER_CRITICAL();
        if (OSIntNesting > 0u) {                           /* Prevent OSIntNesting from wrapping       */
            OSIntNesting--;
        }
        if (OSIntNesting == 0u) {                          /* Reschedule only if all ISRs complete ... */
            if (OSLockNesting == 0u) {                     /* ... and not locked.                      */
                OS_SchedNew();
                OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
                if (OSPrioHighRdy != OSPrioCur) {          /* No Ctx Sw if current task is highest rdy */
#if OS_TASK_PROFILE_EN > 0u
                    OSTCBHighRdy->OSTCBCtxSwCtr++;         /* Inc. # of context switches to this task  */
#endif
                    OSCtxSwCtr++;                          /* Keep track of the number of ctx switches */
                    OSIntCtxSw();                          /* Perform interrupt level ctx switch       */
                }
            }
        }
        OS_EXIT_CRITICAL();
    }
}

回帖(3)

王明钊

2019-10-9 08:53:24
汇编不懂,但是既然OS_ENTER_CRITICAL锁住了,应该是OS_EXIT_CRITICAL之后才能真正切换任务。不然设计没意义了
举报

廉凌刚

2019-10-9 09:07:05
我现在是按照流水线理解的,因为退出临界区的汇编为:
MSR PRIMASK,R0
BX LR
这两条指令应该在取指、译码器里。所以正好能执行。
举报

周杰

2019-10-9 09:26:46
这块 我也不明白,帮顶
举报

更多回帖

发帖
×
20
完善资料,
赚取积分