OsHndlT OsNewTask( UInt8T priority );
Function OsNewTask() should be called by the client application to create a new task. The function argument must be a value from the enumeration OsPriorE and represents the priority assigned to the task (high, medium, low or idle). If the value is out of range, it is quietly fixed up to the lowest priority (idle). If successful, the function returns a handle to the new task. If the function fails, for example due to the exhaustion of task resources, it returns OsHndl_NONE.
The example below shows the creation of a new task and the binding to it of a task function. The task is assigned medium priority. The task handle is stored in variable task and then checked for validity before continuing.
OsHndlT task;
task = OsNewTask( OsPrior_MEDIUM );
if ( task != OsHndl_NONE )
OsTaskBindFunction( task, MyTask );
Task handles are small integers in the range 1 to some limit defined by the build configuration of ECROS. Clients can elect to not use API function OsNewTask() and instead define task handles as constants at compile time. This may result in a slight improvement in program efficiency. However, mixing run-time and compile-time establishment of task handles is not recommended. Obtaining a handle to a task with OsNewTask() when it has already been made ready, for example, will crash ECROS.