Common Code Architectures in Embedded Software

Click on the blue text above Tangsi Laboratory

Get more automotive cybersecurity news

Everyone is familiar with microcontroller programs, but not many truly understand the architectures used. As program development increases, architecture becomes essential.

1. Time-Slice Polling Method

A program architecture design scheme that lies between sequential execution methods and operating systems.

This design scheme should help embedded software developers reach new heights. In the embedded software development process, if the following points are encountered, this design scheme can be considered the optimal choice, suitable for more complex embedded systems:

Current design requirements do not necessitate the use of an operating system.

Task functions do not need to be executed constantly, and there are intervals (for example, buttons, which generally require software debouncing. Beginners usually delay for about 10ms before judging, but 10ms greatly wastes CPU resources; during this time, the CPU can handle many other tasks).

Real-time performance has certain requirements.

This design scheme requires the use of a timer, generally set to 1ms (the timing can be arbitrary, but if interrupts are too frequent, efficiency decreases; if interrupts are too long, real-time performance is poor). Therefore, consideration must be given to the execution time of each task function, which should not exceed 1ms (optimizing the program to shorten execution time is best; if optimization is not possible, the execution cycle of the task must be much greater than the time taken to execute the task), and it is required that there should be no millisecond-level delays in the main loop or task functions.

Common Code Architectures in Embedded Software

Below are two different implementation schemes, one for friends who are unfamiliar with function pointers and another for those who want to learn more.

1. Design Method Without Function Pointers

Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software

2. Design Method With Function Pointers

Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software

2. Operating Systems

The embedded operating system EOS (Embedded Operating System) is a versatile system software that was primarily used in industrial control and defense systems in the past.

For microcontrollers, commonly used operating systems include UCOS, FreeRTOS, RT-Thread Nano, and RTX, among other preemptive operating systems (other operating systems like Linux are not suitable for microcontrollers).

In terms of task execution, the operating system does not have excessive requirements on the time consumed by each task; it needs to set the priority of each task. When a high-priority task is ready, it preempts low-priority tasks; the operating system is relatively complex, so it will not be detailed here.

Regarding how to choose the appropriate operating system (comparison of features of RTOS such as uCOS, FreeRTOS, RT-Thread, RTX):

  • uCOS: Rich online resources, very suitable for learning, but requires payment for use in products.

  • FreeRTOS: Free to use, hence widely used in many products.

  • RT-Thread: A domestic IoT operating system with a wealth of components, also free, documentation: RT-Thread Document Center.

  • RTX: A royalty-free, deterministic real-time operating system designed for ARM and Cortex-M devices.

Here is a comparison chart from the internet:

Common Code Architectures in Embedded Software

3. Front and Back Sequential Execution Method

This is a commonly used program framework design scheme for beginners, which does not require too much consideration; the code is simple, or the overall real-time and concurrency requirements of the system are not high; after initialization, it continuously calls the functions it has written through while(1){} or for(;;){} loops, and does not consider the time required for each function execution, most of the time, there are delays in the functions.

Advantages: For beginners, this is the easiest and most intuitive program architecture, with clear logic, suitable for simple logic and low complexity software development.

Disadvantages: Low real-time performance, as each function has some milliseconds of delay, even 1ms can cause different execution intervals for other functions, although this can be mitigated by using timer interrupts, but the premise is that the time taken for the interrupt execution function must be short. When the complexity of the program logic increases, it can lead to confusion for maintenance personnel, making it difficult to clarify the program’s operating state.

Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software

Source:https://blog.csdn.net/an520_/article/details/124877026

Common Code Architectures in Embedded Software
Common Code Architectures in Embedded Software

Register Now

Tangsi Laboratory AutoSec Intelligent Vehicle Security Attack and Defense Training Course, November, Shanghai

Common Code Architectures in Embedded Software

Leave a Comment