Do Embedded Development Need Architectural Design?

Source | IOT IoT Town

This may be a controversial topic, whether it is necessary or not, still needs to be combined with the actual situation.

What is architectural design

1. Understanding the concept of architectural design
I believe most of the students reading this article are engaged in embedded development, and everyone must have this impression: many architectural design positions on recruitment websites are targeted at the Web direction, but very few see recruitment for embedded system architects.
My understanding is that there are roughly two reasons:
(1) Web Development: A Hundred Schools of Thought Contend, No Unified Standards or Leaders
In recent years, thanks to the development of mobile Internet, the demand for front-end and back-end development positions has increased significantly, and various frameworks have emerged one after another.
How to use these frameworks to provide users with high-performance services does not have a unified standard, thus leading to a hundred schools of thought contending, and corresponding designer positions have emerged one after another.
Do Embedded Development Need Architectural Design?
(2) Embedded Development: Linux is the Only Choice
In the development of embedded systems, there is almost no room for choice in operating systems; most are ARM+Linux combinations.
At the Linux operating system level: those experts have already designed the kernel and driver layer perfectly, and developers rarely need to make a lot of modifications.
At the application level: developers can simply implement the functions defined in the specifications if they have no other aspirations.
As for the bosses, they only care about whether the product functions can be implemented normally, and do not consider aspects such as portability, scalability, execution efficiency, etc.
Even if the product needs to be updated, developers can simply re-implement it; after all, it only needs to work.
Do Embedded Development Need Architectural Design?
2. The Importance of Architectural Design in Embedded Systems
Let me tell a small story.
A colleague wrote a program for a microcontroller product for a client, and later, after the colleague left, handed over the code to me.
This product had a small function that needed to be modified, and I happened to be handling another project at that time, so with the boss’s permission, I sent the source code to the client, asking them to modify it themselves.
Because they received the source code, the client was certainly very happy, as they could develop other similar devices themselves as long as they understood the code.
After a while, I asked the client: How’s the function modification for that product going?
He said: Not resolved yet; I lost the code you gave me, and it’s very frustrating; I’m rewriting the code from scratch now.
Do Embedded Development Need Architectural Design?
This story is true.
Code is made up of characters; some code looks pleasing, while some code makes you question life.
Code without architectural design guidance has the following drawbacks:
(1) Code cannot be reused, and porting is very troublesome.
(2) When requirements change, the code cannot be quickly adjusted.
(3) Regarding existing code: developers are afraid to change and do not want to change; a single change can affect everything.
(4) Debugging bugs is very painful.
Do Embedded Development Need Architectural Design?
On the contrary, if the architectural design is good, it benefits all aspects:
For the project:

(1) Project cycle is controllable

(2) Code readability is good

(3) Functions are extensible

(4) Modifying a single module will not affect other functions

(5) Parallel development

(6) Unit testing is convenient

For developers:
(1) Saves development time
(2) Global perspective enhances the ability to develop large projects
(3) Easy and quick debugging

How to conduct architectural design

