Knowing Scheduler Status

nobody wrote on Wednesday, February 21, 2007:

Initializing and using LCD requires a lot of software delays, this is inefficient. Better way is to replace every SoftwareDelay() with vTaskDelay(t) or vTaskDelayUntil(t).

However vTaskDelay() can only be used when the scheduler is running.

I want to write a function Delay() such that, when it’s called when scheduler is not running, it uses software delay, otherwise it uses vTaskDelay().

If [scheduler is NOT running]

How can I know scheduler is running or not? The variable "xSchedulerRunning" is declared in task.c, so not accessible. Should I take xSchedulerRunning out and declare in task.h, or is there a cleaner way?

Thank you.

nobody wrote on Wednesday, February 21, 2007:

A couple suggestions:

1) Rather than make the variable global, include an access function in tasks.c such as xIsSchedulerRunning() that returns the variable.  This is a bit neater.

2) Most ports use a variable called ulCriticalNesting that is initialized to non zero, then set to zero when the first task starts.    It is not static so can be accessed from any file, but be careful as it will still be non zero from within a critical section even when the scheduler is running.


nobody wrote on Wednesday, February 21, 2007:

It is a fairly safe bet that if uxCriticalNesting (ulCriticalNesting?) is > 15 then the scheduler has not been started unless you are writing really screwy code.

nobody wrote on Tuesday, February 27, 2007:

Thx… i tried the first suggestion, it works… , and clean code too…

I didnt try the second suggestion because I just dont understand what ulCriticalNesting does. Thank you anyway