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 is intended for use with AUTOSAR schema version 4.0 or later.
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,
Mfl.h
or Mfx.h
)
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 (u1
)
and column (u2
). AUTOSAR (and ASAM) takes the Cartesian
coordinate approach—x-axis (u2
) and y-axis
(u1
), where u1
and u2
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.
For more information on code replacement and code replacement libraries, see What Is Code Replacement? (Embedded Coder) and Code Replacement Libraries (Embedded Coder).
To explore the AUTOSAR library routines supported by the AUTOSAR code replacement
library, use the Code Replacement Viewer. To open the viewer,
at the command prompt, enter crviewer
.
For more information, see Choose a Code Replacement Library (Embedded Coder).
To configure the code generator for your model to use the AUTOSAR code replacement library, open the Configuration Parameters dialog box. Select Code Generation > Interface > Code replacement library > AUTOSAR 4.0.
For more information on code replacement and code replacement libraries, see What Is Code Replacement? (Embedded Coder) and Code Replacement Libraries (Embedded Coder).
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.
This example shows how to replace code generated for Simulink lookup table blocks with functions that are compatible with AUTOSAR floating-point interpolation (IFL) library routines. If you want to replace code with fixed-point interpolation (IFX) library routines, you can change the type and reconfigure the block.
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:
Configure the code generator for your model to use the AUTOSAR 4.0 code
replacement library. In the Configuration Parameters dialog box, select Code Generation > Interface > Code replacement library > AUTOSAR 4.0. Alternatively, from the command line or programmatically, use
set_param
to set the
CodeReplacementLibrary
parameter to 'AUTOSAR
4.0'
.
Optionally, you can configure the model for the code generator 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
programmatically, use set_param
to set the
GenerateCodeReplacementReport
parameter to
'on'
.
Build the model and review the generated code for expected code replacements.
For example: