0

Device : F28335 contorolCRAD and Experimenter's Kit - Delfino F28335.

Ported ucos-II.

I use OSTimeGet() function to get OSTime.

But task1 returns '0' everytime and task2 doesn't work.

What is the problem? How to fix this?

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
Jinho
  • 9
  • 1
  • What do you mean `task2` doesn't work? Doesn't run? – Fiddling Bits Oct 24 '18 at 14:55
  • 2
    `OSTimeGet` `return`ing `0` sounds like your `SysTick`(or whatever the periodic time interrupt is) interrupt isn't firing. – Fiddling Bits Oct 24 '18 at 14:56
  • Yes, task2 doesn't run. And task1 printed just once. – Jinho Oct 25 '18 at 06:02
  • CPU_Init(); BSP_Init(); OSInit(); OSTaskCreateExt(TaskStart); OSStart(); => in main() / BSP_Tick_Init(); =>in TaskStart / Can you explain why OSTimeGet returns 0 everytime? thank you for comment :) – Jinho Oct 25 '18 at 06:08
  • Delays in UCOS are based on the systick interrupt. When this interrupt isn't running of configured correctly the task switches will not work and the same goes for the delays. Probably the Task1 function will not get passed OSTimeDly(5); – Roel Balink Oct 26 '18 at 06:34
  • `task1` does not return; _"task1 returns '0' everytime"_ does not make much sense. Where is the code where the threads are instantiated and the scheduler initialised and started? The scheduler is clearly not running, or the tick handler not implemented, or interrupts disabled. – Clifford Oct 28 '18 at 07:53
  • Where, when and how have you called `OSInit()`, `OSTaskCreate()` and `OSStart()`. Is the uC/OS-II port your own, or provided. Chances are the error is in the port if your thread and OS initialisation code (not shown) is correct. As an aside `printf()` is unlikely to be thread safe; if it is buffered, you are likely to get garbled interleaved output, if it is unbufferd it may have a bigger impact on the thread timing than the delays. The results will depend greatly on the relative priorities of the two threads. – Clifford Oct 28 '18 at 08:07
  • Do not add clarifications in comments - edit the question to add vital information. It seems from your output that while _"OSTimeGet returns 0 everytime"_, it is in fact running only _once_ despite being in a not-terminating loop. That is the issue at hand - it is returning zero because when it runs that is exactly what the tick value is - of more interest is why is the tick not running - allowing `OSDelay` to return, and the `OSTime` to increment? That is to say you are missing the actual problem and asking about just one of several _symptoms_ that indicate the real issue. – Clifford Oct 28 '18 at 08:13

1 Answers1

0

It seems that your Systick function isn't running correctly. As I have no experience in the Chip you are using I cannot give you the full answer. But your systick function should contain something like this. This is code from a LPC17xx but something similliar should happen for you

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             */
}

The OSTimeTick() is used for your OSTimeDly(), OSTimeGet() and the task switching

Roel Balink
  • 417
  • 1
  • 4
  • 19