TargetLink generates highly efficient C code straight from MathWorks® Simulink®/Stateflow®. Automatic code generation also means that if you make a change that impacts more than one line of code TargetLink updates all those lines automatically. As a result, you can now focus on the actual application. Early verification through the built-in simulation and testing features leads to faster turnaround times and lower costs.
Why Code Quality Counts
Compared to code used in rapid control prototyping, where developers need to have a lot of freedom when testing new concepts, production code for electronic controls in vehicles, planes, and for any other real-use industrial application needs to fulfill very strict requirements in terms of quality. For example, developers have to be sure that the code is highly optimized, that it can be easily integrated with other software, that it is readable in the present and in the future to ensure maintainability, that all connections between requirements, model and code are clear and comprehensible, and that the code fulfills the relevant standards. In short: topmost reliability, efficiency, security, maintainability, traceability, and – concerning the generation process – reproduceability (i.e., the same model leads to the same code) is required.
TargetLink for High-Quality Production Code
The production code generator dSPACE TargetLink is an extremely powerful software system which ensures that your code always achieves superior quality – and it does so while letting you take your individual requirements and the relevant standards into account. Despite TargetLink’s comprehensive features, the typical steps in generating your production code are easy to follow, with many options to fit the process to your individual environment. Typical steps include the control design, the iterative validation and verification (based on simulation), and the code integration on the ECU. Furthermore, TargetLink interacts smoothly with other tools from dSPACE and with tools from other vendors, which together form the TargetLink Ecosystem.
Designing Controller Models Directly with TargetLink
The Simulink® block library is very powerful in simulation tasks, providing all necessary specification features. When it comes to code generation, however, more information is needed for each block. For example, the blocks need additional capabilities for fixed-point simulation. That is why TargetLink comes with the TargetLink Block Library which offers a block for each supported Simulink block.
The TargetLink blocks significantly enhance the functionality of the supported Simulink blocks and have an extended dialog that allows you to enter the implementation-specific information necessary for code generation. Each block also provides a means of data logging and overflow detection. A special routine automatically prepares Simulink models for code generation with TargetLink by enhancing the Simulink blocks to TargetLink blocks. As a result, the model is ready for production code generation and on-target bypassing.
If you need to change the properties of a large model, TargetLink’s graphically oriented Property Manager is a quicker alternative to changing the properties in the block dialogs manually. It displays the properties of TargetLink blocks and Stateflow objects in your model, and lets you view, filter, and modify several properties simultaneously.
Three Simulation Modes for Testing
Although code generators produce virtually flawless results, when compared to manual programming, the generated code still needs to be tested as well as the underlying specification. TargetLink provides powerful and easy-to-use means to verify the generated code. The code tests are performed in the same simulation environment that was used to specify the underlying simulation model. Functional identity has been achieved when the simulation results match. TargetLink provides a three-step verification process which shows at the click of a button whether the specification (the model) and implementation (the generated code) are functionally identical.
Model-in-the-Loop Simulation | Data is recorded for reference plots from the simulation model. Signals from selected blocks and state variables are automatically logged by TargetLink. The model-in-the-loop simulation captures the specified behavior of the model that is to be implemented in C code later on. The recorded signal plots act as the reference for the next verification steps. Model-in-the-loop simulation can also be used for detecting overflows of integer variables, and its results are used for simulation-based autoscaling. |
Software-in-the-Loop Simulation | The code is generated and replaces the controller blocks in the simulation model (for example, the same plant and stimulus signals). TargetLink does this automatically in the background. You still see the controller blocks, though it is the code that is executed on the host PC instead. The signal plots should be largely identical when compared to the results of model-in-the-loop simulation. If they are not, they can be analyzed to get a better understanding of the cause of the deviation and to fine-tune the fixed-point settings. |
Processor-in-the-Loop Simulation | The generated code runs on an embedded processor, but because code that runs correctly on the host PC can still cause trouble, it has to be inspected further. An off-the-shelf evaluation board is connected to the host PC, and the generated code is compiled with the target compiler and downloaded to the evaluation board. TargetLink manages the communication between the host PC and the evaluation board. All these activities are automated and need no user interaction. Simulation on an evaluation board just takes two mouse clicks. |
Features and Benefits of the Simulation Concept
Feature | Description | Benefit |
---|---|---|
MIL/SIL/PIL simulation at the click of a button | Switching from MIL to SIL or PIL simulation requires just one click | Powerful simulation environment No need for separate test models, generation of S-functions or manual insertions into test harness models |
Integrated data logging | Built-in data logging and result plotting for all simulation modes | No model modifications necessary Available for all simulation modes |
Direct comparison of MIL/SIL/PIL results | Automatical plotting of all simulation results in the same plot window | Display results of simulations in different modes directly and analyze deviations Direct feedback whether code matches model simulation |
Detailed signal analysis and deviation plots | Zoom signals to visually inspect deviations, display constraints (e.g., defined ranges), use cursor to scroll through signal histories, display signal values numerically or plot signal deviation | Get a clear picture of the signal behavior Especially useful for conversion from floating-point to fixed-point |
Integrated data logging and plotting | Built-in TargetLink blocks come with an integrated data logging functionality. In the block dialogs, you can specify whether to log the block output signals. | |
Run-time analysis for profiling the code | Processor-in-the-loop (PIL) simulation can also be used to profile the generated code. During PIL simulation, TargetLink automatically measures execution time and stack consumption directly on the target processor. | |
Code coverage analysis | You can assess how comprehensive tests are by using code coverage analysis. TargetLink offers C0 and C1 coverage analysis, also called statement coverage and decision coverage. | |
Model-code traceability | For improved traceability and simplified code reviews, code files can optionally be generated in HTML format, with hyperlinks for navigation from model to code and vice versa. |
High Code Efficiency
Regardless of the application type (fixed-point or floating point), TargetLink generates highly efficient production code for your embedded system. Multiple scaling properties give ample choices to fine-tune fixed-point code to the conflicting requirements of low execution time, high computational precision, and overflow avoidance. If an overflow occurs, TargetLink’s overflow detection shows the exact location in the block diagram. The problem can be corrected right away.
Scaling Variables
To shorten the time-consuming and error-prone manual scaling process, TargetLink provides an Autoscaling Tool. It supports you in finding suitable ranges and calculating appropriate scaling parameters. A scaling task that took days and weeks in the past can now be done in minutes and hours.
As a scaling method, TargetLink offers the two-coefficient linear scaling, which is widely used in embedded control applications. The properties for specifying fixed-point scalings in TargetLink are:
- Data type
- Power-of-two scaling factor or arbitrary scaling factor
- Offset value
- Constraint values
- Bit safety margins
- Saturation options
While fixed-point scaling can be done manually by a software engineer, in most instances it is left to TargetLink’s autoscaling tools. Two autoscaling procedures are available:
- Simulation-based autoscaling – benefit from maximum computational precision
- Worst-case autoscaling – no plant model required and overflows automatically prevented
Moreover, TargetLink also supports scaling with scaling formulas and type definitions.
Powerful Code Optimization
TargetLink generates highly optimized ANSI C code that is just as efficient as optimized handwritten code. This is achieved by various optimization techniques, such as standard optimization techniques that are also used by modern C compilers. TargetLink’s interblock optimization gives the generated code a human touch, because it combines code in a very similar way to what a skilled software engineer would do. For more complex blocks, TargetLink uses code from an internal code pattern library during the code generation process, ensuring that the code for complex blocks is also highly efficient.
Further Verification Features in TargetLink
Feature | Description |
---|---|
|
|
|
|
|
|
|
|