Three Common Architectures in Embedded Software Development

Click the image below to searchInternet of Things to get many practical IoT projects prepared for you.

Three Common Architectures in Embedded Software Development
Microcontroller programs are familiar to everyone, but few actually consider the architecture. With the increasing number of programs being developed, architecture is very necessary.
The architecture of applications can be roughly categorized into three types:
1. Simple front and back sequential execution programs. This method is commonly used by most people, without needing to think about the specific architecture of the program; applications can be written directly through execution order.
2. Time-slice polling method. This method lies between sequential execution and operating systems.
3. Operating system. This method is probably the highest realm of application program writing.
1. Program Framework Design
1. Front and back sequential execution method
This is a commonly used program framework design scheme for beginners. It does not require 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 you have written through a while(1){} or for(;;){} loop, and generally does not consider the execution time required for each function, with most functions having some level of millisecond-level delay waiting.
Advantages: For beginners, this is the easiest and most intuitive program architecture, with clear and simple logic, suitable for software development with simple logic and relatively low complexity.
Disadvantages: Low real-time performance, as each function has some level of millisecond-level delay. Even 1ms can cause different intervals between function executions. Although this can be mitigated by using timer interrupts, the prerequisite is that the time taken by the interrupt execution function must be short. When the program logic complexity increases, it can lead to confusion for later maintenance personnel, making it difficult to clarify the program’s operating state.
2. Time-slice method
This is a program architecture design scheme that lies between the front and back sequential execution method and the operating system. This design scheme can help embedded software developers reach a higher level. When encountering the following points in the embedded software development process, this design scheme can be said to be 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, but have intervals (for example, buttons generally require software debouncing. Beginners typically delay for about 10ms before making a judgment, but this wastes CPU resources significantly, as the CPU can handle many other tasks during this time).
There are certain real-time requirements.
This design scheme requires the use of a timer, generally set to 1ms (the timing can be set freely, but if the interrupts are too frequent, efficiency will be low; if the interrupts are too long, real-time performance will be poor). Therefore, the execution time of each task function must be considered, and it is recommended not to exceed 1ms (optimizing the program to shorten execution time is best; if optimization is not possible, it must be ensured that the execution cycle of the task is much longer than the time taken by the task).
Additionally, there should be no millisecond-level delays in the main loop or task functions.

Three Common Architectures in Embedded Software Development

The following introduces two different implementation schemes, targeting friends who have no concept of function pointers and those who wish to learn further.
1. Design method without function pointers

Three Common Architectures in Embedded Software DevelopmentThree Common Architectures in Embedded Software DevelopmentThree Common Architectures in Embedded Software Development

2. Design method with function pointers

Three Common Architectures in Embedded Software DevelopmentThree Common Architectures in Embedded Software DevelopmentThree Common Architectures in Embedded Software DevelopmentThree Common Architectures in Embedded Software Development

3. Operating System
The Embedded Operating System (EOS) is a versatile system software that was primarily used in industrial control and defense systems in the past. For microcontrollers, commonly used preemptive operating systems include UCOS, FreeRTOS, RT-Thread Nano, and RTX (other operating systems like Linux are not suitable for microcontrollers).
In terms of task execution, the operating system has no excessive requirements on the time taken for each task. It requires setting the priority of each task, and when a high-priority task is ready, it will preempt a low-priority task. The operating system is relatively complex, so it is not detailed here.
About how to choose the appropriate operating system (comparative characteristics of uCOS, FreeRTOS, RTThread, RTX, etc.):
uCOS: There is abundant information available online, making it very suitable for learning, but it requires payment for product use.
FreeRTOS: It is free to use, so many products use it.
RT-Thread: A domestic IoT operating system with a rich set of components, also free. Documentation can be found at the RT-Thread documentation center.
RTX: A royalty-free, deterministic real-time operating system designed for ARM and Cortex-M devices.
Here’s a comparative image found online:

Three Common Architectures in Embedded Software Development

4. Conclusion
From the comparison above, it can be seen that the time-slice polling method has significant advantages. It combines the benefits of both the front and back sequential execution method and the operating system. The structure is clear, simple, and very easy to understand, making it a commonly used microcontroller design framework.
This article is reproduced from: https://blog.csdn.net/an520_/article/details/124877026

Three Common Architectures in Embedded Software Development

Recent Courses Available:
C Language Programming | Comprehensive C++ for Beginners | QT Development | AI Image Processing | Advanced Linux Programming | Advanced Linux Network Programming | Database + BS Development | 5G IoT Engineering Development

Leave a Comment

×