当前位置:
文档之家› 嵌入式代码自动生成_周玲_mathworks
嵌入式代码自动生成_周玲_mathworks
嵌入式代码自动生成
周玲/ Ling.Zhou@ 应用工程师 201406
© 2014 The MathWorks, Inc. 1
目录
代码生成概述
代码结构控制
模型数据管理 代码生成的优化 代码生成相关
2
目录
代码生成概述
代码结构控制
模型数据管理 代码生成的优化 代码生成相关
12
示例- 可配置的代码生成
代码结构控制
模型数据管理 代码生成的优化 代码生成相关
14
默认入口函数原型
<model>_initialize()
– initialize signals, states and parameters prior to first time step
32
代码优化工具
33
目录
代码生成概述
代码结构控制
模型数据管理 代码生成的优化 代码生成相关
34
其它话题
Scheduler Multi-rate Multi-tasking Optimizing Code Customer Code Integration Customer Storage Class Target Language Compiler AUTOSAR Support ……
“Growth of top end automotive embedded software has been exponential.”
Robert Gee Director of Strategy for Motorola Automotive
High-level architectural planning Algorithm development with models Automatic generation of code from models Industry-wide standardization of interfaces and common functionality
28
目录
代码生成概述
代码结构控制
模型数据管理 代码生成的优化 代码生成相关
29
代码生成统计报告
30
移除不需要的代码或数据支持
Removing initialization code (Optimization pane) Removing termination code (Interface pane) Removing data support (Interface pane) Disabling MAT-File Logging (Interface pane) Conditional Input Branch Execution (Optimization pane)
RGBSplit-4
I N P U T B L U E
V P O W E R
R C S
G
R E E N
R E D
Sensors CCP
Special Interfaces
ASAP2
Most Development is on Core Software Algorithms
Scheduler/Operating System And Support Utilities
4
代码量的爆炸式增长
Estimated Source Lines of Code (LOC) Today’s powertrain: 500,000 LOC Today’s vehicles: 1,000,000 LOC 2015 vehicles: 100,000,000 LOC
Management trends:
Learn more from MathWorks Training Service - Embedded Coder for Production Code Generation (3 days)
35
MathWorks在中国的技术支持体系
在中国提供多层次的技术支持
应用工程师: 负责产品层面的支持,有丰富产品和行业知识 Pilot 工程师: 结合用户实际项目,提供指导支持,有实际项目经 验同时对工具链熟悉 技术咨询顾问团队:全部是行业和产品专家,有着丰富的实际项 目经验,目前主要在北美和欧洲,服务于全球,在中国已经开始 建立团队 培训服务:提供公开课和现场的收费培训,可以针对行业定制。 技术支持热线:对服务期内正版用户提供 5×8 的电话技术支持
Fixed-point
Word size Signed/unsigned Scaling 22
定义数据类型
23
定义存储类型
model.c
model_private.h
24
算法模型与数据保持独立
Name Description Data type Value
Storage class
Rest of model (algorithm, system dynamics, etc.)
/support/contact_us/
36
联系我们
官方网站: 官方微博: MATLAB 官方社区(英文): 中文社区: 联系电话(总机):010 – 59827000 联系地址:
迈斯沃克软件 (北京) 有限公司 北京市海淀区科学院南路2号 融科资讯中心C座南楼3层301
迈斯沃克软件 (北京) 有限公司上海分公司 上海市浦东新区竹林路101号 陆家嘴基金大厦1702单元
37
27
自定义参数的存储类型
Create a parameter data object. Use the parameter as a block parameter in the model. Enable “Inline parameters” in the model’s configuration parameters.
Simulink® Coder™ Generate C and C++ from Simulink and Stateflow
MATLAB Coder
MATLAB® Coder™ Generate C and C++ from MATLAB
8
代码自动生成已成为行业趋势
Click for User Story
18
参数化调用被引用模型
19
代码生成文件控制
20
目录
代码生成概述
代码结构控制
模型数据管理 代码生成的优化 代码生成相关
21
Simulink里的数据
Signal
Data in Simulink
Parameter
State
Data characteristics
Memory size
9
代码自动生成基本流程
模型被充分测试验证以后:
运行Model Advisor • 配置代码生成选项 • 生成代码 • 查看代码报告 • 代码测试
•
10
示例- 简单滤波器算法的代码生成
11
示例- 代码生成报告
Hyperlink between code and model. Hyperlink within C code files.
25
定义数据对象 关联模型数据
Simulink Data Objects
– which specify characteristics – data type, dimensions…
Signals States parameters
Source of data (M-files or MAT-files)
Storage class
Organization
Data type
External
Internal
Scalar
Array
Bus
Built-in
Local
Reusability
Global
Format exportability
Float
Precision
Integer
Word size Signed/unsigned
3
核心算法的代码自动生成
Communication Interfaces Comm Drivers
Core Software Algorithms and Logic
Output Drivers
M
Actuators
A
B
C
Input Drivers
Special Device Drivers
BLACK BOX
“…No longer possible to validate and verify functionality by brute force testing alone.”
Jim Kolhoff Director of Software Engineering at GM Powertrain Automotive Engineering, “Managing for Software Success” – Aug 2006 /automag/electronics/08-2006/1-114-8-34.pdf
No termination function
31
优化数据存储结构
Signal Storage Reuse (Signals and Parameters pane) Enabling Local Block Outputs (Signals and Parameters pane) Reusing Block Outputs (Signals and Parameters pane) Expression Folding (Signals and Parameters pane) Reusing Global Variables (Signals and Parameters pane) Inlining Parameters (Signals and Parameters pane) Block Reduction (Optimization pane) Boolean Logic (Optimization pane)