stm32isp吧 关注:168贴子:165
  • 3回复贴,共1

UCOSII V2.8 系统漏洞 BUG

只看楼主收藏回复

这个BUG陷害了我半年时间,头发也白了很多,最近才逐渐发现真相的
现象是这样的:
1平时好好的,一点问题都没有,因为开了看门狗,系统不时的出现复位,不过我没有在意为什么复位,因为我的系统允许一定的故障
2 因为要做省电处理,进入停止模式,所以把看门狗关闭了。这时就问题来了:唤醒的时候,居然只有最低优先级的任务在运行,而其他任务不能运行?!!!
花了半年时间,才逐渐摸出规律来,染化在网上验证了一下这个问题,果然找到了同样悲剧的一串童鞋。。。
所以决定把这个问题公开,以免后人再上当。
解决办法很简单,就是把OS文件夹里面的OS_CORE.C文件修改两个地方,修改后的文件请丛吧里找。同样悲剧的童鞋在这里:http://bbs.21ic.com/icview-95426-1-1.html
同样悲剧的童鞋说:


IP属地:广东1楼2013-09-08 18:27回复
    网上找到了更详细资料 1) OS_CORE.C:
    OSIntExit() and OS_Sched() have changed slightly because of a boundary condition found with the Cortex-M3 port. Specifically, we needed to move the statement:
    OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
    Before testing for the priority.
    2.86中的代码是这样的:
    void OS_Sched (void)
    {
    #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
    OS_CPU_SR cpu_sr = 0;
    #endif
    OS_ENTER_CRITICAL();
    if (OSIntNesting == 0) { /* Schedule only if all ISRs done and ... */
    if (OSLockNesting == 0) { /* ... scheduler is not locked */
    OS_SchedNew();
    if (OSPrioHighRdy != OSPrioCur) { /* No Ctx Sw if current task is highest rdy */
    OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
    #if OS_TASK_PROFILE_EN > 0
    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();
    }
    2.88中的是这样的:
    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();
    }
    修改了两个地方、把优先级判断与优先级切换掉过来了,个人感觉应该是对的


    来自iPhone客户端3楼2013-09-12 10:31
    回复
      确认是这个问题,本人已经全部改过来了。死机现象已派出。楼主我正打算把文件传上来就被楼上捅开了。


      IP属地:广东来自iPhone客户端4楼2013-09-12 10:33
      回复
        V2.86的BUG修改方式
        原代码:
        if (OSPrioHighRdy != OSPrioCur)
        { /* No Ctx Sw if current task is highest rdy */
        OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
        ...
        }
        修改后:
        OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
        if (OSPrioHighRdy != OSPrioCur)
        { /* No Ctx Sw if current task is highest rdy */
        ...
        }
        大家注意:OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];的位置有变化,这是高优先级任务调度失败的原因。


        IP属地:广东5楼2013-09-12 10:37
        回复