C code export

This section describes C code export option.

C code export provides an option to generate C code for a selected subsystem within a schematic model.

Even though the code is generated only for a selected subystem, the whole schematic is evaluated. This makes sure that the namespace and signal types are calculated properly for every component inside the selected subsystem.

There are three ways to export C code from a selected subsystem:
  • Model menu (Model C code exportExport) - see Figure 1 ,
  • Context menu (right click on the component, then in menu C code export choose Export option) - see Figure 2,
  • Shortcut CTRL + E.

Figure 1: C code export menu

Figure 2: C code export context menu

Code can be generated either for a generic target platform, or a custom target platform (see Platform-specific code generation). By default, code is generated for a generic target platform. That means that the Typhoon types int, uint, and real are by default mapped to int, unsigned int, and double, respectively. However, in the C Code Export tab (see Figure 3) it is possible to provide custom type mapping for each Typhoon type. Beyond that, C Code Export tab offers a possibility of defining a destination directory for the generated code. This tab can be opened through:
  • Model menu (Model C code exportSettings), and
  • Context menu (right click on the component, then in menu C code export choose Settings), and

Figure 3: C Code Export tab

C code will be generated successfully if the following requirements are met:
  • Exacly one subystem is selected,
  • Selected subsystem does not contain electric components, and
  • Selected subsystem does not contain HIL-specific components.

If at least one of the requirements from above is not met, an error message will be shown in the Schematic console.

Once C code export is finished, all files needed to succesfully run the code are created inside the destination directory. For every subsystem used for C code export, an appropriate header (.h) and source (.c) file will be generated. The C code inside these files is structured in a such way that allows easy reusability. This is accomplished by encapsulating all relevant data (variables) inside a single Model structure, which is passed as an argument to both init and step functions - which are used to interact with the generated C code.

Besides the main Model structure, each header file contains additional structures, such as:
  • ExtIn - contains variables generated from the inputs of the selected subsystem,
  • ExtOut - contains variables generated from the outputs of the selected subsystem,
  • Sinks - contains variables generated from SCADA Ouput, Digital Probe, and Probe components, and
  • States - contains variables used to preserve the state between successive calls of step function.