Roboter hand writes on keyboard

Code Generation

What is the Benefit of Code Generation in the Embedded Field?

Time to Read 3 min

Anybody developing embedded systems has experienced this: during production ramp-up, the software is already finished. It shows that the standy-controller has to set a pin for the production test. The setting of the pin is done fast, but to route the command for the pin from the test port to the HMI controller then through the main controller to the standby controller via all protocol stacks is expensive and error-prone.

If all this could be done by pushing a button!
...this is possible: with code generation!

What is the Goal of Code Generation?

An important goal of course is to save time and commit less errors. In addition the code quality should improve, because repetitive parts are generated automatically and the complete information exists in only one place ("Single Point of Truth": from one source, the model the code for all controller, the code for the controlling PC and the documentation of the project is generated). An in addition the developers are also more motivated because the do not have to write boring "boilerplate" code themselves.

Code Generator Block Schematic

How is code generated?

Basically code generation consists of transforming a model description into compilable and afterwards of course executable code. The model can be of graphical nature or a textual data model, e.g. based on the standards JSON or XML .

What does the Solcept Code Generator do?

Our code generator is a .NET/ C# application, which generates C or C++ code for the embedded system. We use textual models in JSON, which contain the data structures, ranges, content descriptions etc.

First the generator reads the model, then checks it for syntax and consistency and transforms the model for code generation. With the help of the .NET Template Engine and the specific code templates for C and C++ or also C# etc. it generates the target code. Target code for the embedded system or also a PC/ Tablet based configuration tool.

Where do we use Code Generation?

We use code generation pragmatically, i.e. only where we can produce a real benefit. The two most important applications are communication and management of data and user interfaces.

For communication we model transferred data ("protocols") and configuration data. From this we can produce the code for storage, data management (non-volatile storage...) and transmission (as well as between embedded controllers as towards superordinate (PC-) systems). In addition an up-to-date documentation of the data emerges without further actions.

The modeling of GUI (Graphical User Interface) menus is the other application. The menu tree and the according authorizations are modeled, from this model the complete menu including the connection to the data model and the access/ authorization management code is generated .

A simpler application is the the is version information. There the code for the version information of the components of the embedded system is generated automatically and can e.g. be used for the management of updates.

What is Your Benefit?

When we apply cod generation in projects, then we can decrease the effort for development and at the same time optimize the quality, especially also for changes short before or after the start of production.

If you would also like to profit from our code generators, contact me:

Alois Cavelti

Do you have additional questions? Do you have a different opinion? If so, email me  or comment your thoughts below!

Author

Keywords/ Tags

Comments

No Comments

What is Your Opinion?

* These fields are required

Projects? Ideas? Questions? Let's do a free initial workshop!