This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Need a RTOS delay API that does not block the CPU.

I need a time delay in my code (mS order). But it cannot block the CPU. It must allow other tasks to run until the delay is exhausted. Is such facility available?

  • TI-RTOS's Task_sleep does what you want.
  • Hi Jonathan,

    If Markus's reply answers your question, can you please mark this post as answered ?

    Here's a link to Task_sleep() cdoc in case you need more info on the API:

    http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/sysbios/6_45_00_20/exports/bios_6_45_00_20/docs/cdoc/ti/sysbios/knl/Task.html#sleep

    Best,

    Ashish

  • In a nutshell, I am trying to blink a LED on my board to indicate the ID of the board. It is a low priority task. So I am calling a function to blink the LED from the Idle thread. That's why I need a time delay to blink the LED at a low rate. The Task_sleep() looks good, but I saw this constraint in the documentation you sent me:

    "Task_sleep should not be called from within an Idle function. Doing so prevents analysis tools from gathering run-time information."

    Do I need to be concerned with this constraint if I use Task_sleep() the way I described?

    Jonanthan

  • Hi Jonathan,

    Like you noted, calling Task_sleep() from Idle task is bad. I haven't looked at your code but from your post, it looks like you are creating a low priority task and plan on calling sleep from within it. That should be ok.

    Best,
    Ashish
  • Actually, I was going to call Task_sleep() from a function (Blink_LED()) in the Idle thread. But It sounds like it is not a good idea. Are you suggesting that I should create a low priority task to do the LED blinking and calling sleep() from that task instead of using the Idle thread?

    Alternatively, can I use the Clock module in RTOS to make my own delay function and use it within the Idle thread? Will this be a non-blocking delay similar to the Task_sleep() call?

    Jonathan
  • Jonathan Duan said:

    Actually, I was going to call Task_sleep() from a function (Blink_LED()) in the Idle thread. But It sounds like it is not a good idea. Are you suggesting that I should create a low priority task to do the LED blinking and calling sleep() from that task instead of using the Idle thread?

    Yes, I would suggest creating a low priority task to do the LED blinking and call Task_sleep().

    Jonathan Duan said:

    Alternatively, can I use the Clock module in RTOS to make my own delay function and use it within the Idle thread? Will this be a non-blocking delay similar to the Task_sleep() call?

    If you need to do the LED blinking from the Idle thread only then a possible solution is to implement a delay function using clock tick count (by default 1 clock tick=1ms). The delay function would continuously read the number of elapsed clock ticks by calling Clock_getTicks() and ensure the desired amount of delay time has elapsed before returning. This would basically provide a non-blocking delay.

    Best,

    Ashish