In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of the method of writing the lightweight program architecture kernel of the embedded C language, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe that everyone will gain something after reading this article on the method of writing the lightweight program architecture kernel of the embedded C language. let's take a look at it.
1. Understand the concept and role of program architecture
When writing a single-chip microcomputer program, we often encounter the following situations
1. The function of the product requires many different delay effects, and the dead delay of delay can not be used, such as key detection and led different flicker effects.
2. As soon as there are more functions of the program, the whole brain is confused. I don't know how to integrate it.
3. People in different functional areas don't know what to do except to share global variables or arrays.
Real-time operating system rtos, ucos, linux system, are good program architecture, they provide developers with good real-time system, high reliability, strong portability and other guarantees. Engineers do not need to study replicated data structures and algorithms, such as task allocation, task scheduling, memory management, message mechanisms, etc., just need to learn to use the system.
two。 Understand the common program architecture of single-chip microcomputer
1. The traditional program architecture of sequential execution
Most of the time, single-chip microcomputer programs use while dead loop, and then execute various functions sequentially, this kind of program design is relatively simple.
# include int main () {keys = KeyScan (); while (1) {if (keys = = 1) {/ /}} return 0;}
The disadvantage is that it is only suitable for small projects, after the program is large, the logic must be very chaotic, real-time, stability, poor portability.
2. Real-time operating system
For example, ucos, rtos, users only need to transplant the system to run. The advantage of this architecture is that it is stable and real-time, and some even provide powerful functions such as graphic gui and network tcp/ip.
The disadvantage is that the occupation of memory resources is more serious, transplanting is more complex, if the application is not deep ploughing, the working principle of the system architecture will not be able to start. So this kind of system is generally aimed at large-scale projects, and some functions are needed, such as those with screens that need to do a lot of interfaces, or those with network communications.
3. Lightweight program architecture
The positioning of this program architecture can be applied to most of the low-end single-chip microcomputer, occupying less memory resources of single-chip microcomputer, about 1kb.
3. The Design idea of lightweight Program Architecture
It is mainly divided into two parts:
1. Program architecture, system kernel
2. Task communication
The system kernel is used for the unified allocation and management of tasks.
Task communication is the communication between different modules, such as data transmission between hardware layer and application layer, which is realized through callback function.
The focus of this paper is to write a system kernel code with task assignment and task scheduling. It can meet the characteristics of high portability, strong stability and good real-time performance.
4. The implementation principle of kernel code in program architecture
The kernel code is mainly used to assign tasks and task scheduling, and the task is the processing function of each functional module polling. To assign a task is to create a task and add each functional module processing function to the task management list.
Task scheduling is to regularly wake up and hibernate the tasks in the task list.
The wake-up call here is the call, and hibernation is to suspend the task and not let it execute.
The system kernel workflow of the program architecture:
Task initialization: including hardware initialization, such as gpio configuration, timer initialization, serial port initialization and so on. Then the task is created and the task execution function is initialized.
Task scheduling: the function of polling in our traditional while (1) loop, except that we provide a different time beat for each task and allow any task to go to sleep.
5. Master the kernel writing of lightweight program architecture
To put it bluntly, the system kernel is to write a task manager, through which the allowable state of the whole program can be controlled more flexibly, especially for products that need to do low power consumption.
The system kernel mainly completes the following tasks:
1. Task creation
2. Task scheduling
3. Task suspended
4. Task hibernation
Advantages:
1. Different clock beats can be provided for each task.
2. The execution status of each task can be controlled flexibly.
3. Higher real-time performance
4. The program flow is clearer.
5. More suitable for low power consumption
OS_System.c code and OS_System.h code
# include "OS_System.h" volatile OS_TaskTypeDef OS_ Task [OS _ TASK_SUM]; CPUInterrupt_CallBack_t CPUInterrupptCtrlCBS / * @ function name OS_CPUInterruptCBSRegister * @ description registering CPU interrupt control function * @ parameter pCPUInterruptCtrlCBS-CPU interrupt control callback function address * @ return value none * @ Note No * / void OS_CPUInterruptCBSRegister (CPUInterrupt _ CallBack_t pCPUInterruptCtrlCBS) {if (CPUInterrupptCtrlCBS = = 0) {CPUInterrupptCtrlCBS = pCPUInterruptCtrlCBS }} / * @ function name OS_TaskInit * @ describe system task initialization * @ Parameter No * @ return value No * @ Note none * * / void OS_TaskInit (void) {unsigned char i For (iTuno; I
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.