If your model is configured for AUTOSAR code generation, you can use the AUTOSAR 4.0 code replacement library to produce functions that closely align with the AUTOSAR standard.
The AUTOSAR 4.0 code replacement library enables you to customize the code generator to produce C code that closely aligns with the AUTOSAR standard. Consider using the code replacement library if:
You want to use service routines provided in the library.
You have replacement code for the service routines.
The replacement code follows the AUTOSAR file naming convention, that is,
routines for any given specification are in one header file (for example,
You have a build harness setup that can compile and link the AUTOSAR library with the generated code. For more information about building code for AUTOSAR, see Code Generation.
MATLAB® and Simulink® lookup table indexing differs from AUTOSAR MAP indexing. MATLAB takes the linear algebra approach—row (
and column (
u2). AUTOSAR (and ASAM) takes the Cartesian
coordinate approach—x-axis (
u2) and y-axis
are input arguments to Simulink 2-D lookup table blocks. Due to the difference, the code replacement
software transposes the input arguments for AUTOSAR MAP routines.
To explore the AUTOSAR library routines supported by the AUTOSAR code replacement
library, use the Code Replacement Viewer (Embedded Coder). To open the viewer,
at the command prompt, enter
For more information, see Choose a Code Replacement Library (Embedded Coder).
To configure the code generator to use the AUTOSAR code replacement library for your model, open the Configuration Parameters dialog box. Select Code Generation > Interface > Code replacement libraries > AUTOSAR 4.0.
Code replacement requires that the combination of types for input, breakpoint, table, and output types are compatible with the AUTOSAR specification. Floating-point (IFL) replacement only supports single types while fixed-point (IFX) replacement supports uint8, uint16, int8, int16 and associated fixed-point types. When using these routine blocks, the type combination requirements vary and are enforced as required.
The Code Replacement Viewer lists AUTOSAR floating-point interpolation (IFL) and fixed-point interpolation (IFX) library routines that you can generate in lookup table C code. For replacing lookup table C code with IFL or IFX library routines, AUTOSAR Blockset provides lookup table blocks that are preconfigured for AUTOSAR code generation. You insert a block such as Curve or Map in your model, then open the block dialog box and configure the block to generate a specific interpolation routine required by your design. For more information, see Configure Lookup Tables for AUTOSAR Measurement and Calibration.
This example shows how to replace code generated for AUTOSAR lookup table blocks with functions that are compatible with AUTOSAR IFL library routines. If you want to replace code with IFX library routines, you can edit the lookup table block dialog boxes to change the targeted routine library.
Create your Simulink model by using any of these AUTOSAR lookup table blocks: Prelookup, Curve Using Prelookup, Map Using Prelookup, Curve, or Map. For example, here is a Prelookup block connected to a Curve Using Prelookup block.
Alternatively, you can open the AUTOSAR example model
mAutosarLutObjs.slx, which contains the displayed blocks.
To copy the model file to your working folder, enter this MATLAB command:
Open each lookup table block and configure it to generate a routine from the AUTOSAR 4.0 code replacement library (CRL). As you modify block settings, the block dialog box updates the name of the targeted AUTOSAR routine.
For details about configuring the blocks in this example, see Configure COM_AXIS Lookup Tables by Using Lookup Table and Breakpoint Objects.
Configure the code generator to use the AUTOSAR 4.0 CRL for your model. In the
Configuration Parameters dialog box, select Code Generation > Interface > Code replacement libraries > AUTOSAR 4.0. Alternatively, from the command line or programmatically, use
set_param to set the
CodeReplacementLibrary parameter to
Optionally, you can configure the model to produce a code generation report
that summarizes which blocks trigger code replacements. In the Configuration
Parameters dialog box, in the Code Generation > Report pane, select the option Summarize which blocks triggered
code replacements. Alternatively, from the command line or
set_param to set the
GenerateCodeReplacementReport parameter to
Build the model and review the generated code for expected code replacements.
For example, search the generated code for the routine prefix