嵌入式代码自动生成 - MathWorks...3 目录 代码生成概述 代码结构控制...

37
1 © 2014 The MathWorks, Inc. 嵌入式代码自动生成 周玲/ [email protected] 应用工程师 201406

Transcript of 嵌入式代码自动生成 - MathWorks...3 目录 代码生成概述 代码结构控制...

  • 1© 2014 The MathWorks, Inc.

    嵌入式代码自动生成

    周玲/ [email protected]应用工程师201406

  • 2

    目录

    代码生成概述

    代码结构控制

    模型数据管理

    代码生成的优化

    代码生成相关

  • 3

    目录

    代码生成概述

    代码结构控制

    模型数据管理

    代码生成的优化

    代码生成相关

  • 4

    核心算法的代码自动生成

    Core

    Software

    Algorithms

    and Logic

    A B C

    M

    I N P U T

    B L U E G R E E N R E D

    P O W E R

    RGBSplit-4BLACK BOX

    V R C S

    Input

    Drivers

    Output

    Drivers

    Special

    Device

    Drivers

    Comm

    Drivers

    Scheduler/Operating System

    And Support Utilities

    Communication

    Interfaces

    Sensors

    Actuators

    Special

    Interfaces

    ASAP2

    CCP

    Most

    Development

    is on Core

    Software

    Algorithms

  • 5

    代码量的爆炸式增长

    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:

    High-level architectural planning

    Algorithm development with models

    Automatic generation of code

    from models

    Industry-wide standardization of

    interfaces and common functionality

    Automotive Engineering,

    “Managing for Software Success” – Aug 2006

    sae.org/automag/electronics/08-2006/1-114-8-34.pdf

    “Growth of top end automotive

    embedded software has been

    exponential.” Robert Gee

    Director of Strategy for Motorola Automotive

    “…No longer possible to

    validate and verify

    functionality by brute force

    testing alone.” Jim Kolhoff

    Director of Software Engineering at GM

    Powertrain

    http://www.sae.org/automag/electronics/08-2006/1-114-8-34.pdf

  • 6

    使用更高效的算法开发平台

  • 7

    代码自动生成

  • 8

    代码自动生成工具

    MATLAB® Coder™

    Generate C and C++ from MATLAB

    Simulink® Coder™

    Generate C and C++ from Simulink and

    Stateflow

    Embedded Coder™

    Generate C and C++ from MATLAB and

    Simulink optimized for embedded systems

    Simulink

    Coder

    MATLAB Coder

    Embedded

    Coder

  • 9

    代码自动生成已成为行业趋势Click for User Story

    http://www.mathworks.com/industries/auto/iac/presentations/keener.pdfhttp://www.mathworks.com/industries/auto/iac/presentations/keener.pdfhttp://www.mathworks.com/products/rtwembedded/userstories.html?file=45567http://www.mathworks.com/products/rtwembedded/userstories.html?file=45567http://www.mathworks.com/products/rtwembedded/userstories.html?file=49476http://www.mathworks.com/products/rtwembedded/userstories.html?file=49476http://www.mathworks.com/products/rtwembedded/userstories.html?file=45644http://www.mathworks.com/products/rtwembedded/userstories.html?file=45644http://www.mathworks.com/products/rtwembedded/userstories.html?file=45639http://www.mathworks.com/products/rtwembedded/userstories.html?file=45639http://www.mathworks.com/products/rtwembedded/userstories.html?file=45538http://www.mathworks.com/products/rtwembedded/userstories.html?file=45538http://www.mathworks.com/products/rtwembedded/userstories.html?file=45638http://www.mathworks.com/products/rtwembedded/userstories.html?file=45638http://www.mathworks.com/products/rtwembedded/userstories.html?file=45577http://www.mathworks.com/products/rtwembedded/userstories.html?file=45577http://www.mathworks.com/products/rtwembedded/userstories.html?file=45588http://www.mathworks.com/products/rtwembedded/userstories.html?file=45588http://www.mathworks.com/products/rtwembedded/userstories.html?file=45689http://www.mathworks.com/products/rtwembedded/userstories.html?file=45689http://www.mathworks.com/products/rtwembedded/userstories.html?file=45513http://www.mathworks.com/products/rtwembedded/userstories.html?file=45513http://www.mathworks.com/products/rtwembedded/userstories.html?file=45601http://www.mathworks.com/products/rtwembedded/userstories.html?file=45601http://www.mathworks.com/products/rtwembedded/userstories.html?file=50327http://www.mathworks.com/products/rtwembedded/userstories.html?file=50327http://www.mathworks.com/automotive/mac2010/pdfs/AutomaticCodeGenerationofAUTOSARSoftwareComponentsPres.pdfhttp://www.mathworks.com/automotive/mac2010/pdfs/AutomaticCodeGenerationofAUTOSARSoftwareComponentsPres.pdfhttp://www.mathworks.com/industries/auto/mac2007/proceedings/day2/presentations/2_autosar.pdfhttp://www.mathworks.com/industries/auto/mac2007/proceedings/day2/presentations/2_autosar.pdfhttp://www.mathworks.com/industries/auto/mac2007/proceedings/day2/presentations/6_testsuite.pdfhttp://www.mathworks.com/industries/auto/mac2007/proceedings/day2/presentations/6_testsuite.pdfhttp://www.mathworks.com/industries/auto/mac2007/proceedings/day2/presentations/3_rtwecoder.pdfhttp://www.mathworks.com/industries/auto/mac2007/proceedings/day2/presentations/3_rtwecoder.pdfhttp://www.mathworks.com/industries/auto/mac2007/proceedings/day1/presentations/3_proofofconcept.pdfhttp://www.mathworks.com/industries/auto/mac2007/proceedings/day1/presentations/3_proofofconcept.pdfhttp://www.mathworks.com/industries/auto/iac06/presentations/24-iac2006-psa.pdfhttp://www.mathworks.com/industries/auto/iac06/presentations/24-iac2006-psa.pdfhttp://www.mathworks.com/industries/auto/iac06/presentations/25-iac2006_slide_final_toyota.pdfhttp://www.mathworks.com/industries/auto/iac06/presentations/25-iac2006_slide_final_toyota.pdfhttp://www.mathworks.com/industries/auto/iac06/presentations/28-denso.pdfhttp://www.mathworks.com/industries/auto/iac06/presentations/28-denso.pdfhttp://www.mathworks.com/industries/auto/iac06/presentations/14-Gillet-Autoliv.pdfhttp://www.mathworks.com/industries/auto/iac06/presentations/14-Gillet-Autoliv.pdfhttp://www.mathworks.com/products/rtwembedded/userstories.html?file=45642http://www.mathworks.com/products/rtwembedded/userstories.html?file=45642http://www.mathworks.com/mason/tag/proxy.html?dataid=4362&fileid=20303http://www.mathworks.com/mason/tag/proxy.html?dataid=4362&fileid=20303http://www.sae.org/mags/aei/9027http://www.sae.org/mags/aei/9027http://www.mathworks.com/mason/tag/proxy.html?dataid=9939&fileid=44540http://www.mathworks.com/mason/tag/proxy.html?dataid=9939&fileid=44540http://www.mathworks.com/products/rtwembedded/userstories.html?file=45633http://www.mathworks.com/products/rtwembedded/userstories.html?file=45633http://www.mathworks.com/company/events/programs_de/iac2004/presentations/18_pp_FIAT.pdfhttp://www.mathworks.com/company/events/programs_de/iac2004/presentations/18_pp_FIAT.pdfhttp://www.mathworks.com/automotive/iac06/presentations/07-Assfalg-Bosch.pdfhttp://www.mathworks.com/automotive/iac06/presentations/07-Assfalg-Bosch.pdfhttp://www.mathworks.com/company/events/programs_de/iac2004/presentations/04_pp_siemens_vdo.pdfhttp://www.mathworks.com/company/events/programs_de/iac2004/presentations/04_pp_siemens_vdo.pdfhttp://www.mathworks.com/products/rtwembedded/userstories.html?file=45539http://www.mathworks.com/products/rtwembedded/userstories.html?file=45539http://www.mathworks.com/products/rtwembedded/userstories.html?file=45631http://www.mathworks.com/products/rtwembedded/userstories.html?file=45631http://www.mathworks.com/products/rtwembedded/userstories.html?file=45471http://www.mathworks.com/products/rtwembedded/userstories.html?file=45471http://www.mathworks.com/products/rtwembedded/userstories.html?file=45642http://www.mathworks.com/products/rtwembedded/userstories.html?file=45642http://www.mathworks.com/products/rtwembedded/userstories.html?file=45522http://www.mathworks.com/products/rtwembedded/userstories.html?file=45522http://www.mathworks.com/products/rtwembedded/userstories.html?file=45550http://www.mathworks.com/products/rtwembedded/userstories.html?file=45550http://www.mathworks.com/company/user_stories/userstory45557.htmlhttp://www.mathworks.com/company/user_stories/userstory45557.htmlhttp://www.mathworks.com/products/rtw/userstories.html?file=7895&title=ABB Accelerates Application Control Software Development for a Power Electronic Controllerhttp://www.mathworks.com/products/rtw/userstories.html?file=7895&title=ABB Accelerates Application Control Software Development for a Power Electronic Controllerhttp://www.mathworks.com/products/rtwembedded/userstories.html?file=17102http://www.mathworks.com/products/rtwembedded/userstories.html?file=17102http://www.mathworks.com/products/rtw/userstories.html?file=11240&title=Wartsila Accelerates Engine Control Development Using Production Code Generationhttp://www.mathworks.com/products/rtw/userstories.html?file=11240&title=Wartsila Accelerates Engine Control Development Using Production Code Generationhttp://www.mathworks.com/industries/aerospace/aerodef/proceedings/Thales-SoftwareDevelopmentAdvantagesfromReal-TimeWorkshopEmbeddedCoder.pdfhttp://www.mathworks.com/industries/aerospace/aerodef/proceedings/Thales-SoftwareDevelopmentAdvantagesfromReal-TimeWorkshopEmbeddedCoder.pdfhttp://www.mathworks.com/aerospace-defense/aerodef_conf06/pdfs/madc_2006_12_robb_lm.pdfhttp://www.mathworks.com/aerospace-defense/aerodef_conf06/pdfs/madc_2006_12_robb_lm.pdf

  • 10

    代码自动生成基本流程

    模型被充分测试验证以后:

    • 运行Model Advisor

    • 配置代码生成选项

    • 生成代码

    • 查看代码报告

    • 代码测试

  • 11

    示例- 简单滤波器算法的代码生成

  • 12

    示例- 代码生成报告

    Hyperlink between

    code and model.

    Hyperlink within

    C code files.

  • 13

    示例- 可配置的代码生成

  • 14

    目录

    代码生成概述

    代码结构控制

    模型数据管理

    代码生成的优化

    代码生成相关

  • 15

    默认入口函数原型

    _initialize()

    – initialize signals, states and parameters

    prior to first time step

    _step()

    – execute one time step

    _terminate()

    – Optional. Cleanup after last simulation

    step.

  • 16

    可配置入口函数原型

  • 17

    子系统生成单独函数

    Virtual

    Atomic

  • 18

    被多次引用的子系统代码重用

  • 19

    参数化调用被引用模型

  • 20

    代码生成文件控制

  • 21

    目录

    代码生成概述

    代码结构控制

    模型数据管理

    代码生成的优化

    代码生成相关

  • 22

    Simulink里的数据Data in Simulink

    Signal Parameter StateData characteristics

    Memory size Storage class

    External Internal

    Local Global

    Reusability Format

    exportability

    Float Fixed-point

    Built-in

    Integer

    Precision Word size

    Signed/unsigned

    Word size

    Signed/unsigned

    Scaling

    Data typeOrganization

    Scalar Array Bus

  • 23

    定义数据类型

  • 24

    定义存储类型

    model_private.h

    model.c

  • 25

    算法模型与数据保持独立

    Name

    DescriptionValue

    Storage classData type

    Rest of model (algorithm, system dynamics, etc.)

  • 26

    定义数据对象 关联模型数据

    Simulink Data Objects

    – which specify characteristics

    – data type, dimensions…

    Signals

    States

    parameters

    Data Algorithm

    Source

    of data

    (M-files or

    MAT-files)

  • 27

    自定义信号的存储类型

    Create a signal data object.

    Use the object name to label a signal in the model.

    Indicate the signal must resolve to a signal data object.

  • 28

    自定义参数的存储类型

    Create a parameter data object.

    Use the parameter as a block parameter in the model.

    Enable “Inline parameters” in the model’s configuration

    parameters.

  • 29

    目录

    代码生成概述

    代码结构控制

    模型数据管理

    代码生成的优化

    代码生成相关

  • 30

    代码生成统计报告

  • 31

    移除不需要的代码或数据支持

    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)

    No termination

    function

  • 32

    优化数据存储结构

    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)

  • 33

    代码优化工具

  • 34

    目录

    代码生成概述

    代码结构控制

    模型数据管理

    代码生成的优化

    代码生成相关

  • 35

    其它话题

    Scheduler

    Multi-rate Multi-tasking

    Optimizing Code

    Customer Code Integration

    Customer Storage Class

    Target Language Compiler

    AUTOSAR Support

    ……

    Learn more from MathWorks Training Service

    - Embedded Coder for Production Code Generation (3 days)

    Embedded Coder生成产品代码 - 详细课程大纲 - MathWorks 中国.htm

  • 36

    MathWorks在中国的技术支持体系

    在中国提供多层次的技术支持

    应用工程师: 负责产品层面的支持,有丰富产品和行业知识

    Pilot 工程师: 结合用户实际项目,提供指导支持,有实际项目经

    验同时对工具链熟悉

    技术咨询顾问团队:全部是行业和产品专家,有着丰富的实际项目经验,目前主要在北美和欧洲,服务于全球,在中国已经开始建立团队

    培训服务:提供公开课和现场的收费培训,可以针对行业定制。

    技术支持热线:对服务期内正版用户提供 5×8 的电话技术支持www.mathworks.cn/support/contact_us/

    http://www.mathworks.cn/support/contact_us/

  • 37

    联系我们

    官方网站:www.mathworks.cn

    官方微博: MATLAB

    官方社区(英文):

    中文社区:

    联系电话(总机):010 – 59827000

    联系地址:

    迈斯沃克软件 (北京) 有限公司

    北京市海淀区科学院南路2号 融科资讯中心C座南楼3层301

    迈斯沃克软件 (北京) 有限公司上海分公司

    上海市浦东新区竹林路101号 陆家嘴基金大厦1702单元

    http://www.mathworks.cn/http://www.mathworks.com/programs/bounce_hub_generic.html?s_eid=PEP_4119&url=http://www.weibo.com/mathworkshttp://www.mathworks.com/programs/bounce_hub_generic.html?s_eid=PEP_4119&url=http://www.weibo.com/mathworkshttp://www.mathworks.com/programs/bounce_hub_generic.html?s_eid=PEP_4119&url=http://www.weibo.com/mathworks