1. Introduction to bare metal and FreeRTOS and introduction to FreeRTOS system

Table of contents

1. Introduction of bare metal and FreeRTOS

2. Introduction to FreeRTOS

1. Introduction of bare metal and FreeRTOS

What is the difference between them?

        Now there is such an event, I am playing King of Glory, suddenly my girlfriend sent me a message, these are two events

For bare metal systems it does this:

while(1)
{
    打游戏();
    回复消息();
}

        That is to say, reply to the girlfriend's message after playing the game. In this case, the girlfriend should be anxious. That is to say, if you play games, you ignore your girlfriend, and you have to hang up the game when you reply to your girlfriend’s message. You are in such a contradiction.

For the FreeRTOS system it is handled like this:

void main(main)
{
    /*创建打游戏任务*/
    xTaskCrete(打游戏)
    /*创建回复消息任务*/
    xTaskCreate(回复消息)
}

void 游戏(void)
{
    while(1)
    {
        打游戏();
    }
}

void 消息void()
{
    while(1)
    {
        回复消息();
    }

}

        That is to say, it will create two tasks, namely the game task and the message task. The game task is dedicated to replying messages, and the message task is dedicated to replying messages.

How does he run it?

        It will execute the game for 1 time slice. The size of 1 time slice is what we can set, that is, the clock beat of the tick timer. We set the interrupt once in 1ms in the code, and 1 time slice is 1ms, that is, Play the game for 1ms, immediately switch to the reply message, the reply message is also executed for 1ms, and then switch back to play the game for 1ms, so switching back and forth, the switching speed is very fast, from a macro perspective, it is like a clone, and their tasks are carried out at the same time The priority is the same, so that you can play the game for a while, reply to the message, and switch back and forth. Although you can only do one thing at a time, but the time is too short, it is the same from a human perspective.

        In the same scenario, assuming that Xiao Ming has a stomachache and needs to go to the hospital, what will the bare metal and RTOS do?

/*对于裸机系统而言*/
while(1)
{
    打游戏();
    回复消息();
    if(FLAG==1)
    {
        去医院();
        FLAG=0;
    }

}

        That is, I can only go to the hospital after playing the game and replying to the message, so that the disadvantages of the bare metal will be exposed.

/*FreeRTOS系统*/
void main(main)
{
    /*创建打游戏任务*/
    xTaskCrete(打游戏)
    /*创建回复消息任务*/
    xTaskCreate(回复消息)
    /*创建去医院任务*/
    xTaskCrete(去医院)//任务优先级
}

void 游戏(void)
{
    while(1)
    {
        打游戏();
    }
}

void 消息void()
{
    while(1)
    {
        回复消息();
    }

}

void 去医院(void)
{
    while(1)
    {
        去医院();
    }
}

        After the high-priority tasks are executed, the execution rights of the CPU will be released, that is, messages can be replied, and games can be played again, making full use of CPU resources.

Bare metal and RTOS features

        Bare metal: Bare metal is also called the front-end and background systems. The foreground system refers to the interrupt service function, and the background system refers to the large cycle, that is, the application program.

        1. Poor real-time performance (applications) are executed in turn

        2.delay empty wait, cpu does not execute code

        3. The structure is bloated (implementation functions are placed in an infinite loop)

        FreeRTOS features: it is a free real-time operating system, emphasizing real-time

        1. Divide and conquer, and implement functions are divided into multiple tasks.

        2. Delay function task scheduling makes full use of CPU resources.

        3. Preemptive, high-priority tasks preempt low-priority tasks.

        4. Task stack, each task has its own space.

        Note 1: Interrupts can interrupt any task

        Note 2: Tasks can have equal priority

2. Introduction to FreeRTOS

        First look at the name of FreeRTOS, which can be divided into two parts: "Free" and "RTOS". "Free" means free, free, and unconstrained. The full name of "RTOS" is Real Time Operating System. The Chinese name is Real-time operating system, it should be noted that RTOS is not a specific operating system, but a type of operating system, for example, µC/OS, FreeRTOS, RTX, RT-Thread, etc. are all RTOS-like operating systems . Therefore, as can be seen from the name of FreeRTOS, FreeROTS is a free real-time operating system. It can be said that RTOS is an indispensable skill in work.

        FreeRTOS is a free embedded real-time operating system, its features are as follows:

        Free and open source: used in commercial products, no potential commercial risks, no need to worry

        Can be trimmed: the core code of FreeRTOS is 9000+ lines, including 3 .c files

        Simple: easy to use and very portable

        Unlimited priority: There is no limit to task priority allocation, and multiple tasks can have the same priority. If it is software, its priority allocation is not limited. If it is hardware, it will be limited. If 2 single chips have 32 bits, other The priority can only be set to 32, the larger the number, the higher the priority, which is opposite to the 32 single-chip microcomputer.

        Preemption/coroutine/time slice: support preemptive, coroutine, time slice flow task scheduling

        You can check the official website for learning: https://www.freertos.org/, all in English, hey

Guess you like

Origin blog.csdn.net/zywcxz/article/details/131483532