Generate a Main File

How wrapper blocks are used in the process of generating the main.c file.

Generating a custom code for a target requires generating a main.c file. The main.c file contains calls to the APIs exposed by body, but its content is highly target-specific. This file is created by a target-specific code generator function using information from specific blocks, called wrapper blocks, used in the model specifying the input and output operations and the way interruptions are handled.

The wrapper blocks are exposed in the block library for the given target and can be used the same way other blocks are used by the end-user. Typical examples are blocks defining the target input and output ports associated with their pin numbers:



Examples also include blocks defining clock signals associated with different interrupt clocks.

The process of generating target-specific code based on corresponding wrapper blocks is called Custom wrapper code generation. The Custom wrapper is not a complete code generator. It is a generic target that facilitates the creation of code generators for various targets. The final target is defined in the model, and the model uses blocks corresponding to this target. A code generator corresponding to the target should be available. To add support for a new target, the corresponding wrapper blocks and the code generator can be provided as a Twin Activate library (Extension).

The Custom wrapper code generator is used on a super block provided in the target library. This super block defines the target of the code generation by providing a mask parameter named target. The value of the parameter specifies the target and the code generator function to be used.

The creation of wrapper blocks for any target is simplified thanks to the use of the GenericWrapperBlock block, available in the palette of the WrapperCodeGenerator library. Wrapper blocks are simply created by parametrizing the block GenericWrapperBlock. The parameters in particular specify the code snippets that must be placed in different positions in the file main.c.