code generation with autosar code replacement library
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.
configure code generator to use autosar 4.0 code replacement library
autosar code replacement library example for ifx/ifl function replacement
required algorithm property settings for ifl/ifx function and block mappings
code replacement library for autosar code generation
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
ormfx.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 .
note
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 (embedded coder) and (embedded coder).
find supported autosar library routines
to explore the autosar library routines supported by the autosar code replacement
library, use the (embedded coder). to open the viewer,
at the command prompt, enter crviewer('autosar 4.0')
.
for more information, see (simulink coder).
configure code generator to use autosar 4.0 code replacement library
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.
for more information on code replacement and code replacement libraries, see (embedded coder) and (embedded coder).
autosar 4.0 library host code verification
to help support matlab host code verification for autosar models, autosar blockset provides host implementations of ifx, ifl, mfx, and mfl routines in the autosar 4.0 library. the host library implementations enable software-in-the-loop (sil) validation for models that trigger code replacements from the autosar 4.0 library.
consider the following autosar model, which contains interpolation and math blocks
that have been tuned to trigger autosar ifx and mfx routine code replacements. in the
model configuration parameters, (simulink coder) is set to autosar.tlc
and (embedded coder) is set to autosar 4.0
.
configure and run a sil simulation of the model. the sil simulation:
generates model code. mathworks® host library implementations are used in ifx, ifl, mfx, and mfl routine code replacements.
builds the sil application. the host library is linked to the sil executable.
runs the model and produces simulation output, based on your sil settings.
if you prefer to use your own host library or custom code for sil simulations, you can disable the mathworks host library by using the following command:
set_param(modelname,'disableautosarroutineshostlibrary','on');
code replacement library checks
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.
autosar code replacement library example for ifx/ifl function replacement
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 blocks 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 .
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.
you can create your simulink model by using any of these autosar lookup table blocks: , , , , or . for example, here is a prelookup block connected to a curve using prelookup block.
you can also open the model file by entering the following command at the matlab® command line:
open_system('mautosarlutobjs');
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 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 to set the
codereplacementlibrary
parameter to'autosar 4.0'
.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 programmatically, use to set the
generatecodereplacementreport
parameter to'on'
.build the model and review the generated code for expected code replacements. for example, search the generated code for the routine prefix
ifl
.
required algorithm property settings for ifl/ifx function and block mappings
ifl/ifx function and block mapping | algorithm property parameters | value |
---|---|---|
prelookup | extrapolation method
|
|
index search method
|
| |
use last breakpoint for input at or above upper limit
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
interpolation using prelookup | interpolation method
|
|
extrapolation method
|
| |
valid index input may reach last index
| on | |
remove protection against out-of-range index in generated code
| off | |
integer rounding mode
|
| |
interpolation using prelookup | interpolation method
|
|
extrapolation method
|
| |
valid index input may reach last index
| on | |
remove protection against out-of-range index in generated code
| off | |
integer rounding mode
|
| |
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
use last table value for inputs at or above last breakpoint
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
use last table value for inputs at or above last breakpoint
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
prelookup | extrapolation method
| clip |
index search method
|
| |
use last breakpoint for input at or above upper limit
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
interpolation using prelookup | interpolation method
|
|
extrapolation method
|
| |
valid index input may reach last index
| on | |
remove protection against out-of-range index in generated code
| off | |
integer rounding mode
|
| |
interpolation using prelookup | interpolation method
|
|
extrapolation method
|
| |
remove protection against out-of-range index in generated code
| off | |
integer rounding mode
|
| |
valid index input may reach last index
| on | |
interpolation using prelookup | interpolation method
|
|
extrapolation method
|
| |
valid index input may reach last index
| on | |
remove protection against out-of-range index in generated code
| off | |
integer rounding mode
|
| |
interpolation using prelookup | interpolation method
|
|
extrapolation method
|
| |
remove protection against out-of-range index in generated code
| off | |
integer rounding mode
|
| |
valid index input may reach last index
| on | |
interpolation using prelookup | interpolation method
|
|
extrapolation method
|
| |
remove protection against out-of-range index in generated code
| off | |
integer rounding mode
|
| |
valid index input may reach last index
| on | |
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
use last table value for inputs at or above last breakpoint
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
use last table value for inputs at or above last breakpoint
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
model configuration parameter optimization > default parameter behavior
|
| |
breakpoint data should match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
model configuration parameter optimization > signals and parameters > default parameter behavior
|
| |
breakpoint data must match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
use last table value for inputs at or above last breakpoint
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
breakpoint data must not match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
breakpoint data must not match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
use last table value for inputs at or above last breakpoint
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
use last table value for inputs at or above last breakpoint
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
model configuration parameter optimization > signals and parameters > default parameter behavior
|
| |
breakpoint data must match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
model configuration parameter optimization > signals and parameters > default parameter behavior
|
| |
breakpoint data must match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
model configuration parameter optimization > signals and parameters > default parameter behavior
|
| |
breakpoint data must match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
use last table value for inputs at or above last breakpoint
| on | |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
breakpoint data must not match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
breakpoint data must not match power 2 spacing. | ||
n-d lookup table | interpolation method
|
|
extrapolation method
|
| |
index search method
|
| |
remove protection against out-of-range input in generated code
| off | |
integer rounding mode
|
| |
use last table value for inputs at or above last breakpoint
| on | |
breakpoint data must not match power 2 spacing. |
related examples
more about
- (embedded coder)