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?
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.
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?
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:
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
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