Generate C and C++ code optimized for embedded systems
Embedded Coder® generates readable, compact, and fast C and C++ code for embedded processors used in mass production. It extends MATLAB Coder™ and Simulink Coder™ with advanced optimizations for precise control of the generated functions, files, and data. These optimizations improve code efficiency and facilitate integration with legacy code, data types, and calibration parameters. You can incorporate a third-party development tool to build an executable for turnkey deployment on your embedded system or rapid prototyping board.
Embedded Coder offers built-in support for AUTOSAR, MISRA C®, and ASAP2 software standards. It also provides traceability reports, code documentation, and automated software verification to support DO-178, IEC 61508, and ISO 26262 software development. Embedded Coder code is portable, and can be compiled and executed on any processor. In addition, Embedded Coder offers support packages with advanced optimizations and device drivers for specific hardware.
To configure code generation settings for Embedded Coder®, you use the MATLAB Coder app for MATLAB® or Embedded Coder Quick Start for Simulink. You can also configure each setting directly using MATLAB commands and scripts.
From the MATLAB Coder app, you can:
- Generate code for your MATLAB files and functions
- Select your processor and code generation output
- Choose Embedded Coder optimizations
From the Embedded Coder Quick Start for Simulink, you can:
- Generate code for your Simulink models and subsystems
- Select your processor and code generation output
- Choose Embedded Coder to optimize for RAM or execution speed
For MATLAB, you specify one of the following output targets:
- C/C++ static library
- C/C++ executable
For Simulink, you specify one of the ready-to-run configurations, which include:
Embedded Real-Time Target — Generates ANSI/ISO C, C++, and encapsulated C++ code with floating-point and fixed-point data for efficient real-time execution on virtually any production processor
AUTOSAR Target — Generates C code and run-time interfaces that support development of AUTOSAR software components (requires AUTOSAR Blockset)
Shared Library Target — Generates a shared library version of your code for host platform execution, either as a Windows® dynamic link library (.dll) file or a UNIX® shared object (.so) file
In addition, MathWorks and third parties offer MATLAB add-ons that extend Embedded Coder to support specific hardware including ARM®, Intel®, NXP™, STMicroelectronics®, and Texas Instruments™.
Embedded Coder enables you to define and control how the model data appears in the generated code to facilitate software integration.
For MATLAB code, Embedded Coder supports all MATLAB Coder data definitions including fixed-point objects and predefined storage classes.
For Simulink models, Embedded Coder supports the following data dictionary and specification capabilities:
Embedded Coder Dictionary — Lets you view and customize code definitions including function interfaces, storage classes, and memory sections
Simulink data object — Provides predefined storage classes, including constant, volatile, exported global, imported global, define directive, structure, bit field (including bit-packed structure), and get and set access methods
Module packaging data object — Provides preconfigured attributes for advanced data objects typically used in mass production, such as memory segments to calibrate or tune lookup tables
User data type — Lets you create abstract types for complex data so you can precisely control how model data appears in the generated code, interface with any legacy data, and augment or replace Simulink built-in types
Embedded Coder gives you access to ASAP2 data exchange files in Simulink, enabling you to export model data with complex data definitions using the ASAP2 standard. You can modify the built-in capabilities to produce other data exchange mechanisms.
Using Embedded Coder, you can control function boundaries, preserve expressions, and apply optimizations on multiple blocks to further reduce code size. Data is exchanged with the generated code via global variables or function arguments. You can trace the generated code to blocks and signals in your model.
Embedded Coder options for generating code from MATLAB code and Simulink models enable you to:
- Generate processor-specific code for math functions and operators
- Reuse code for exporting to legacy or external environments
- Eliminate unnecessary initialization, termination, logging, and error-handling code
- Remove floating-point code from integer-only applications
Additional Embedded Coder optimization and configuration options are available for Simulink models, enabling you to:
- Generate code variants using macros for preprocessor compilation
- Control the format of each generated file
- Determine how global data is defined and referenced
- Specify the contents and placement of comments
Embedded Coder offers several capabilities for examining generated code for your MATLAB files and functions or your Simulink models and subsystems. Using these capabilities, you can:
- Generate a code report describing the code modules, function interfaces, and static code metrics
- Control identifier formats for generated global data, data types, and functions
- Include MATLAB code as comments in generated code, including function help text
With Simulink, Embedded Coder also provides the ability to insert high-level requirements as code comments with links to the requirement source (requires Simulink Requirements™). The code report for Simulink code generation also includes a code interface description, traceability report, and display of generated source files and code. Bidirectional links exist between the model and generated code, making it easy to navigate between every line of code and its corresponding Simulink model element, including subsystems, blocks, MATLAB functions and code, and Stateflow® charts and transitions.
Embedded Coder enables you to incorporate generated code into your code execution environment.
With MATLAB, the code generated from Embedded Coder executes using the same execution framework as provided by MATLAB Coder.
With Simulink, Embedded Coder significantly extends the real-time execution framework provided by Simulink Coder. By default, the code can be executed with or without a real-time operating system (RTOS) and in single-tasking, multitasking, multicore, or asynchronous mode. You can also verify the code execution results using Embedded Coder for software-in-the-loop (SIL) and processor-in-the-loop (PIL) testing. Simulink TestTM and Simulink Coverage help automate test execution, result comparison, and coverage analysis. Code execution profiling analysis is also supported.
Generating a Main Program
Embedded Coder generates an extensible main program based on information you provide for deploying the code in your real-time environment. This capability lets you generate and build a complete customized executable from your model.
Executing Multirate, Multitask, and Multicore Code
Embedded Coder generates single-rate or multirate code using periodic sample times specified in the model. For multirate, multitasking models, it employs a strategy called rate grouping that generates separate functions for the base rate task and for each subrate task in the model. You can also use Simulink Concurrent Execution modeling to produce multithreaded code for multicore processing.
Performing SIL and PIL Testing
Embedded Coder automates execution of generated code in Simulink for SIL testing or on the embedded target for PIL testing using Simulink simulation modes or S-function blocks. Simulink Test™ helps automate test execution and comparison of test results to simulation results from the original model. Structural code coverage analysis to measure test completeness can be performed with Simulink Coverage or with integration with third-party tools. Code profiling analysis provides execution time on host or target processors.
Reduced Data Copies
Generate code with fewer data copies for models that use Data Store Memory blocks to store large bus structures in a model reference hierarchy
Optimized C++ for Reusable Functions
Generate C++ code for reusable functions as private methods inside a class, unless reused across models
SIMD Vectorization for Loops
Use SIMD intrinsics to vectorize loops and arrays for Intel and Arm® processors
Perform one-click back-to-back testing using software-in-the-loop (SIL) and processor-in-the-loop (PIL) simulations
Code Coverage in Code View
View code coverage results from SIL and PIL testing in the Code view
Use symbolic dimensions in Stateflow charts using C action language
Calibration and Monitoring Through XCP and Third-Party Tools
Generate code that supports parameter tuning and signal monitoring through an ASAM MCD-1 XCP communication channel and third-party calibration tools such as ETAS INCA and Vector CANape
Use Cygwin as the recommended toolchain on Windows to build and deploy algorithms to Pixhawk autopilots