1. Design Document
Once you enter the programming field, everyone knows to aim for high cohesion, low coupling, and design by modules and layers.
But how exactly should it be done?
How to do things well within the specified project cycle and not make yourself too tired?
How to lay a good foundation for future maintenance?
…..
These questions might be well planned at the beginning of the project.
However, during execution, people tend to become lazier and deviate more and more from the predefined direction.
My suggestion is:
No matter the size of the project or the length of the project cycle, there must be a design document. The level of detail in the design document should be flexibly grasped according to the actual situation of the project.
The architectural design should be reflected in the design document. During implementation, strictly follow the requirements in the document.
To aim high is to achieve the middle; to aim for the middle is to achieve the lower.
2. Physical Model of Program Files
(1) Layered Design
Business Layer
Functional Module Layer
Driver Layer
(2) Modular Design,
Dividing modules based on functions
Modules interact through API interface functions
Design flexible API interface functions
3. Choice of Processes and Threads
In embedded systems, to implement product functionality, multiple processes can cooperate to complete it, or multiple threads can be used; this choice does not have a fixed standard and depends on the specific situation of the project.
My general practice is:
If the product functionality is not complex, try to use multithreading;
If the product involves many functions, then put strongly related modules into independent processes.
Do Embedded Development Need Architectural Design?
(1) Using Processes
Each module compiles independently and will not affect each other.
If issues like Segment Fault occur, it is easy to locate the culprit.
Convenient for distributed deployment.
Code security: Apart from integrators, others only need to clone their responsible module code without permission or needing to access others’ code.
However: Need to consider inter-process communication issues, e.g., IPC calls, socket communication, buses. (I generally use an MQTT bus to connect all communication modules within the local system)
(2) Using Threads
Creating threads has low costs.
Threads share global variables (from another perspective, this is also a disadvantage).
Modules call conveniently since function addresses are directly visible.
4. API Design
A module can be seen as a black box; given an input, it will return a determined result or execute a determined function,
Modules only need to define this API interface function.
As for how the module is implemented internally, everyone shows their skills.
Additionally, if you are an API designer, be sure to make the caller feel comfortable using it. Just like when you hand a pair of scissors to someone, you must give them the handles.
Do Embedded Development Need Architectural Design?
Another experience is, at the beginning of project design, try not to make the API function design too rigid, as it can easily trap oneself.
For example:
(1) You can design a variable with char *, using a JSON format string to pass data of any length and type.
(2) You can design a variable with void * to pass the address of any data type; this function has been used wonderfully in many projects, for example: the BREW platform of Qualcomm phones long ago, and the ZWave platform in smart homes.
5. Directory Structure Design
This part is easy to understand; files with different responsibilities should be stored in corresponding directories: header files, library files, executable files, related documents. If this part is not organized well, when you hand the project over to other colleagues, they will definitely be cursing you in their hearts: F-U-C-K Y-O-U!
6. Design of Compilation Scripts (Build Tools)
When we receive an embedded project, after determining the plan, the platform on which the program runs is certain; most of the time, it is embedded Linux or some variants.
During the development phase, I have seen some developers cross-compile the code every time they debug a function and then place it, then mount it remotely via NFS or copy it via SCP to execute on real devices. It looks exhausting to me.
Actually, you can compile a version for different platforms in the compilation script.
For example: When developing a product using Ubuntu, as long as the x86 platform can simulate product functionality, directly compile the x86 version.
When all function points are tested OK on the x86 platform, then put them all into the real embedded system for integration testing; this can save a lot of time.

Demo Description

1. Introduction
This demo is extracted from a smart home project, only reflecting the design of various functional modules, with no actual functionality implemented in the functions, merely to showcase the design process.
2. Code Acquisition
https://pan.baidu.com/s/1B3F9byydXeNWdtgYEEQNLg
Password: 3a9p
It can be directly compiled and executed under Ubuntu 16.04.
3. System Architecture Diagram
Do Embedded Development Need Architectural Design?
4. Directory Structure
Makefile: Compilation script
application: Business layer
module: Functional module layer
driver: Hardware driver layer
5. Execution Sequence Demonstration
The orange arrows in the diagram indicate a control command sent from the cloud.
After receiving the command, the business layer parses the command and sends it to the Control module.
The Control module parses the specific command again and sends it to the ZigBee device while logging it.
Do Embedded Development Need Architectural Design?
Disclaimer:This article’s material comes from the internet, and copyright belongs to the original author. If there are copyright issues, please contact me to delete.
———— END ————
Do Embedded Development Need Architectural Design?
● Selected Tutorials from the Embedded Column
● Selected Summary | ST Tools, Download Programming Tools
● Selected Summary | Embedded Software Design and Development
● Selected Summary | STM32, MCU, Microcontroller
Welcome to follow my public account, reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.
Welcome to follow my video account:

Do Embedded Development Need Architectural Design?

Click “Read Original” to see more shares, welcome to share, collect, like, and view.

Leave a Comment

×