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.

Safety of Task_sleep( . )

Other Parts Discussed in Thread: CC3200, SYSBIOS

I'm using CC3200 with SimpleLink + TI-RTOS on CCS6. I have a timer interrupt handler which fires every 500ms.  Within this handler, I need a brief sleep where I'm polling on a device status in a count-limited loop. I want to give up CPU in small chunks of say 5ms when my device hasn't met the loop termination condition. For this, I am calling osi_Sleep( 5 ) which delegates to Task_Sleep( ).

Now, my questions:

Q1. When the Task scheduler of TI-RTOS is in a disabled state, it is certainly _not_ safe to call osi_Sleep( ) in this manner.  The application aborts with a runtime exception:

ti.sysbios.knl.Task: line 524: assertion failure: A_sleepTaskDisabled: Cannot call Task_sleep() while the Task scheduler is disabled.
xdc.runtime.Error.raise: terminating execution

I want to avoid disgraceful termination. How can I check whether the Task scheduler is enabled or not? This seems to be a race condition of the timer interrupt arriving before the OS itself has taken control of the CPU (through osi_start( )). I would like to fall back to spin wait using UtilsDelay(.) if the scheduler is disabled, or have the interrupt disabled until the OS has taken control. How can I do that?

Q2. Is it safe to call Task_Sleep( ) from within the timer interrupt handler, in general (apart from the above) ?


Thanks for reading.

  • From the TI-RTOS documentation:

    Task_sleep
    Delay execution of the current task
    Void Task_sleep(UInt32 nticks);
    [...]
    CONSTRAINTS
    Task_sleep cannot be called from a Swi or Hwi, or within a disable / restore block.
    [...]

    Is there any reason your HWI can't wake up a task to do the polling/sleep loop?

  • Thanks for pointing this out. I should have RTFM first.

    Robert Cowsill said:

    Is there any reason your HWI can't wake up a task to do the polling/sleep loop?

    No excuse, except that I was "only" patching up some existing code and  wasn't thinking in terms of creating a new task to handle the poll.
    I agree that what you suggest would be good design.
    BTW, this is also thought provoking... as to how "software rot" seeps in through "minor" patches like I was contemplating. Thanks!