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.