Main Content

代码生成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

这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:

  • 您要使用库中提供的服务例程。

  • 您的服务例程具有替换代码。

  • 替换代码遵循AutoSar文件命名约定,即任何给定规范的例程都在一个标头文件中(例如,Mfl.horMFX.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代码生成

笔记

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), 在哪里U1andU2are 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什么是代码替换?(嵌入式编码器)and代码更换库(嵌入式编码器)

Find Supported AUTOSAR Library Routines

To explore the AUTOSAR library routines supported by the AUTOSAR code replacement library, use the代码更换查看器(嵌入式编码器)。To open the viewer, at the command prompt, enterCRViewer('AutoSar 4.0')

有关更多信息,请参阅Choose a Code Replacement Library(嵌入式编码器)

配置代码生成器以使用AutoSar 4.0代码替换库

To configure the code generator to use the AUTOSAR code replacement library for your model, open the Configuration Parameters dialog box. Select代码生成>界面>代码更换库>AUTOSAR 4.0

For more information on code replacement and code replacement libraries, see什么是代码替换?(嵌入式编码器)and代码更换库(嵌入式编码器)

AUTOSAR 4.0 Library Host Code Verification

To help support MATLAB host code verification for AUTOSAR models,AUTOSAR Blockset在AutoSar 4.0库中提供IFX,IFL,MFX和MFL例程的主机实现。主机库实现启用了循环中的软件(SIL)验证,以触发从Autosar 4.0库中替换代码的模型。

考虑以下AutoSar模型,其中包含插值和数学块,这些模型已调整为触发AutoSar IFX和MFX例程代码更换。在模型配置参数中,系统目标文件(万博1manbetxSimulink编码器)is set toautosar.tlcand代码更换库(嵌入式编码器)is set toAUTOSAR 4.0

配置并运行模型的SIL模拟。SIL模拟:

  1. 生成模型代码。数学工作®主机库实现在IFX,IFL,MFX和MFL例程代码更换中使用。

  2. Builds the SIL application. The host library is linked to the SIL executable.

  3. 根据您的SIL设置运行模型并产生模拟输出。

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

代码更换查看器列表Autosar浮点插值(IFL)和定点插值(IFX)库例程,您可以在查找表C代码中生成。要用IFL或IFX库例程替换查找表C代码,AUTOSAR Blockset提供对AutoSar代码生成预配置的查找表块。您插入一个块CurveorMap在模型中,然后打开“块”对话框并配置块以生成设计所需的特定插值例程。有关更多信息,请参阅配置查找表进行汽车校准和测量

此示例显示了如何使用与AutoSar IFL库例程兼容的函数替换为AutoSar查找表块生成的代码。如果要用IFX库例程替换代码,则可以编辑“查找表”块对话框,以更改目标例程库。

  1. 通过使用任何这些Auto万博1manbetxSar查找表块创建Simulink模型:prolookup,,,,Curve Using Prelookup,,,,Map Using Prelookup,,,,Curve, 或者Map。For example, here is aprolookupblock connected to aCurve Using Prelookup堵塞。

    另外,您可以打开AutoSar示例模型mautosarlutobjs.slx,,,,which contains the displayed blocks. To copy the model file to your working folder, enter this MATLAB command:

    copyfile(fullfile(matlabroot,'help/toolbox/autosar/示例/mautosarlutobjs.slx'),'。')。
  2. 打开每个查找表块并将其配置为从AutoSar 4.0代码替换库(CRL)生成例程。在修改块设置时,“块”对话框更新了目标汽车例程的名称。

    For details about configuring the blocks in this example, see使用查找表和断点对象配置COM_AXIS查找表

  3. Configure the code generator to use the AUTOSAR 4.0 CRL for your model. In the Configuration Parameters dialog box, select代码生成>界面>代码更换库>AUTOSAR 4.0。或者,从命令行或编程中,使用set_param设置CodeReplacementLibrary参数为'Autosar 4.0'

  4. 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代码生成>报告pane, select the optionSummarize which blocks triggered code replacements。或者,从命令行或编程中,使用set_param设置GenerateCodeReplacementReport参数为'上'

  5. 构建模型并查看预期代码更换的生成代码。例如,搜索生成的代码查看例程前缀ifl

Required Algorithm Property Settings for IFL/IFX Function and Block Mappings

IFL/IFX Function and Block Mapping 算法属性参数 Value

ifl_dpsearch

prolookup

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

以上使用最后一个断点输入上mit

UselastBreakpoint

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

ifl_IpoCur

使用预插条插值

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

有效的索引输入可能达到最后一个索引

ValidIndexMayReachLast

On

在生成的代码中删除针对范围内索引的保护

删除PrototectionIndex

Off

整数圆形模式

rndmeth

Roundor

IFL_IPOMAP

使用预插条插值

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

