code generation with autosar code replacement library -凯发k8网页登录

main content

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.

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 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 .

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:

  1. generates model code. mathworks® host library implementations are used in ifx, ifl, mfx, and mfl routine code replacements.

  2. builds the sil application. the host library is linked to the sil executable.

  3. 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.

autosar_lut_model_com.png

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.

autosar_lut_com_block2.png

for details about configuring the blocks in this example, see .

  1. 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'.

  2. 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'.

  3. build the model and review the generated code for expected code replacements. for example, search the generated code for the routine prefix ifl.

autosar_lut_ccode_com.png

required algorithm property settings for ifl/ifx function and block mappings

ifl/ifx function and block mappingalgorithm property parametersvalue

ifl_dpsearch

prelookup

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

use last breakpoint for input at or above upper limit

uselastbreakpoint

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

ifl_ipocur

interpolation using prelookup

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

valid index input may reach last index

validindexmayreachlast

on

remove protection against out-of-range index in generated code

removeprotectionindex

off

integer rounding mode

rndmeth

round or zero

ifl_ipomap

interpolation using prelookup

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

valid index input may reach last index

validindexmayreachlast

on

remove protection against out-of-range index in generated code

removeprotectionindex

off

integer rounding mode

rndmeth

round or zero

ifl_intipocur

n-d lookup table

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

ifl_intipomap

n-d lookup table

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

ifx_dpsearch

prelookup

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

use last breakpoint for input at or above upper limit

uselastbreakpoint

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

ifx_ipocur

interpolation using prelookup

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

valid index input may reach last index

validindexmayreachlast

on

remove protection against out-of-range index in generated code

removeprotectionindex

off

integer rounding mode

rndmeth

round or zero

ifx_lkupcur

interpolation using prelookup

interpolation method

interpmethod

flat

extrapolation method

extrapmethod

clip

remove protection against out-of-range index in generated code

removeprotectionindex

off

integer rounding mode

rndmeth

round or zero

valid index input may reach last index

validindexmayreachlast

on

ifx_ipomap

interpolation using prelookup

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

valid index input may reach last index

validindexmayreachlast

on

remove protection against out-of-range index in generated code

removeprotectionindex

off

integer rounding mode

rndmeth

round or zero

ifx_lkupmap

interpolation using prelookup

interpolation method

interpmethod

nearest

extrapolation method

extrapmethod

clip

remove protection against out-of-range index in generated code

removeprotectionindex

off

integer rounding mode

rndmeth

round or zero

valid index input may reach last index

validindexmayreachlast

on

ifx_lkupbasemap

interpolation using prelookup

interpolation method

interpmethod

flat

extrapolation method

extrapmethod

clip

remove protection against out-of-range index in generated code

removeprotectionindex

off

integer rounding mode

rndmeth

round or zero

valid index input may reach last index

validindexmayreachlast

on

ifx_intipocur

n-d lookup table

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

ifx_intlkupcur

n-d lookup table

interpolation method

interpmethod

flat

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

ifx_intipofixcur

n-d lookup table

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

model configuration parameter optimization > default parameter behavior

defaultparameterbehavior

inlined

breakpoint data should match power 2 spacing.

 

ifx_intlkupfixcur

n-d lookup table

interpolation method

interpmethod

flat

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

model configuration parameter optimization > signals and parameters > default parameter behavior

defaultparameterbehavior

inlined

breakpoint data must match power 2 spacing.

 

ifx_intipofixicur

n-d lookup table

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

breakpoint data must not match power 2 spacing.

 

ifx_intlkupfixicur

n-d lookup table

interpolation method

interpmethod

flat

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

breakpoint data must not match power 2 spacing.

 

ifx_intipomap

n-d lookup table

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

ifx_intlkupmap

n-d lookup table

interpolation method

interpmethod

nearest

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

ifx_intlkupbasemap

n-d lookup table

interpolation method

interpmethod

flat

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

linear search or binary search

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

ifx_intipofixmap

n-d lookup table

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

model configuration parameter optimization > signals and parameters > default parameter behavior

defaultparameterbehavior

inlined

breakpoint data must match power 2 spacing.

 

ifx_intlkupfixmap

n-d lookup table

interpolation method

interpmethod

nearest

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

model configuration parameter optimization > signals and parameters > default parameter behavior

defaultparameterbehavior

inlined

breakpoint data must match power 2 spacing.

 

ifx_intlkupfixbasemap

n-d lookup table

interpolation method

interpmethod

flat

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

model configuration parameter optimization > signals and parameters > default parameter behavior

defaultparameterbehavior

inlined

breakpoint data must match power 2 spacing.

 

ifx_intipofiximap

n-d lookup table

interpolation method

interpmethod

linear

extrapolation method

extrapmethod

linear

index search method

indexsearchmethod

evenly spaced points

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

breakpoint data must not match power 2 spacing.

 

ifx_intlkupfiximap

n-d lookup table

interpolation method

interpmethod

nearest

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

breakpoint data must not match power 2 spacing.

 

ifx_intlkupfixibasemap

n-d lookup table

interpolation method

interpmethod

flat

extrapolation method

extrapmethod

clip

index search method

indexsearchmethod

evenly spaced points

remove protection against out-of-range input in generated code

removeprotectioninput

off

integer rounding mode

rndmeth

round or zero

use last table value for inputs at or above last breakpoint

uselasttablevalue

on

breakpoint data must not match power 2 spacing.

 

related examples

    more about

    • (embedded coder)
    网站地图