Common Software Architectures in Embedded Development

Common Software Architectures in Embedded Development

For microcontroller programs, everyone is familiar, but few truly consider the architecture. As program development continues to increase, architecture becomes essential.

1. Time-Slice Polling Method

A program architecture design scheme that lies between front and back sequential execution methods and operating systems. This design scheme should help embedded software developers reach a higher level. If the following points are encountered during embedded software development, then this design scheme can be considered the optimal choice, suitable for more complex embedded systems;

Current demand design requires that there is absolutely no need to use an operating system.

Task functions do not need to be executed all the time, there are intervals (for example, button presses, which generally require software debouncing. The common practice for beginners is to delay about 10ms before judging, but 10ms greatly wastes CPU resources. During this time, the CPU can handle many other tasks).

Real-time requirements are present.

This design scheme requires the use of a timer, generally set to 1ms (the timing can be set arbitrarily, but if the interrupts are too frequent, efficiency is low; if the interrupts are too long, real-time performance is poor). Therefore, it is necessary to consider the execution time of each task function, which should not exceed 1ms (if the execution time can be optimized through programming, that would be best; if it cannot be optimized, then the execution cycle of the task must be much greater than the time taken by the task). At the same time, there should be no millisecond-level delays in the main loop or task functions.

Common Software Architectures in Embedded Development

Below are two different implementation schemes, one for friends without the concept of function pointers and the other for those who want to learn further.

1. Design Method Without Function Pointers

Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development

2. Design Method With Function Pointers

Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development

2. Operating Systems

The embedded operating system EOS (Embedded Operating System) is a widely used system software. In the past, it was mainly applied in industrial control and national defense system fields. For microcontrollers, commonly used operating systems include UCOS, FreeRTOS, RT-Thread Nano, and RTX, among various 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, and when a high-priority task is ready, it will preempt the low-priority task. The operating system is relatively complex, so it is not detailed here.

About how to choose a suitable operating system (comparison of uCOS, FreeRTOS, RTThread, RTX, etc.):

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

  • FreeRTOS: Free to use, so many products are using it.

  • RT-Thread: A domestic IoT operating system with a rich set of components, also free. Documentation: RT-Thread Documentation Center.

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

Borrowing an online comparison chart:

Common Software Architectures in Embedded Development

3. Front and Back Sequential Execution Method

This is a commonly used program framework design scheme for beginners, where not much consideration is needed. 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 completed through a while(1){} or for(;;){} loop, and it generally does not consider the time required for each function to execute. In most cases, there are some millisecond-level delays waiting within the functions.

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

Disadvantages: Low real-time performance. Due to the existence of millisecond-level delays in each function, even 1ms can cause different execution intervals for other functions. Although it can be done through timer interrupts, the premise is that the time taken for the interrupt execution function must be short. As the complexity of the program logic increases, it can lead to confusion for later maintenance personnel, making it difficult to clarify the program’s running state.

Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development
Common Software Architectures in Embedded Development

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

This article is sourced from the internet, free to convey knowledge, and the copyright belongs to the original author. If there are any copyright issues, please contact me for deletion.

Previous Recommendations

“Complete Guide to Embedded Linux Drivers”

Reply 1024 in the public account chat interface to obtain embedded resources

Leave a Comment

Your email address will not be published. Required fields are marked *