An Embedded Operating System Based on Priority Cooperative Scheduling

1. Introduction to QuarkTS

An Embedded Operating System Based on Priority Cooperative Scheduling

GitHub link: https://github.com/kmilo17pet/QuarkTS

Open Source License: MIT license

QuarkTS is an open-source embedded operating system designed to provide a modern development environment for small embedded applications, helping developers build stable and predictable event-driven multitasking software. Its features include:

  • Priority Cooperative Scheduling: Tasks manage their own lifecycle, avoiding the complexities brought by preemption and reducing reentrancy issues.

  • Time Control: Provides timed tasks and software timers for time-related operations.

  • Inter-task Communication Mechanisms: Offers mechanisms such as queues, notifications, and event flags for effective communication between tasks.

  • State Machine Support: Provides layered state machine support to simplify the implementation of complex logic.

  • Coroutines: Supports coroutines to enhance code efficiency and simplify concurrent programming.

  • AT Command Line Interface: Offers a simple command-line interface for debugging and interaction.

  • Safe and Reliable: Adheres to MISRA C 2012 and CERT coding standards, and undergoes multiple static analysis checks to ensure code safety and reliability.

2. Priority Cooperative Scheduling

Priority cooperative scheduling is a task scheduling strategy where tasks manage their own lifecycle and switch tasks at points specified by the programmer. This scheduling method avoids common complexities in preemptive scheduling, such as resource contention, deadlocks, and priority inversion.

In priority cooperative scheduling, each task has a priority, but tasks are not forcibly interrupted by external events or expiration of time slices.

Instead, tasks voluntarily relinquish the CPU upon completing their current operation or reaching a programmer-specified switching point, transferring control to other tasks. This method makes task switching more controllable and predictable.

Characteristics:

  • Reduced Reentrancy Issues: Since tasks are not arbitrarily interrupted by others and switch only at allowed points, reentrancy issues common in concurrent programming are reduced.
  • Simplified Resource Sharing: Resource contention issues between tasks are easier to manage because task switching is controllable.
  • Avoid Deadlocks: Cooperative scheduling avoids common deadlock issues present in preemptive scheduling since task switching is deterministic.

Other common task scheduling strategies include:

Preemptive Scheduling

Preemptive scheduling is a task scheduling strategy where tasks can be forcibly interrupted by external events (such as interrupts) or time slice expiration and taken over by higher-priority tasks.

Characteristics:

  • Fast Response Speed: High-priority tasks can immediately preempt the CPU, ensuring quick responses to urgent events.
  • Resource Contention: Since tasks can be preempted, additional synchronization mechanisms are needed to manage resource contention.
  • High Complexity: Preemptive scheduling increases system complexity, as it requires consideration of context saving and restoring during task switching, as well as priority inversion issues.

Time-Slice Scheduling

Time-slice scheduling is a special type of preemptive scheduling strategy where each task is allocated a fixed-length time slice. When a task completes its time slice, it is forcibly interrupted and control is transferred to the next ready task, regardless of whether it has finished.

Characteristics:

  • Fairness: By allocating time slices to each task, it ensures that all tasks have an opportunity to access CPU resources.
  • Context Switching Overhead: Due to frequent task switching, there is additional overhead for context saving and restoring.
  • Suitable for Multi-tasking Environments: Time-slice scheduling is particularly suitable for multi-user systems that need to handle multiple tasks simultaneously.

Comparison

Priority Cooperative Scheduling Preemptive Scheduling Time-Slice Scheduling
Task Switching Programmer Controlled External Events or Time Slice Expiration Time Slice Expiration
Reentrancy Issues Reduced Increased Increased
Resource Sharing Simplified Complex Complex
Deadlocks Avoided Possible Possible
Response Speed Medium (Depends on Programmer’s Design) Fast Fast (But Limited by Time Slice Length)
System Complexity Low High Medium (Requires Management of Time Slices and Context Switching)
Fairness Uncertain (Depends on Programmer’s Design) Uncertain (Depends on Priority Allocation) High

Priority cooperative scheduling, preemptive scheduling, and time-slice scheduling each have their advantages and disadvantages.

Priority cooperative scheduling is suitable for systems that need to simplify resource sharing and avoid deadlocks, but its response speed may not be as fast as preemptive scheduling.

Preemptive scheduling is suitable for systems that require quick responses to urgent events, but it increases system complexity and resource contention issues.

Time-slice scheduling provides a fair way to allocate CPU resources, suitable for multi-tasking environments, but it introduces additional context switching overhead.

3. QuarkTS Application Scenarios

The design goal of QuarkTS is to leverage a compact, simple, yet robust implementation to fulfill its stated functions, making it suitable for resource-constrained microcontrollers, where full real-time operating systems are excessive and integrating them would add unnecessary complexity to firmware development.

Additionally, with state machine support, coroutines, time control, and inter-process communication primitives, QuarkTS provides a modern environment for building stable and predictable event-driven multitasking embedded software.

Its modularity and reliability make this operating system an ideal choice for efficiently developing a range of applications on low-power devices, including automotive control systems, monitoring, and IoT fields.

An Embedded Operating System Based on Priority Cooperative Scheduling

END

Source: Embedded Mixed Bag
Copyright belongs to the original author. If there is any infringement, please contact for deletion..
Recommended Reading
I Don’t Want to Do This Project Again!
How Fast Can GPIO Toggle?
Could the Ingenious kfifo Crash the MCU?
→ Follow to Stay Updated ←

Leave a Comment