Sirius RTOS is a multitasking operating system capable of concurrent task execution. These tasks function similarly to threads within a single process environment. Each task maintains its own private stack for local variable storage, while global data remains accessible to all tasks across the system.
A task exists in one of three primary states: running, ready, or blocked. At any specific moment, the CPU executes only one task, which is designated as being in the running state. The illusion of simultaneous execution is maintained through rapid context switching. The scheduler allocates a CPU time slice to tasks in the ready state. Tasks in the blocked state are ineligible for execution as they await a specific event or signal to transition back to the ready state. Task states are dynamic and transition based on system object operations and kernel events.
Tasks are themselves system objects and thus possess signaled or non-signaled states. A task remains in the non-signaled state throughout its lifecycle until it is terminated. Upon termination, the task object transitions to the signaled state, and any tasks waiting on that task object are immediately resumed.
As system objects, tasks can be initialized at any time: during system boot, within an interrupt service routine, or by another active task. A new task is identified by a handle returned by the osCreateTask function. The entry point for the task is defined during creation via a startup routine, which is a standard C function of the TTaskProc type.
Task creation requires the definition of several parameters, including the startup routine address, priority, and stack size. If the stack size is specified as 0, the kernel assigns a default size defined by the OS_DEFAULT_TASK_STACK_SIZE constant, which is typically 512 bytes.
A task naturally concludes its execution by returning from its startup routine using a standard C return statement. Alternatively, a task may self-terminate at any point by calling osExitTask. If OS_TERMINATE_TASK_FUNC is enabled, a task can be forcibly terminated by another task or an interrupt handler using the osTerminateTask function.
Upon finishing, a task provides an exit code to the system. This code is passed either via the return instruction or as an argument to osExitTask. If the task is forcibly ended via osTerminateTask, the exit code is automatically set to ERR_TASK_TERMINATED_BY_OTHER. When OS_TASK_EXIT_CODE_FUNC is active, the osGetTaskExitCode function may be used to retrieve this value.
When a task performs operations on itself (such as adjusting its own priority or suspending), it must provide its own handle. Since tasks created dynamically may not have immediate access to their assigned handle variable, the osGetTaskHandle function is provided for self-retrieval. This feature is available only when OS_GET_TASK_HANDLE_FUNC is set to 1.
During task termination, the kernel automatically releases all critical sections owned by the task and marks them as abandoned. If OS_ALLOW_OBJECT_DELETION is enabled, all objects opened by the task are also closed.
The system always executes the task with the highest priority among those in the ready state. Priorities are assigned during creation, ranging from 0 (highest priority) to the value specified by OS_LOWEST_USED_PRIORITY. To optimize memory consumption, this constant should be set to the lowest priority actually utilized by the application (within the range of 0 to 254). Task priorities can be modified at runtime using osSetTaskPriority and retrieved via osGetTaskPriority, provided that OS_TASK_PRIORITY_FUNC is enabled.
If multiple ready tasks share the same priority level, the scheduler manages them through Round Robin scheduling, assigning each a short CPU time slice known as a time quantum. While the scheduler defaults to a single quantum per task, you may increase this for computationally intensive tasks using osSetTaskQuantum. Valid quantum values range from 1 to 255. The current quantum settings can be inspected using osGetTaskQuantum if OS_TASK_QUANTUM_FUNC is active.
When the OS_SUSP_RES_TASK_FUNC configuration is enabled, the osResumeTask and osSuspendTask functions become available. These permit the suspension or resumption of a task's execution from another task or an interrupt handler. A task may also suspend its own execution, in which case it stops immediately and the scheduler selects the next eligible task to run.
If the OS_GET_TASK_STAT_FUNC constant is set to 1, the system provides the osGetTaskStat function. This utility allows developers to obtain the calculated CPU load for a specific task. The sampling rate for these statistics is governed by the OS_STAT_SAMPLE_RATE constant, which defaults to 100 system time units.