Experience Embedded

Professionelle Schulungen, Beratung und Projektunterstützung

Easier and Safer Configuration of Source Code Libraries

Author: Oreste Bernardi, Infineon Technologies AG

Beitrag - Embedded Software Engineering Kongress 2015

 

Increasingly complex libraries are being developed for microcontrollers to accommodate the rising performance levels of microcontroller peripherals and applications. The usual configuration methods using #defines and/or data structures can be time-consuming and result in configuration errors. A graphical user interface coupled with a configuration generator offers a number of advantages here. Besides the obvious readability and parameter description benefits, a GUI could check and validate user input in real time. Unfortunately, GUI programming know-how is beyond the usual sphere of competence of microcontroller developers and acquiring this knowledge could be time-consuming. This article explores a novel approach to creating a user interface and a code generator to support the configuration of source code libraries. This approach is suitable for developers who do not have GUI programming expertise as it implements a new UI execution model that simplifies development and debugging.

New silicon technology is enabling more and more complex SOCs. This is evident also in microcontroller developments: we are seeing more flexible peripherals, more peripheral instances and more pins. A good example is Infineon’s XMC4500 microcontroller. This microcontroller can be used for motor control and power conversion and is not particularly complex. Its reference manual describes more than 7050 register bit fields (the number doesn’t include duplicate register bit fields due to multiple instances of the same peripheral).

As a result, software libraries that support microcontrollers such as these are becoming more complex and difficult to configure given the number of parameters. The majority of microcontroller libraries are developed in C. Typically the user configures the library in two stages: during compilation using the #define pre-processor macro and during runtime by activating configuration functions with appropriate arguments. However, these methods are not suitable for large and complex software development projects.

Code generators with a graphical user interface are already used to generate configuration macros and initialization functions. Examples include DAVE™, the Vector AUTOSAR ECU configuration tool, STM32Cube and Processor Expert. Usually, the GUI of these tools also checks the consistency of user settings, providing pictures and tool tips to clarify the meaning of configuration parameters and guide the user in how to set them.

Hence a C library should ideally be provided with a GUI-based configuration tool. Developers of deep-embedded C libraries do not typically have a good knowledge of GUI programming.

DAVE™v3

We experienced this issue directly when developing Apps for DAVE™ v3. DAVE™ is a free IDE and code generator developed by Infineon to support its XMC industrial microcontroller family. The code generator is based on the concept of Apps. A DAVE™ App essentially combines:

  • A C library
  • An XML GUI description
  • A manifest file that implements the GUI logic
  • Template scripts that generate the library configuration based on GUI parameters.

 

DAVE™ also comes with a DAVE™ SDK to develop Apps.

The App concept was introduced in DAVE™ v3 but our developers had difficulty developing complex GUIs because they are specialized in deeply embedded code and not in GUI programming. The GUI design process was very easy thanks to our WYSIWYG tool but GUI logic implementation was slow and error-prone. In DAVE™ v3, we used typical UI programming methods based on call-backs. The developer can register a call-back for each event of a widget UI; if an event fires (i.e. user enters a value in a widget), the registered call-back is executed.

The most important limitations that we experienced were:

  • Scattered code
  • Hidden states

 

Scattered Code

The same variable can be accessed by multiple call-backs and this makes it more difficult to debug and understand the code. By way of example, assume that a variable has a wrong value and the developer would like to review the code that affects the target variable. In this case, the developer has to inspect all code that could access this variable.

Hidden States

It is quite easy for App developers to create hidden states that are sensitive to the order of user inputs. A simple example of this scenario is shown in figure 1 (see PDF).

There are two checkboxes with two different call-backs that assign two different values to the same variable. Obviously, the user can create the same configuration for the checkbox with two different mouse click streams – but the result is completely different. This issue is very relevant for one important feature of DAVE™: project upgrades to the latest App versions. Project upgrades are performed by creating a new project, adding the latest Apps and then copying the configuration parameters from the old project to the new one. In cases such as that described, DAVE™ v3 was not able to correctly upgrade the project because it had no understanding of the JavaScript code used to define the call-backs and it was not recording the order of user operations.

Reactive Programming - Think Spreadsheet!

These are just some of the issues typically encountered with traditional GUI programming.[1][2] For this reason, GUI programming requires discipline and experience. However, our developers spend 90% of their time developing efficient C libraries and can only dedicate a small window to user interface programming.

In our search for a solution, we came across the Reactive Programming (RP) paradigm. This paradigm focuses on the propagation of changes and data flow.[3] Every day, millions of people use a tool based on this paradigm: the common spreadsheet.

In a spreadsheet, a cell contains a value or a formula that defines its value. As soon as this value is changed by the user, all cells that contain a formula directly or indirectly affected by the modified cell are updated.

The spreadsheet concept (Reactive Programming) thus had the potential to solve our problems. Let’s call the cells/variables that contain constant values only free variables (cells A1, B1 and C1 in fig. 2) and the cells/variables that have been assigned a function not free variables (cells A2 and B3 in fig.2, see PDF). The free variables can be considered as the GUI inputs and the not free variables together with their formulae as the GUI logic. Debugging a GUI developed according to this concept is very easy. One not free variable is associated only with one formula or code, the execution of which only affects the assigned variable. So if its value is wrong, the developer has just to inspect the code linked to this variable. If it is correct, the developer checks the code linked to the input variable and so on – right down to the user inputs.

