首页 > 解决方案 > 在 UC/OS-II 中打印 OSTime

问题描述

设备:F28335 contorolCRAD 和实验者套件 - Delfino F28335。

移植 ucos-II。

我使用 OSTimeGet() 函数来获取 OSTime。

但是 task1 每次都返回 '0' 并且 task2 不起作用。

问题是什么?如何解决这个问题?

App_Task1's priority = 6u
App_Task2's priority = 7u


static  void  App_Task1 (void *p_arg)
{
   (void)&p_arg;
   INT32U t;

    while (DEF_TRUE) {

        t = OSTimeGet();

        printf("Task1 \n");
        printf("OSTime=%lu\n",t);
        OSTimeDly(5);
    }
}

static  void  App_Task2 (void *p_arg)
{
   (void)&p_arg;
   INT32U t;

    while (DEF_TRUE) {

        t = OSTimeGet();

        printf("Task2 \n");
        printf("OSTime=%lu\n",t);
        OSTimeDly(10);
    }
}


output
Task1 OSTime=0

标签: crtosucos

解决方案


您的 Systick 功能似乎运行不正确。由于我对您使用的芯片没有经验,因此无法给您完整的答案。但是你的 systick 函数应该包含这样的东西。这是来自 LPC17xx 的代码,但你应该会发生类似的事情

void  OS_CPU_SysTickHandler (void)
{
    CPU_SR_ALLOC();


    CPU_CRITICAL_ENTER();
    OSIntNestingCtr++;                                      /* Tell uC/OS-II that we are starting an ISR             */
    CPU_CRITICAL_EXIT();

    OSTimeTick();                                           /* Call uC/OS-II's OSTimeTick()                          */

    OSIntExit();                                            /* Tell uC/OS-II that we are leaving the ISR             */
}

OSTimeTick() 用于您的 OSTimeDly()、OSTimeGet() 和任务切换


推荐阅读