
Open a blank Simulink model.
Add a TargetLink Subsystem block.
Add a TargetLink MIL Handler block.
Save the model.
TargetLink Main Dialog
Generates production code for the currently selected code generation unit (CGU).
The build processes (Build SIL/Build PIL) cover code generation, compilation and download for the respective simulation mode (SIL/PIL).
Menu in the Simulink Editor
Generates code for the system or subsystem(s) currently selected.
Context menu of the Data Dictionary Manager
Generates code for the selected CGU or a selected module of a code generation unit.
Function block
Generates code for subsystems that are configured for incremental code generation (with the Enable
Incremental Code Generation checkbox selected on the Incremental page).
API function
Used for automation use cases
commands
tl_generate_code
tl_build_host
tl_build_target
TargetLink Main Dialog
DD
DD-based CGUs that reference the CodegenOptionSet object via their CodegenerationOptionSetRef property
Model-based CGUs in the model hierarchy of the root model whose TargetLink Main Dialog block references the CodegenOptionSet object via its Code Generator option set edit field.
--------------------------
TLPredefinedOptionSet :default (general-purpose Code Generator options)
---------------------------
Modifications
Via the All Options button on the Advanced page of the TargetLink Main Dialog Block
DD
Hook Scripts
When you create a new DD project file, you can choose from predefined system templates.
dsdd_master_basic.dd [System]
Provides the new DD workspace with a basic set of predefined DD objects, such as DD Typedef, DD VariableClass, and DD FunctionClass objects.
dsdd_master_advanced.dd [System]
Provides the new DD workspace with additional predefined objects, such as DD Template objects and DD RTOS objects required for multirate code generation.
dsdd_master_autosar4.dd [System]
Provides the new DD workspace with additional predefined objects, such as DD Typedef and DD Variable objects to be used in AUTOSAR SWCs, and a DD object for specifying AUTOSAR software components and interfaces. Use this template to work with the AUTOSAR 4.x standard.
variable objects that describe a fixed set of properties and can be used globally.
Using a variable object is useful if you often need to reference the same type of variable description or want to keep variable definitions consistent by sharing DD files with other team members of your workgroup.
Variable classes determine how the variables are created in the generated code
each properties combination represents a variable class
Predefined categories
DISP -> Observation
CAL -> Parameter Calibration
MACRO -> C macros (constants)
FCN -> Function Arguments
Use Cases - Module Separation
Explicit Struct
Implicit Struct
To specify code decorations, such as declaration statements, pragmas or memory
sections, for code elements.
basic example
function with shared/specific parameters
Embedding external code as statements or function
direct code implementation from within the block (code inlining). The inserted custom code is included directly in the production code. The inlined code is also used for MIL simulation (Type |)
Use Case:
"Suppose your target ECU is equipped with special hardware features, for example, a unit for PWM generation or a hardware timer that can be accessed by external C functions. To allow offline simulations, your controller model contains a rather complicated implementation of the hardware unit by basic blocks. In this case you do not want TargetLink to generate C code for the model of the hardware function, which is needed only for offline simulations. Instead, you want TargetLink to call your own existing C function in the generated code. You can achieve this behavior by embedding an external function."
Steps:
a subsystem that contains a TargetLink Function block with its step function class property Storage set to
extern.
In model-based design, code generation plays a pivotal role in translating graphical or mathematical models into executable code. This approach enables engineers to design and simulate complex systems using graphical tools or mathematical representations, then automatically generate production-quality code directly from these models. Platforms like MATLAB/Simulink facilitate this process by providing a visual environment for system modeling and simulation. Once the model is validated through simulation, code generation tools generate efficient, optimized code tailored to the target platform, whether it's embedded systems, desktop applications, or hardware-in-the-loop (HIL) testing setups. This seamless transition from models to code enhances productivity, reduces development time, and ensures consistency between design and implementation, making model-based design a preferred methodology in various industries, including automotive, aerospace, and industrial automation.
TargetLink is software that generates highly efficient C code for electronic control units (ECUs) and domain controllers straight from MathWorks® Simulink®/Stateflow®, making TargetLink an essential tool for your model-based embedded production software and systems development.
TargetLink comes with software design features as well as built-in code optimization, simulation, and testing functionalities so that you can quickly verify and optimize your generated results. TargetLink interacts smoothly with other tools from dSPACE and with tools from other vendors, which together form the TargetLink Ecosystem.
This is a crash course for beginner in using targetLink.
In this course you will learn many areas of targetlink
Model Preparation
creating targetlink compliant models from scratch
convert existing simulink models into targetlink compliant models
Code Generation
Simulation
MIL
SIL
TargetLink Data Dictionary
TargetLink Data Dictionary Manager
Property Manager