Common Software Architectures in Embedded Development

Common Software Architectures in Embedded Development

Common Software Architectures in Embedded Development

Microcontroller programs are not unfamiliar to everyone, but very few truly consider architecture. With the continuous increase in program development, architecture is very necessary.

1. Time-Slice Polling Method

A program architecture design scheme between front and back sequential execution and operating systems. This design scheme needs to help embedded software developers to reach a higher level. In the embedded software development process, if the following points are encountered, this design scheme can be said to be the best choice, suitable for more complex embedded systems;

The current demand design does not require an operating system at all.

Task functions do not need to be executed all the time, there is an interval (for example, buttons generally require software debounce; beginners typically delay 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 needs to use a timer, generally set to 1ms (the timing time can be set freely, but if the interrupts are too frequent, the efficiency is low; if the interrupts are too long, the real-time performance is poor). Therefore, it is necessary to consider the execution time of each task function, which should not exceed 1ms (optimizing the program to shorten execution time is best; if optimization is impossible, then the execution cycle of the task must be much greater than the time consumed by the task). Additionally, there should not be any millisecond-level delays in the main loop or task functions.

Common Software Architectures in Embedded Development

Next, two different implementation schemes will be introduced, one for friends without function pointer concepts 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) is a widely used system software, primarily applied in industrial control and national defense systems in the past. For microcontrollers, commonly used ones 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 for the time consumed by each task. It requires setting the priority of each task, where high-priority tasks will preempt low-priority tasks when they are ready; the operating system is relatively complex, so it is not detailed here.

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

  • uCOS: Abundant 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 wealth of components, also free; see: RT-Thread Documentation 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 Software Architectures in Embedded Development

3. Front and Back Sequential Execution Method

This is a common 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 for the system are not high; after initialization, it continuously calls the functions it has completed through a while(1){} or for(;;){} loop, and does not consider the time required for each function execution. In most cases, there are some millisecond-level delays waiting in the functions.

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

Disadvantages: Low real-time performance; since each function has some millisecond-level delays, even 1ms can cause different intervals for other functions’ execution, although it can be handled through timer interrupts, the premise is that the time taken by the interrupt execution function must be short. When the program logic complexity increases, it will confuse later maintenance personnel, making it difficult to clarify the program’s operating 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

Common Software Architectures in Embedded Development

Common Software Architectures in Embedded Development

Screenshots of some e-books

Common Software Architectures in Embedded Development

Common Software Architectures in Embedded Development

Leave a Comment

×