Characteristics of Zero Interrupt Latency in RTOS

Follow+Star Public Account Number to not miss exciting content

Author | Source: gitee

Friends who have worked on projects should know that in projects, using methods like disabling global interrupts to protect critical sections can lead to harmful consequences (loss of responsiveness, processing delays). For example, high-speed communication can result in frame loss, and high-speed capture can lead to lost pulse interruptions.

Some RTOS indiscriminately disable global interrupts and fail to provide core parameters such as “maximum system interrupt disable time,” making real-time performance a moot point. Statistics show that an increasing number of users have expressed dissatisfaction and have demanded real-time interrupt response from RTOS, hoping for high-priority interrupts to preempt in real-time with zero interrupt latency.

With the development of the times and the advancement of technology, zero interrupt latency has become possible… Thus, engineers have developed a zero interrupt latency RTOS: CosyOS.

Open-source address:

https://gitee.com/cosyos/cosyos

About CosyOS

CosyOS is an open-source real-time operating system from China that can achieve global disabling of global interrupts and zero interrupt latency, applicable to scenarios with high requirements for system real-time performance and interrupt response speed, from the classic 8051 core to the popular Arm Cortex-M core. CosyOS implements a highly object-oriented and user-friendly design with a romantic touch through macro definitions. With zero interrupt latency as its purpose, innovation as its guideline, and simplicity as its principle, CosyOS aims to be easy to use.

CosyOS – Real-time Operating Model

  • User Interrupt Layer-> Execution of local interrupt services-> Loading of suspended interrupt services

  • Kernel Service Layer

    • SysTick [minpri]-> Software RTC/timer counting-> Restore timing tasks-> Call timing hooks/tick hooks (execution of tick services)

    • PendSV [minpri]-> Execution of suspended interrupt services-> Task scheduling/switching

    • Task Critical Section [Disable SysTick/PendSV]-> Execution of task services

  • Task Layer

    • Taskmgr[maxpri]

    • Debugger[maxpri]

    • Starter[maxpri-1]

    • General User Task[maxpri-1 ~ minpri+1:1]

    • User Idle Task[minpri:0]

    • System Idle Task[minpri:0]

  • User interrupts preempt in real-time with zero interrupt latency

  • Preemptive scheduling for tasks of different priorities, time-slice round-robin scheduling for tasks of the same priority

Basic Principles of Zero Interrupt Latency

  • In the service layer, SysTick, PendSV, and task critical sections are mutually exclusive. In other words, the entire service layer is a large critical section (service layer critical section).

  • All kernel services (except local interrupt services) are executed in the “service layer critical section”, ensuring that the “operation flow” of services is not interrupted.

  • Local interrupt services use a mutual exclusion access mechanism.

Initial Experience

Now, let’s have a preliminary experience of the ease of use of CosyOS.

Example of creating a task in CosyOS:

Task Name Task Priority Task Stack Size Safe Runtime Private Message
demo1_task Level 1 128 bytes 0, infinite 0, no private message
demo2_task Level 2 256 bytes 9 time slices 3 parameters

Note 1:Safe runtime is a safety-critical technology of CosyOS that prevents any task from monopolizing or timing out the processor for too long. Note 2:Private message is a unique inter-task communication method in CosyOS that can be used to implement signals, events, messages, and other functions.

# Static creation of demo1_task
uCreateTask(demo1_task, 1, 128, 0, 0)
{
    uSendTaskMsg(demo2_task, "hello", 999, 3.14); // Send private message to demo2_task
    uDelay_ms(100); // Block delay for 100ms
    uEndTasking; // Last line of all task threads
}
# Dynamic creation of demo2_task
dCreateTask(demo2_task, 2, 256, 9, 3)(char *p, int a, float b)
{
if(uRecvTaskMsg(500)){ // Receive private message, timeout of 500 ticks, returns true if received successfully
/* Use private message (read p, a, b)*/
    }
    uEndTasking;
}
# Start hook
void start_hook(void)
{
    uStartTask(demo1_task, 0); // Start demo1_task and set the initial state of the task to ready
    uStartTask(demo2_task, 1); // Start demo2_task and set the initial state of the task to suspended
}