This also solves the problem of hidden states. In fact, the state of UIs based on this concept is defined by the value of the free variables. For the programmer, it is impossible to create a GUI/spreadsheet where the results depend on the order of the inputs.

There are other advantages of the reactive paradigm/spreadsheet concept. In fact, a dependency graph [5] can be built in such a way that it is possible to:

  • execute only the code that is affected by user changes
  • parallelize the execution of code.

 

DAVE™ Implementation

In DAVE™ v4, we used this simple concept to accelerate development and improve the quality of our Apps. DAVE™ v4 App developers essentially write a simple Groovy [4] class. We chose Groovy over other Domain Specific Languages (DSL) for the following reasons:

  • Fully featured language ready to be used (not another DSL)
  • Syntax very similar to Java/C++
  • Ease of integration in Java applications (DAVE™ is written in Java)
  • Easy extension of compiler by modifying the intermediate representation of source code (abstract syntax tree).

 

Every time a user adds an instance of an App, the constructor of the class is executed and it configures the UI by assigning functions to variables that represent the different properties of the GUI widgets.

Example

Figure 2 (see PDF) shows a very simple user interface with a DAVE™ App. The developer wants to show the message “Speed too high” if the motor speed settings exceed 100.

Essentially the developer assigns one function to the visible property of the high_speed_msg widget. As soon as the value of motor_speed changes, the function is evaluated and the returned value assigned to the visible property.

The Groovy compiler parses the MF (Manifest Function) definitions; it extracts the input variables and it modifies the code so DAVE™ is able to build the dependency tree at runtime. Moreover, the compiler checks that the MF code doesn’t contain any assignments to variables that are not locally declared. This ensures that there are no side effects (or hidden states) during the execution of MF code.

Developer Experience

After the development of around 100 Apps with the DAVE™ v4 SDK, our programmers confirmed that they had reduced development time and encountered fewer bugs during testing. Moreover, they were able to program more complex GUI implementations relative to DAVE™ v3. An empirical study confirmed these quality improvements and greater programming abilities.[6]

Beyond DAVE™

If C programmers want to design a GUI-based configurator for any library, the advanced methodologies implemented in DAVE™ and the DAVE™ SDK are ideal. These tools can be downloaded from www.infineon.com/dave. Using the video tutorials provided, programmers can rapidly develop their own graphical library configurator.

However Reactive Programming is an emerging trend in desktop and mobile UI programming [7] [8] and also relevant to certain safety-critical embedded software development projects[9]. In the opinion of the author, this paradigm will expand its reach to embedded software development – especially to UI programming.

Conclusion

Complex microcontroller libraries should be provided with a configuration tool that simplifies correct configuration. However, developers of deeply embedded code have little experience in complex UI programming. For this reason, the DAVE™ v4 SDK has implemented a Reactive Programming concept. The aim is to improve the quality and speed of GUI development. After developing around 100 DAVE™ Apps, our programmers confirmed the advantages of functional Reactive Programming over traditional GUI programming. DAVE™ v4 and the DAVE™ SDK can be downloaded free of charge and used by developers interested in exploring easy, safe GUI programming.

References

[1] Jonathan Edwards. 2009. Coherent reaction. In Proceedings of the 24th ACM SIGPLAN conference companion on Object oriented programming systems languages and applications (OOPSLA '09). ACM, New York, NY, USA, 925-932. DOI=10.1145/1639950.1640058 http://doi.acm.org/10.1145/1639950.1640058

[2] Martin Sústrik http://250bpm.com/blog:24

[3] Wikipedia https://en.wikipedia.org/wiki/Reactive_programming

[4] http://www.groovy-lang.org/

[5] https://en.wikipedia.org/wiki/Dependency_graph

[6] Guido Salvaneschi, Sven Amann, Sebastian Proksch, and Mira Mezini. 2014. An empirical study on program comprehension with reactive programming. In Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE 2014). ACM, New York, NY, USA, 564-575. DOI=http://dx.doi.org/10.1145/2635868.2635895

[7] http://www.infoq.com/news/2013/08/reactive-programming-emerging

[8] https://www.gartner.com/doc/2560015

[9] https://en.wikipedia.org/wiki/Lustre_(programming_language)

 

 

Beitrag als PDF downloaden

 


Implementierung - unsere Trainings & Coachings

Wollen Sie sich auf den aktuellen Stand der Technik bringen?

Dann informieren Sie sich hier zu Schulungen/ Seminaren/ Trainings/ Workshops und individuellen Coachings von MircoConsult zum Thema Implementierung /Embedded- und Echtzeit-Softwareentwicklung.

 

Training & Coaching zu den weiteren Themen unseren Portfolios finden Sie hier.


Implementierung - Fachwissen

Wertvolles Fachwissen zum Thema Implementierung/ Embedded- und Echtzeit-Softwareentwicklung steht hier für Sie zum kostenfreien Download bereit.

Zu den Fachinformationen

 
Fachwissen zu weiteren Themen unseren Portfolios finden Sie hier.