Work Hours
Monday to Friday: 8am – 6pm
Weekend: 10am – 2pm
“Modern” approach to embedded software.
I have reached the stage where it would be good to be able to monitor the progress of the track riding. I have a choice: pay for a commercial device, or develop something of my own, from components I already have.
Since my treasure box contains an epapier module with ESP32, I have a GPS module and an accelerometer rolling around somewhere, and I have a battery for the whole thing, I decided to assemble something of my own. This is also a good opportunity to improve on my embedded systems programming skills.
Let’s try to complete laptimer components:
So far, every embedded software project I’ve done has been fairly simple, because it has done relatively simple things.
This project, is designed to do several things at one time, plus it should be ready for development and present scientific value for me. So let’s abandon the Superloop architecture and learn something new.
The biggest issues I see with the traditional Superloop approach are:
So, how can embedded programming be approached to eliminate issues?
Looking back in the history of software, especially operating systems, problems very quickly emerged and with them – solutions.
RTOS (real-time operating system, RTOS), an operating system that was developed to meet the requirements imposed, in time to perform the desired operations. This is roughly the ’60s of the last century. This is when Rate-monotonic scheduling (RMS) was developed. It is a method of optimal scheduling in RTOS. It is used to schedule periodic tasks without synchronization between them. Very quickly, it was found to be not enough. Around the ’80s, RTOS began to be written so that communication between threads was possible and that they used the same range of shared data. This approach to RTOS required access coordination. This is because it enforces competitiveness in accessing and modifying data, in such a way that the data remains consistent and in a predictable state. Any synchronization of threads is time-consuming for the processor.
You can approach this in a completely different way, using Events. That is, Event-Driven Programming. Cloud programmers, you probably know something 😉 The first operating systems using Event-Driven Programming were further back in the ’80s. It really started at the time of the entry of the first GUIs, when we needed to synchronize mouse, keyboard and other input hardware with UI elements. There was a similar problem with synchronizing asynchronous network processes.
EDP, relies on a simple Event handler loop, which is the only one that enforces blocking synchronization.
It boils down to encapsulating threads so that they don’t share anything. The only communication between them is the exchange of messages through asynchronous Events.
The second important component of the application, is the State Machine. This allows us to at least get rid of some of the spaghetti code. The traditional state machine, is a description of the states that occur in the application and the transitions between them.