Are you impressed? Creating a task in CosyOS is so simple; just call the API and input the parameters, then directly write the task code (the loop is integrated, so users do not need to write it themselves). The next step is to start the task in the start hook, and the task can participate in scheduling and execution. CosyOS also innovatively uses task parameters as private messages, allowing the number, name, and type of private message parameters to be freely defined, just like ordinary function parameter definitions. Other applications also follow a similar principle, aiming to simplify processes and reduce the workload of developers, creating a warm and comfortable development environment.

Breakthrough Innovations

  • Achieved global disabling of all kernel interrupts (zero interrupt latency), ensuring real-time response of interrupts

  • Exclusive technology enables system services to be reentrant, allowing the 51 to completely eliminate reentrant stacks and significantly speed up

  • Highly optimized for the 51, making it vibrant and shining

  • 251 supports both MSP and PSP stack modes, where the PSP mode allows task switching efficiency to be equivalent to Cortex-M

  • Timing services (software timer interrupts), including timed interrupt tasks/hooks and timed query tasks/hooks, with priorities that can be flexibly configured by users

  • Software RTC, supports setting and getting time, can replace hardware RTC

  • Innovative flying message, extremely simple type, ultra-fast communication, a powerful tool for inter-thread communication

  • Innovative private message, freely defined, flexible and variable, convenient for passing multiple messages

  • Message mailbox, each mailbox can define its own data type upon creation, greatly enriching the forms of messages and facilitating inter-thread message passing

  • Message queue, supports static and dynamic queues, transmission modes support FIFO and LIFO, using efficient pointer referencing

  • Event flag groups, declaring flag groups while defining flag bits, different flag bits in different groups can have the same name, and access to flag groups and bits is achieved through group names and bit names, greatly facilitating the application of flag groups

  • Global variable access, supports safe access to global variables in any task and interrupt without worrying about reentrancy

  • Safety-critical technology, with multiple safety-critical technologies such as interrupt suspended service space isolation and safe runtime, ensuring high reliability

  • Task stack monitoring, with multiple monitoring measures to predict the risk of task stack overflow in advance

Conservative Approach

  • Completely open-source, royalty-free, deterministic RTOS

  • Task scheduling supports preemptive scheduling and time-slice round-robin scheduling

  • Unlimited number of user tasks, and each task can have 255 priority levels (0~254)

  • Simple and efficient code, with extremely low hardware resource usage, making CosyOS easily applicable to various small MCUs

  • Task manager, can monitor the operation of each task in real-time, helping developers quickly identify potential issues in designCharacteristics of Zero Interrupt Latency in RTOS—————————— CosyOS – Task Manager ——————————

Supported Kernels

CosyOS currently supports 8051, 80251, Cortex-M, and will gradually add support for other kernels in the future.

Compilation Environment

CosyOS is developed under the Keil C51, C251, and MDK-Arm compilers, with the best support for these. In the future, support for other compilers will be gradually optimized and adjusted.

File Description

Name Description
System CosyOS kernel filesur_api.h: User APIsv_: System service filesos_: Other kernel files
Config CosyOS configuration filessyscfg.h: System configuration filemcucfg_: MCU configuration files
Hook CosyOS system hooksCosyOS has created six system hook functions for users, located in their respective files, allowing users to write code directly.

———— END ————

Characteristics of Zero Interrupt Latency in RTOS

● Column “Embedded Tools”

● Column “Embedded Development”

● Column “Keil Tutorials”

● Selected Tutorials from the Embedded Column

Follow the public account and reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

Click “Read the Original” to see more shares.

Leave a Comment