有效的索引输入可能达到最后一个索引

ValidIndexMayReachLast

On

在生成的代码中删除针对范围内索引的保护

删除PrototectionIndex

Off

整数圆形模式

rndmeth

Roundor

ifl_IntIpoCur

N-D查找表

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

ifl_intipomap

N-D查找表

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

Ifx_DPSearch

prolookup

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

以上使用最后一个断点输入上mit

UselastBreakpoint

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

IFX_IPOCUR

使用预插条插值

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

有效的索引输入可能达到最后一个索引

ValidIndexMayReachLast

On

在生成的代码中删除针对范围内索引的保护

删除PrototectionIndex

Off

整数圆形模式

rndmeth

Roundor

Ifx_LkUpCur

使用预插条插值

Interpolation method

InterpMethod

Flat

外推法

ExtrapMethod

Clip

在生成的代码中删除针对范围内索引的保护

删除PrototectionIndex

Off

整数圆形模式

rndmeth

Roundor

有效的索引输入可能达到最后一个索引

ValidIndexMayReachLast

On

IFX_IPOMAP

使用预插条插值

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

有效的索引输入可能达到最后一个索引

ValidIndexMayReachLast

On

在生成的代码中删除针对范围内索引的保护

删除PrototectionIndex

Off

整数圆形模式

rndmeth

Roundor

IFX_LKUPMAP

使用预插条插值

Interpolation method

InterpMethod

最近

外推法

ExtrapMethod

Clip

在生成的代码中删除针对范围内索引的保护

删除PrototectionIndex

Off

整数圆形模式

rndmeth

Roundor

有效的索引输入可能达到最后一个索引

ValidIndexMayReachLast

On

IFX_LKUPBASEMAP

使用预插条插值

Interpolation method

InterpMethod

Flat

外推法

ExtrapMethod

Clip

在生成的代码中删除针对范围内索引的保护

删除PrototectionIndex

Off

整数圆形模式

rndmeth

Roundor

有效的索引输入可能达到最后一个索引

ValidIndexMayReachLast

On

Ifx_IntIpoCur

N-D查找表

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

ifx_intlkupcur

N-D查找表

Interpolation method

InterpMethod

Flat

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

Ifx_IntIpoFixCur

N-D查找表

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

模型配置参数Optimization>Default parameter behavior

DefaultParameterBehavior

Inlined

Breakpoint data should match power 2 spacing.

Ifx_IntLkUpFixCur

N-D查找表

Interpolation method

InterpMethod

Flat

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

模型配置参数Optimization>Signals and Parameters>Default parameter behavior

DefaultParameterBehavior

Inlined

断点数据必须匹配功率2间距。

ifx_intipofixicur

N-D查找表

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

Breakpoint data must not match power 2 spacing.

ifx_intlkupfixicur

N-D查找表

Interpolation method

InterpMethod

Flat

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

Breakpoint data must not match power 2 spacing.

ifx_intipomap

N-D查找表

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

Ifx_IntLkUpMap

N-D查找表

Interpolation method

InterpMethod

最近

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

Ifx_IntLkUpBaseMap

N-D查找表

Interpolation method

InterpMethod

Flat

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

线性搜索or二进制搜索

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

ifx_intipofixmap

N-D查找表

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

模型配置参数Optimization>Signals and Parameters>Default parameter behavior

DefaultParameterBehavior

Inlined

断点数据必须匹配功率2间距。

ifx_intlkupfixmap

N-D查找表

Interpolation method

InterpMethod

最近

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

模型配置参数Optimization>Signals and Parameters>Default parameter behavior

DefaultParameterBehavior

Inlined

断点数据必须匹配功率2间距。

ifx_intlkupfixbasemap

N-D查找表

Interpolation method

InterpMethod

Flat

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

模型配置参数Optimization>Signals and Parameters>Default parameter behavior

DefaultParameterBehavior

Inlined

断点数据必须匹配功率2间距。

Ifx_IntIpoFixIMap

N-D查找表

Interpolation method

InterpMethod

Linear

外推法

ExtrapMethod

Linear

索引搜索方法

IndexSearchMethod

Evenly spaced points

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

Breakpoint data must not match power 2 spacing.

Ifx_IntLkUpFixIMap

N-D查找表

Interpolation method

InterpMethod

最近

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

Breakpoint data must not match power 2 spacing.

Ifx_IntLkUpFixIBaseMap

N-D查找表

Interpolation method

InterpMethod

Flat

外推法

ExtrapMethod

Clip

索引搜索方法

IndexSearchMethod

Evenly spaced points

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

RemoveProtectionInput

Off

整数圆形模式

rndmeth

Roundor

在最后一个断点或以上的输入中使用最后一个表值

UseLastTableValue

On

Breakpoint data must not match power 2 spacing.

相关示例

更多关于