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.
- Model menu (Model → C code export → Export) - 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.
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 it is possible to provide custom type mapping for each Typhoon type. Beyond that, the C Code Export tab offers the possibility of defining a destination directory for the generated code. This tab can be opened through one of the following options:
- Model menu (Model → C code export → Settings)
- Context menu (right click on the component, then in menu C code export choose Settings)
- Via the Model Settings dialog (click on the C Code Export tab)
The descriptions for the C Code Export customization options are as follows:
Option name | Description |
---|---|
Export directory | Define the directory where C code will be exported. |
int | Define type mapping for int Typhoon type. By default int is mapped to int C type. |
uint | Define type mapping for uint Typhoon type. By default uint is mapped to unsigned int C type. |
real | Define type mapping for real Typhoon type. By default real is mapped to double C type. |
- exactly one subystem is selected,
- the selected subsystem does not contain electric components, and
- the 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 Editor 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.
- 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.