Use an example to explore the embedded software architecture design

First, emotion

The company nearly new tactics to a children's shoes do develop embedded software development, which is children's shoes from one of the listed companies in Shanghai out, because here we do not have enough, so he arranged to be responsible for a new product development, pre-let he is responsible for the accelerometer, NB-IOT, steering gear, external Flash function test, after the test is completed, ready to let him do a preliminary design of the product. Then he spent two weeks time to write us a summary of the design, to be honest, I saw the outline design, I think it is written by university graduates.

Architecture version of a
2.1 system architecture
system is divided into two layers: the hardware driver layer, the application layer.
2.1.1 hardware driver layer
hardware driver layer contains all the drivers onboard hardware resources needed for normal operation.
1) MCU initialization
2) the I2C data access
3) SPI data reading
4) initializes the accelerometer
5) Bluetooth module startup
6) BC95 module startup
7) starts communication module 485
2.2.2 Application Layer
1) Mcu operating mode switch
2) shake and tilt
3) data analysis
4) on / off lock
5) data transmission
6) historical data retention
after seeing a version of architecture, to be honest, the first time I see such a write architecture, is actually by serial number to write, read this to let others, especially awkward.  

Version two of the architectural design

After seeing architecture design two versions, though quite pleased, but we expect to achieve the desired, but also great a distance, the architecture design, mainly the following questions:

1. understanding of the architecture is not very clear, since it is designed to do architecture, it should on the whole, and not just limited to one module, or function inside.

2. Each level of understanding is also not very clear, for example, speak of MCU initialization, attributed to the hardware driver layer inside. MCU initialization, strictly speaking, be part of the process, and rather than drive. For example, start the computer is turned on, this attributed to hardware drivers which is definitely part of the irrelevant.

3. There is the start of each module, it can not belong to the hardware driver layer, are also part of the business process, and should not be part of the driver layer.

4. There is a write data bus, although the role of the drive is read, but not write data bus is written hardware drivers.

5. The system parameter initialization application layer, still belongs to the process.

6. The occurrence of the data analysis and data, which belong to a communication function, and should not be a separate independent, belonging to a single application.

 

After seeing here, to be honest, I was really surprised, stumped out of children's shoes from big business, the ability to do all this? From big business out of children's shoes, but also to pay the Lao Gao Lao Gao, stumped they do not know, wages in Kunming, are based on K to calculate it? In Kunming 8K can get paid to do the development of people, few. Then to 1W

Above, children's shoes were even less.

To be honest, we are the children's shoes, go to work, often read books, during the internship often read books, I do not know, would he find the strength, the heart can put so wide, there is no complete account of living , there is still time to see e-books. Of course, asked his blessing, my salary rose 6K finally, because the new salary is higher than the elderly,

Do live is still the same (not the same as a result I know), in order to take into account the old man's heart imbalance, so just give me wages. The leaders at the time of application for grant plus salary, but also specifically called me to the office, so I determined to watch her. .

 

Then, I let him go and change, I say to these changes, he then let's look at, what problems did? The results that I see him scratching, there are all kinds of sighing, and then I said, can not change.

Since it can not change, then I can only personally battle surgeon, after all, a colleague.

 

 Second, the basic framework of FIG.

Objective (1) architecture design

1, the application code logic clear, and avoid duplicate create the wheel.

2, if there is no good architecture, transplant would be a very painful thing, so a good architecture for easy software migration.

3, the maximum multiplexing.

4, low coupling high cohesion. 

 

(2) design ideas

How the hardware driver and a functional module into one package, then as a child building blocks, a module can quickly spliced ​​together to form a different model.

Our idea is embedded architecture comes from this, that feature a modular design, hierarchical design.

This is similar to the design and development WEB MVC model, we are focusing on hierarchical design.

 

The modular design: the need to collect, classify, analyze and summarize, these requirements will be summarized as a separate function, each function, made a separate functional blocks.

Hierarchical design not directly express a word, look it mainly reflected in several aspects:

1, the external functional module calls the module encapsulated API into one, will be a low level driver module API function call for. (Respective functional modules may be compiled independently (e.g., the communication module pure ANSI C, can be multiplexed on any platform), or call the driver layer interfaces (log database module calls the drive to read and write the Flash), short, words and short, the various functional package reusable independent functional modules.)

2, API API into the drive layer and application layer API, and not all programs call the driver layer API. (Throughout the application calls the driver layer API calls will lead to applications drive everywhere, not portable and maximize reuse)

 

Overall hardware driver sub-layer -> functional module layer -> business logic -> Application Layer

A schematic block diagram showing the overall structure:

Description:

1. can not cross-layer between the layers calls.

2. Module module independently, no dependencies.

3. The module provides a unified interface for the upper calling, internal and external module interface clearly.

4. The only function of the module increases, can not be changed.

The layers of each module may also continue layered, such as interface layer, driver layer, the hardware layer.

 

(3) Description Module level

Hardware driver layer
hardware driver layer contains all the drivers onboard hardware resources required for normal operation and to provide API calls to the function module.

The function module
function module to realize the function layer comprises a specific function, by calling the corresponding function driver layer API, while providing an API that can be called to the business logic layer.

Business logic layer
logic layer includes various business processes overall product functionality, implemented by API calls function module layer.

Application layer
application layer to integrate various business logic calls, completion of the entire product.

 

(4) Advantage

If the drive change, or change a different platform, only the driver layer, the application layer is not affected.

If the function module changes, simply update the corresponding function modules, other modules are not affected, the application layer is not affected.

According to this logic, after a good design, the main job is in the business logic layer. The overall process and framework for the application layer, compared with the program, call the main business logic layer implement different functions.

Published 136 original articles · won praise 71 · views 160 000 +

Guess you like

Origin blog.csdn.net/u012308586/article/details/104970734