目录

1. 模型搭建

2. 添加测试模型

3. 运行仿真

4. 代码生成

5. 总结 


1. 模型搭建

要开始在软件架构画布中开发AUTOSAR compositions和 components,需要创建一个AUTOSAR架构模型(需要System Composer)。

1. 创建架构模型

(1) 在Simulink窗口,创建新的Architecture如下图

Autotest开源库 autosar开源代码_代码生成

(2) 选择AUTOSAR Blockset,并得到如下的Autosar架构画布,并保存

Autotest开源库 autosar开源代码_autosar_02

Autotest开源库 autosar开源代码_simulink_03

(3) 根据自己的项目实际情况添加软件组合或者软件组件,如图这里举例创建了三个不同时间周期的任务,另外可根据实际需求创建不同的软件算法模块

Autotest开源库 autosar开源代码_Composer_04

 (4) 把生成Embedded代码的模型放到Autosar的架构里,如下是生成Embedded code的模型

 

Autotest开源库 autosar开源代码_代码生成_05

 (5) 把模型按照定义的Task进行分类,新建一个子模型,这里命名为Task_10ms

 

Autotest开源库 autosar开源代码_autosar_06

 (6)配置模型步长为10ms,定步长离散域

Autotest开源库 autosar开源代码_autosar_07

  (7)配置硬件参数,生成代码选择autosar.tlc

Autotest开源库 autosar开源代码_Autotest开源库_08

   (8)配置Autosar的版本,需要考虑和BSW用的版本对应

Autotest开源库 autosar开源代码_autosar_09

  (9) 调整模型的算法模块输入输出类型如下, Bus Element In 和 Bus Element Out, 其他软件Task也用这种方法,分别创建不同的模型

Autotest开源库 autosar开源代码_Autotest开源库_10

Autotest开源库 autosar开源代码_autosar_11

 配置输入输出的数据类型

Autotest开源库 autosar开源代码_Autotest开源库_12

 最后得到每个算法模块的模型,如下:

Autotest开源库 autosar开源代码_Composer_13

 (10) 用Software component调用各个算法模型

Autotest开源库 autosar开源代码_autosar_14

全都调用后如下图所示 

Autotest开源库 autosar开源代码_Autotest开源库_15

 (11) 最后连接每一个模块

Autotest开源库 autosar开源代码_代码生成_16

到这一步,Composition就创建好了,我们需要用到台架测试能否正常工作

2. 添加测试模型

 (1)替换到原先生成Eembedded代码的模型 

Autotest开源库 autosar开源代码_autosar_17

 (2)信号的输入需要添加Bus creator 输出需要添加Bus selector

Autotest开源库 autosar开源代码_Autotest开源库_18

3. 运行仿真

 仿真效果与Embedded code的模型一样,没有问题

 

Autotest开源库 autosar开源代码_Composer_19

4. 代码生成

(1)点Export, 找到Generata Code and ARXML

Autotest开源库 autosar开源代码_代码生成_20

 (2)选择把代码和ARXML打包成zip

Autotest开源库 autosar开源代码_simulink_21

 (3)等待生成代码的过程,出现如下表示生成完成

 

Autotest开源库 autosar开源代码_Composer_22

  (4)生成的代码和ARXML文件

Autotest开源库 autosar开源代码_Composer_23

Autotest开源库 autosar开源代码_Composer_24

5. 总结 

 以上就是用Autosar的架构系统仿真和代码生成,对于Autosar的软件结构,数据结构还有很多内容需要学习,以上只是演示如何利用Simulink的System Composer功能完成架构的设计,怎么把嵌入式的模型调整成架构式的模型,对于代码生成也同样有很多需要了解和配置的地方,有时间再总结吧