Code Generation Using Simulink Coder
Code Generation Technology
MathWorks® code generation technology produces C or C++ code and executable programs for algorithms. You can write algorithms programmatically by using MATLAB® or graphically in the Simulink® environment. You can generate code for MATLAB functions and Simulink blocks that are useful for real-time and embedded applications. Generated source code and executable programs for floating-point algorithms match the functional behavior of MATLAB code execution and Simulink simulations to a high degree of fidelity. Using the Fixed-Point Designer product, you can generate fixed-point code that provides a bitwise match to model simulation results. Such broad support and high degree of accuracy are possible because code generation is tightly integrated with the MATLAB and Simulink execution and simulation engines. The built-in accelerated simulation modes in Simulink use code generation technology.
When designing components or a complete application in the Simulink environment, you can generate code from your models by using Simulink Coder™ or Embedded Coder®.
Use Simulink Coder to generate code for rapid prototyping and hardware-in-the-loop (HIL) testing of real-time and nonreal-time applications. You can tune and monitor the generated code by using Simulink or run and interact with the code outside of MATLAB and Simulink.
Use Embedded Coder to generate readable, compact, and fast C or C++ code for embedded processors that are used in production. You can apply customizations for controlling the efficiency and appearance of the generated code. For example, you can simply integration by configuring data and function code interfaces and how the code is packaged in files. Embedded Coder provides tools for tuning parameters, analyzing code performance, testing numeric equivalence, and performing code coverage and traceability analysis.
Code generation technology and related products provide tooling that you can apply to the V-model for system development. The V-model is a representation of system development that highlights verification and validation steps in the development process. For more information, see Validation and Verification for System Development.
Code Generation with Simulink Coder
Use Simulink Coder to generate C or C++ source code for:
Rapid prototyping and real-time simulation for proof-of-concept development, testing, and optimization
Development of rapid prototyping and hardware-in-the-loop (HIL) turnkey solutions
Application binaries that run on desktop platforms
Development of model designs and generated code that provide intellectual property protection
Rapid Prototyping and Real-Time Simulation and Deploy Environment Model for Real-Time Hardware-In-the-Loop (HIL) Simulation introduce the use of Simulink Coder for deploying algorithm models for rapid prototyping and deploying environment models for real-time HIL simulation.
For information on developing rapid prototyping and HIL turnkey solutions, see Code and Tool Customization, Simulink Real-Time™, and Simulink Desktop Real-Time™.
Model Protection provides information on developing models and generated code that provide intellectual property protection.
To generate and deploy code for embedded processors used in mass production, use Embedded Coder. Embedded Coder extends capabilities of Simulink Coder, including, but not limited to:
Generation of function code modules that you can integrate with external code
Advanced code optimizations
Control over code appearance, including code interfaces
Variety of tools for verification, testing, and certification
You can generate code for most Simulink blocks and many MathWorks products as Use Products and Blocks Supported for Code Generation shows. This figure shows how to use Simulink Coder to generate and deploy code.
The code generation workflow is a part of the V-model for system development. The process includes model design, code generation, code verification, and testing of the executable program in real-time. For rapid prototyping of a real-time application, typical tasks are:
Configure the model for code generation in the model configuration set.
Check the model configuration for execution efficiency using the Code Generation Advisor.
Generate and view the C code.
Create and run the executable of the generated code.
Verify the execution results.
Build the target executable.
Run the external model target program.
Connect Simulink to the external process for testing.
Use signal monitoring and parameter tuning to further test your program.
Here is a typical workflow for applying the software to the application development process.
For more information on how to perform these tasks, see Generate C Code for a Model.