Framework

C++ Framework for embedded Applications

A framework provides the developer with tried-and-tested concepts and a clear structure, enabling them to find solutions efficiently.

The developer can concentrate on finding solutions in terms of content.

The object-oriented (OO) approach is increasingly being used in the development of applications on microcontrollers. C++ has established itself as a programming language in this area. But using the OO approach and C++ language is not enough to guarantee success on its own. In addition, frameworks such as those used in desktop environments are often unsuitable.

In other words, the key lies in the experience of the employees and in the implementation of suitable concepts. The framework developed by CSA Engineering combines both of these factors.

Logo nanoFramework

Creating structures

During the design phase, UML elements such as package or component provide effective structuring, while during implementation, classes and namespaces are often insufficient to achieve satisfactory results. 

The framework implemented by CSA Engineering provides a template for developing building blocks. Building blocks are a defined arrangement of classes that together perform a specific task and have a clearly defined input/output interface. 

This clear structure contributes significantly to compliance with the confidentiality and locality principles, thus reducing dependencies. Endless chains of includes are prevented from appearing from the outset, which speeds up compilation times.

 

Figure 1 Example class diagram BuildingBlock A

Modell

Clear interfaces for high reusability

Developers with little experience in OO technology tend to see the advantage of this approach as being able to reuse individual classes. In reality, however, the benefits of reuse are limited at the class level.

The real benefit is to be found in reusing entire functional units. Clear interfaces are required for this to succeed.

Building blocks, as implemented in the framework, define these clear interfaces. By adapting a single class, a building block can be reused in a completely different application. 

 

Figure 2 The model still looks tidy

Higher reliability

The building block concept ensures that critical transactions only take place locally. As a general rule, the allocation and deallocation of memory only takes place within building blocks, usually within the same function. This significantly reduces the risk of memory hogs. 

In most cases, the complexity of a building block is calibrated in such a way that a single developer can be responsible for implementing it, eliminating problems that may arise due to a lack of coordination between team members.

Integration

Multitasking as an integral part

Real-time operating systems are often used to guarantee the time independence of the various tasks in an embedded application. Building blocks are designed to work in their own task context if required. 

Essential aspects of a multitasking application such as

  • creating tasks
  • terminating tasks
  • communication between tasks
  • synchronising tasks

are standardised and are already covered in the framework. 

A framework provides the developer with tried-and-tested concepts and a clear structure, enabling them to find solutions efficiently. The developer can concentrate on finding solutions in terms of content.

 

Figure 3 Conceptual integration of the OS into the framework

Portability

In order to achieve portability, access to the operating system is implemented only via special classes. There is no direct access to the operating system within the framework. 

By appropriately implementing a few classes intended for porting, the framework can be ported to any operating system in a short time. Ports to Keil RTX, FreeRTOS and Win32 have already been implemented.

Developing, debugging and testing on a desktop computer

Even when creating embedded applications, it is very convenient if individual modules can be developed and tested a desktop computer. The existing port for Win32 is very helpful for this purpose: In the selected IDE, such as MS Visual Studio Code, the framework can be fully integrated and combined with tools such as GoogleTest/GoogleMock. This makes coding and testing possible without using the real hardware, which is convenient and makes you less dependent on the hardware.

Watch out for pitfalls

Applying the object-oriented approach successfully and using C++ require experience. There are many potential pitfalls, which can easily lead to disenchantment. Procedural programming with classes or object-oriented over-engineering shall only be mentioned in passing here. 

A framework helps to avoid pitfalls by limiting the solution space and providing developers with a template for their own work.

Contact us