Simulink Coder
Product Description
- Introduction and Key Features
- Selecting and Working with Targets
- Defining and Controlling Data
- Generating Code
- Executing Code in a Real-Time Environment
- Tuning Parameters and Logging Data
Executing Code in a Real-Time Environment
Simulink Coder provides a complete framework for executing the generated code in real time and incorporating it into your execution environment. It generates single-rate or multirate code based on the periodic sample times you specify in the model.
Execution Modes
Code can be deployed with or without an RTOS, and in single-tasking, multitasking, or asynchronous mode.
Single-Tasking Mode
In single-tasking mode, a simple scheduler invokes the generated code in a single thread of execution, preventing preemption between rates.
Multitasking Mode
In multitasking mode, a deterministic, rate-monotonic scheduler invokes the generated code, enabling preemption between rates. In a bare-board environment, you preempt the code with nested interrupts. In an RTOS environment, you use task priorities and task preemption.
Asynchronous Mode
In asynchronous mode, nonperiodic or asynchronous rates are specified using Simulink S-functions. Simulink Coder translates these rates into the code necessary for your execution environment. You model and generate code for events, such as hardware interrupts, and trigger subsystems as independent tasks. You can use the included asynchronous block library as a template for creating a library appropriate for other environments.
Real-Time Deployment
Simulink and Simulink Coder provide a complete set of target-independent capabilities for real-time deployment. These include:
- Task priorities that you can specify for each rate in your model
- Production-quality counters and timers for computing absolute and elapsed time
- A Rate Transition block to specify data transfer mechanisms between rates (for example, semaphore, mutex, and double buffering), enabling you to make trade-offs among data integrity, determinism, and performance
- Overrun detection for incorporating error-handling logic for each rate
Legacy Code Integration
You can customize the generated code and its run-time environment by incorporating custom legacy C, Fortran, Ada, and C++ code for simulation and code generation. Customization tools in Simulink Coder include a Target Language Compiler (TLC), custom code blocks, template makefiles, build process APIs, and S-Function Builder. Using the Legacy Code Tool, you can rapidly integrate existing C and C++ functions into your Simulink models, which is particularly useful for integrating discrete-time code typically used in embedded systems.