Export an Embed Block from Twin Activate
Export generated code both for simulation and inclusion of generated code in Embed for target deployment purposes.
Prerequesites for This Tutorial
The following software is required for this tutorial:
- Altair Twin Activate
- Altair Embed
- Visual Studio Compiler for compiling generated code from Twin Activate and to create an Embed block.
Overview
One of Twin Activate's code generation options is to export the generated code both for simulation and inclusion of generated code in Embed for target deployment purposes. This tutorial captures the overall steps to set up and achieve a working setup for such a design flow.
Embed provides standard block APIs to define the block behavior for simulation and code generation. The code generation option Embed Block leverages these published APIs to automatically wrap the generated code from Twin Activate.
When creating a simulation diagram in the Twin Activate diagram, you can easily test the generated code in a target environment. The code is target agnostic and optimized, leveraging the inlined code generation option. Embed supports more than 1200 microcontroller targets. You can include the needed target specific drivers and schedule for execution using the visual interface from Embed. You can also customize the RTOS behavior and Software/Hardware Interrupt scheduling in Embed for testing in Processor In the Loop and Hardware In the Loop configurations.
Export an Embed Block
- In a Twin Activate diagram, select the super block to be exported.
- Select .
-
Set Target to be Embed Block. Set
Processor to 64 bits or 32
bits, depending on your Embed installation. Select the
Embed installation path and your desired
Output directory. Set the other name fields as
necessary.
-
Click Generate.
In the output directory, you now have the following files:
- Body.c: A C file that provides the implementation of the actual super block.
- Body.h: Header file containing the function definition for the implementation in the Body.h.
- main.cpp: Embed Block Specific Wrapper with the Body.h file to include the relevant generated code from Twin Activate. The file contains functions leveraging the Embed Block API for simulation and code generation.
- make.bat and make.sh: Contains
the relevant make process for the generated code.Note: Based on the Embed installation, relevant libraries (Vissim32.lib/Vissim64.lib) are referenced for linking.
- [DLL name].def: Exported functions for the current
diagram.Note: In the example from the above screenshot, this file name is Block_From_Activate.def.
- Open a command prompt and change the directory to the Visual Studio Build folder.
- Set up the compiler environment. For example, for 64-bit Visual Studio, call vcvars64.bat x64.
-
Change directory to the code generation output directory, and then call
make.bat.
If there are no errors, the invocation of the make.bat produces a dll that can be further registered in Embed.
Add the DLL to Embed
- Open Twin Activate Embed.
- Select .
-
Open the Addons tab, and then double-click
... at the bottom of the list.
-
Browse to the location of the DLL you created in the export steps, and then
select it.
The DLL is added to the bottom of the Addons list.
-
Select the DLL from the list, and then click OK.
The new block is added to the Blocks menu.
You can use the new block for simulation and code generation.