Open Source CAN Stack with C-Code API generated from Vector CANdb++ *.dbc Files

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Implementing a CAN interface on top of the basic interrupt driven CAN hardware layer involves typical tedious tasks, which can be automated. Most obvious is the need for a pair of pack and unpack functions for each CAN message, which compose messages from signal values and vice versa. Such functions can be auto-coded based on the information in the DBC files. However, a lot more of the CAN interface can be auto-coded like right transmission timing and handling of checksums and sequence counters.

comFramework is an Open Source CAN stack (http://sourceforge.net/projects/comframe/), which offers all of this. It builds on the frame based CAN hardware driver layer (platform dependent drivers are not included). The concept is to have generic hand-coded algorithmic parts that operate on auto-coded (data) parts, which depend on the application specific communication matrix (a set of *.dbc files).

Auto-coding is done with a flexible code generator, which can be used stand-alone without the actual CAN interface. (Only generating the pack and unpack functions would be a typical use case.) The code generator parses the *.dbc files and feeds a powerful template engine (www.StringTemplate.org) with the information. Under control of some templates can the DBC file contents be rendered in nearly any textual form, C source code is just a natural example.

A template is a text file, which mainly contains the desired output literally but intermingled with template expressions, which insert the DBC specific information at the right locations. A simple example would be:

/* Frame size of frame . */
const unsigned int frameSize__ = ;

This template could then be expanded for all of the parsed frames (or a specific sub-set) using iterations.

There's a strong library of samples and templates available. These show how to generate the pack/unpack functions, how to generate API structures (data based or functional), how to realize conditional C code based on user attributes in the DBC file (e.g. checksum validation yes/no), A2L files, AUTOSAR interfaces, interfaces with TargetLink and Embedded Coder, HTML documentation, among more.

Note, while the templates to generate the bit operations inside the pack/unpack functions should be considered an invariant will it be a matter of simple template adaptations only to make the signature and naming of the functions perfectly fit to your existing environment.

Note, the concept is to generate C source code, which has to be compiled. This targets embedded applications. A host based application, which wants to dynamically load a DBC file at run-time and process it, can't be implemented with the framework.

The major drawback of the framework is the learning curve you have to go through. The template expression syntax needs to be fully understood (approx. 50 pages pdf, including many examples) and the data model, i.e. the parse tree and at the same time the input to the template engine, needs to be known. (See example above: you need to know that there is an object "frame" and that this object has a field "id" and that id is an integer, etc.) The data model is documented in HTML, Javadoc.

The best thing to do first is to have a look at the code generation samples. See http://sourceforge.net/p/comframe/code/HEAD/tree/codeGenerator/trunk/samples/, start with "raceTechnology". They have a folder "output", which hold the generated files. Browsing these files will give you an immediate idea whether comFramework's code generator will be useful for you or not.

The architecture and the concept of the CAN interface itself and how it cooperates with the code generator is explained in the Wiki pages of the SourceForge project. Understanding and use of the CAN interface is supported by some sample integrations.
0 Likes
1 Reply
Not applicable
Just one comment:

The above and all webpages/documentations linked in there are walls of text. No one image/graph which helps to understand the idea/function.

Very hard to follow.
0 Likes