53
1 © 2013 The MathWorks, Inc. Per Knopfdruck vom Modell zum Code mit automatischer Generierung von Seriencode Model to Code via Push-Button Production Code Generation Michael Fröstl Pilot Engineering, Production Code Generation MathWorks http://www.mathworks.de/embedded-code-generation/

Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

1 © 2013 The MathWorks, Inc.

Per Knopfdruck vom Modell zum Code

mit automatischer Generierung von

Seriencode

Model to Code via Push-Button Production Code Generation

Michael Fröstl

Pilot Engineering, Production Code Generation

MathWorks

http://www.mathworks.de/embedded-code-generation/

Page 2: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

2

switch(braindump)

{

Page 3: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

3

case ‘Applications’:

Page 4: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

4 http://www.mathworks.com/company/user_stories

Page 5: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

5

case ‘Programming’:

Page 6: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

6

ASCII MATLAB

C

C++

ASM

IEC 61131-3

Page 7: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

7

case ‘Hardware’:

Page 8: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

8

MCU /

DSP

ARM®

Analog Devices®

Atmel®

Freescale™

Infineon®

Intel®

Microchip®

NXP™ Renesas®

STMicroelectronics®

Texas Instruments™

Xilinx®

Page 9: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

9

case ‘Operating Systems’:

Page 10: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

10

OS

Green Hills® Integrity RTOS

Embedded Linux®

Texas Instruments™ DSP/BIOS™

Wind River® VxWorks®

OSEK-OS

Microsoft® Windows Embedded

QNX® Neutrino® RTOS

Android™

Page 11: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

11

case ‘Standards’:

Page 12: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

12

NORM

AUTOSAR MISRA C

ISO 26262

IEC 61508

EN 50128

DO-178B/C

Page 13: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

13

default :

printf(“Need a break?”);

}

Page 14: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

14

MBD_Overview();

Page 15: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

15

INTEGRATION

IMPLEMENTATION

PLC MCU DSP FPGA ASIC

Structured

Text VHDL, Verilog C, C++

DESIGN

Environment Models

Physical Components

Algorithms

RESEARCH REQUIREMENTS

TE

ST

& V

ER

IFIC

AT

ION

TEST

SYSTEM

Page 16: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

16

INTEGRATION

IMPLEMENTATION

DESIGN

TE

ST

& V

ER

IFIC

AT

ION

RESEARCH REQUIREMENTS

Environment Models

Mechanical

Control Algorithms

Electrical

Supervisory Logic

Structured

Text VHDL, Verilog C, C++

TEST

SYSTEM

MCU DSP FPGA ASIC PLC

Page 17: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

17

switch(topics)

{

Page 18: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

18

case ‘Fixed-Point’:

Page 19: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

19

void diffEq( void ) { /* Implements a fixed point first order difference equation */ int Prod; long Accum; static short lastVal=0; short a=0x7eb8; /* 0.99 in s16,15 */ short oneminusa=0x0148; /* .01 in s16,15 */ short temp; Prod = gAlg_in1 * gAlg_in1; temp = Prod >> 15; Accum = a*lastVal + oneminusa*temp; gAlg_out1 = (short)(Accum >> 15); lastVal = gAlg_out1; }

Keep track of binary point location

No saturation or rounding

Convert variables to integer types

Need lots of comments

to understand code

Page 20: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

20

Page 21: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

21

Fixed-Point Design Workflow

Proof of Concept

Design and simulate floating-point algorithms

Iterate on algorithm trade-offs

Verifying Fixed-Point Algorithms

Verify fixed-point results against floating-point reference

Verify results against original requirements

Model Hardware Constraints

Convert algorithm to fixed-point and simulate

Iterate on implementation trade-offs

Page 22: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

22

case ‘Code Generation’:

Page 23: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

23

Page 24: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

24

Page 25: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

25

Algorithm Export (MAAB Model, MISRA C )

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

Tuning

Generated

Algorithm

Code

Included

Legacy

Code

Controller

Model

1MathWorks Automotive Advisory Board Style Guidelines, v3.0 2MISRA AC AGC: Guidelines for the Application of MISRA-C:2004 in the Context of Automatic Code Generation

1 2

Page 26: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

26

Page 27: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

27

Page 28: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

28

Page 29: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

29

Page 30: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

30

Page 31: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

31

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

Generated

Algorithm

Code

Input

Drivers

Output

Drivers

Special

Device

Drivers

Comm

Drivers

Scheduler/Operating System

and Support Utilities

Communication

Interfaces

Sensors

Actuators

Special

Interfaces

Tuning

Included

Target

Optimized

Code

Controller

Model

Algorithm Export (MAAB Model, Target Code)

Page 32: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

32

Page 33: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

33

Page 34: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

34

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

Generated

Algorithm

Code

Input

Drivers

Output

Drivers

Special

Device

Drivers

Comm

Drivers

Scheduler/Operating System

and Support Utilities

Communication

Interfaces

Sensors

Actuators

Special

Interfaces

Tuning

Optional

Target

Optimized

Code

Controller Model

w/Driver Blocks

Full Executable (Target Model, Target Code)

Page 35: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

35

Page 36: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

36

Page 37: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

37

case ‘Targets’:

Page 38: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

38 http://www.mathworks.de/hardware-support/home.html

Page 39: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

41 http://www.mathworks.de/services/consulting/areas/developing-embedded-targets.html

Page 40: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

42

case ‘Getting ARMed’:

Page 41: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

43

INTEGRATION

IMPLEMENTATION

DESIGN

TE

ST

& V

ER

IFIC

AT

ION

RESEARCH REQUIREMENTS

Environment Models

Mechanical

Control Algorithms

Electrical

Supervisory Logic

Structured

Text VHDL, Verilog C, C++

TEST

SYSTEM

MCU DSP FPGA ASIC PLC

Page 42: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

44

Create Model

Page 43: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

45

Stateflow

Simulink

Page 44: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

46

Simulate and Test (on Host)

Page 45: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

47

Page 46: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

49

Generate ARM Optimized Code

Page 47: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

50

Embedded

Coder

Page 48: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

51

Processor-in-the-Loop

Execution Profiling

Page 49: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

52 STM32F

Cable

Host Target

Page 50: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

53

Add I/O Blocks, Generate Code, and

Deploy!

Page 51: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

54

STM32F4xx

Blockset

Page 52: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

55

default :

printf(“Time for a

break!”);

}

Page 53: Per Knopfdruck vom Modell zum Code mit automatischer ... · Texas Instruments™ DSP/BIOS™ ... MATLAB Expo PCG Primer Author: Martin Ritt Keywords: Version 13.0 Created Date: 7/8/2013

56

INTEGRATION

IMPLEMENTATION

DESIGN

TE

ST

& V

ER

IFIC

AT

ION

RESEARCH REQUIREMENTS

Environment Models

Mechanical

Control Algorithms

Electrical

Supervisory Logic

Structured

Text VHDL, Verilog C, C++

TEST

SYSTEM

MCU DSP FPGA ASIC PLC