Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to switch between two fixed tasks in Wanlix operating system

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today Xiaobian to share with you Wanlix operating system how to achieve the switch between two fixed tasks related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you have some gains after reading this article, let's learn about it together.

Starting from scratch, first realize the mutual switching of two fixed tasks to verify the switching function of operating system.

And then continue to add new features, from shallow to deep, step by step to enrich the operating system. The addition of each function is an independent phase.

What are the characteristics of Wanlix operating system?

Wanlix only provides the function of actively switching tasks. It is a non-preemptive operating system. It is relatively simple to write. It is a good choice as an introductory textbook for learning to write operating systems. This also makes it very compact, suitable for use in small embedded software systems with low hardware resources but requiring task switching.

How do I switch between two fixed tasks?

From the C language point of view, tasks are functions, but in the operating system, a task can be switched to other tasks, in fact, a function can be switched to other functions.

When the switch occurs, the 17 registers R0 to R15 and CPSR of the function 1 being executed are temporarily saved, and then the last saved values of the function 2 to be executed are restored to the 17 registers R0 to R15 and CPSR, so that the chip switches from function 1 to function 2.

When you want to switch from function 2 to function 1, save the 17 registers of function 2, restore the 17 registers of function 1, and the chip continues to run function 1 again. This inserts function 2 in the middle of function 1, which is a task switch, which is called "up and down switch." A series of functions called by the top-level parent function of function 1 or function 2 constitutes a task, regardless of whether it starts from the top-level parent function.

Schematic diagram of task switching

This switching can also be done between multiple tasks. As for when to switch and how to control the switching, this is what the operating system has to do.

Below we will follow this design idea to write the simplest switching process-2 functions constantly switching between each other to verify the correctness of the register backup and recovery principle during task switching.

In order to see the effect of task switching, we design two functions

TEST_TestTask1 and TEST_TestTask2, these two functions are endless loops, repeatedly executing the process of "Print Message-> Delay", we can confirm which function is executing by printing information,

The pseudocode is as follows:

Without function switching, such functions would loop endlessly as soon as they started executing, giving no chance for other functions to execute, and we would see only one function printing messages in a loop. If function switching can occur according to the switching principle described above, then we

What you should see is that these two functions are printed alternately in a loop.

In the main function, first initialize the hardware, then call WLX_TaskInit function to initialize the two tasks, and finally call WLX_TaskStart function to start task scheduling. These two tasks begin to execute alternately and print data to the serial port alternately.

End result:

The above is "Wanlix operating system how to achieve the switch between two fixed tasks" all the content of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report