A Code Generation Framework for Distributed Real-Time ... · I Model Based Design (MBD),...

Preview:

Citation preview

A Code Generation Framework for DistributedReal-Time Embedded Systems

M. Bambagini and M. Di Natale

17th International Conference on Emerging Technologies & Factory AutomationKrakow, Poland, September 17-21, 2012

TeCIP Institute, Scuola Superiore Sant’AnnaArea della Ricerca CNR, Via Moruzzi, 1

56127 Pisa, ITALY

Outline

1 Introduction

2 Proposed framework

3 Code generation issues

4 Evaluation example

5 Conclusions

Introduction

Model creation and analysis tools have been helping engineers toface the design complexity of the current systems

The two most widespread approaches in embedded computing are:I Model Based Design (MBD), Matlab/Simulink/Scade

I formally models the execution semanticsI lets designers simulate and test the model since the earliest

design stagesI provides facility for the code generation (only for single-core)

I Model Driven Architecture (MDA), SysML/MARTEI models computational and communication platforms and

software architectureI issues in the formal definition of semanticsI limited capability of simulation, verification and SW generation

M. Bambagini c©2012 Scuola Superiore Sant’Anna 3/20

Introduction

Model creation and analysis tools have been helping engineers toface the design complexity of the current systems

The two most widespread approaches in embedded computing are:I Model Based Design (MBD), Matlab/Simulink/Scade

I formally models the execution semanticsI lets designers simulate and test the model since the earliest

design stagesI provides facility for the code generation (only for single-core)

I Model Driven Architecture (MDA), SysML/MARTEI models computational and communication platforms and

software architectureI issues in the formal definition of semanticsI limited capability of simulation, verification and SW generation

M. Bambagini c©2012 Scuola Superiore Sant’Anna 3/20

Introduction

Model creation and analysis tools have been helping engineers toface the design complexity of the current systems

The two most widespread approaches in embedded computing are:I Model Based Design (MBD), Matlab/Simulink/Scade

I formally models the execution semanticsI lets designers simulate and test the model since the earliest

design stagesI provides facility for the code generation (only for single-core)

I Model Driven Architecture (MDA), SysML/MARTEI models computational and communication platforms and

software architectureI issues in the formal definition of semanticsI limited capability of simulation, verification and SW generation

M. Bambagini c©2012 Scuola Superiore Sant’Anna 3/20

Proposed framework

We propose a modeling framework/methodology that bridges thegap between MBD and MDA approaches while:

I providing separation of concerns between functional modelingand platform modeling

I improves portability and extensibilityI enables the definition of functional components with

re-targetable interfaces

I exploiting the best-in-class software: Matlab/Simulink andEclipse/EMF

I generating a code implementation for distributed systems withonly changes in the platform and mapping models

I enabling back-annotation of time performance and evaluationof response time in the average and worst-case (vs. deadlines)

M. Bambagini c©2012 Scuola Superiore Sant’Anna 4/20

Proposed framework

We propose a modeling framework/methodology that bridges thegap between MBD and MDA approaches while:

I providing separation of concerns between functional modelingand platform modeling

I improves portability and extensibilityI enables the definition of functional components with

re-targetable interfaces

I exploiting the best-in-class software: Matlab/Simulink andEclipse/EMF

I generating a code implementation for distributed systems withonly changes in the platform and mapping models

I enabling back-annotation of time performance and evaluationof response time in the average and worst-case (vs. deadlines)

M. Bambagini c©2012 Scuola Superiore Sant’Anna 4/20

Proposed framework

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework

1. By model-based tools, algorithms are developed and validatedwithout considering any implementation or hardware detail

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework

2. The Platform Independent Model is parsed and translated intoanother model according to the internal functional meta-model

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework

3. Designers define the deployed HW and SW resources: ECUs,buses, devices, RTOSs, tasks, drivers and communication protocols

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework

4. Designers map functional components onto the computationand communication resources. Timing back-annotations are added

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework

5. The Platform Specific Model is completed

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework

6. The system performance (time, energy...) can be staticallyanalyzed to evaluate if the mapping satisfies the constraints

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework

7. If the performance is not as good as required: the design maybe changed at the platform and functional levels

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework

8. The binary files are obtained by compiling together thefunctional code, the RTOSs, drivers and the generated code

M. Bambagini c©2012 Scuola Superiore Sant’Anna 5/20

Proposed framework - Implementation

M. Bambagini c©2012 Scuola Superiore Sant’Anna 6/20

Proposed framework - Implementation

Functional area: Matlab/Simulink/Embedded Coder

M. Bambagini c©2012 Scuola Superiore Sant’Anna 6/20

Proposed framework - Implementation

Functional/Mapping/Architectural areas: set of Eclipse Plug-ins

M. Bambagini c©2012 Scuola Superiore Sant’Anna 6/20

Proposed framework - Implementation

Code generation: Acceleo scripts (Eclipse Plug-in)

M. Bambagini c©2012 Scuola Superiore Sant’Anna 6/20

Code generation issues

Code generation issues:

I execution of the functional blocks

I sustaining the communication among the blocks

Each subsystem behavior is encoded in: <subsystem name> step()TASK(task_1) {

...

subSystem1_step ();

...

}

TASK(task_2) {

...

subSystem2_step ();

...

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 7/20

Code generation issues

Code generation issues:

I execution of the functional blocks

I sustaining the communication among the blocks

Each subsystem behavior is encoded in: <subsystem name> step()

TASK(task_1) {

...

subSystem1_step ();

...

}

TASK(task_2) {

...

subSystem2_step ();

...

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 7/20

Code generation issues

Code generation issues:

I execution of the functional blocks

I sustaining the communication among the blocks

Each subsystem behavior is encoded in: <subsystem name> step()TASK(task_1) {

...

subSystem1_step ();

...

}

TASK(task_2) {

...

subSystem2_step ();

...

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 7/20

Code generation issues

Communication between the blocks

A middleware level provides the actual implementation of thecommunications

TASK( t a s k 1 ) {. . .s u b S y s t e m 1 s t e p ( ) ;w r i t e s u b 1 O u t 2 ( ) ;. . .

}

TASK( t a s k 2 ) {. . .r e a d s u b 2 I n 1 ( ) ;s u b S y s t e m 2 s t e p ( ) ;. . .

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 8/20

Code generation issues

Communication between the blocks

A middleware level provides the actual implementation of thecommunications

TASK( t a s k 1 ) {. . .s u b S y s t e m 1 s t e p ( ) ;w r i t e s u b 1 O u t 2 ( ) ;. . .

}

TASK( t a s k 2 ) {. . .r e a d s u b 2 I n 1 ( ) ;s u b S y s t e m 2 s t e p ( ) ;. . .

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 8/20

Code generation issues

Communication between blocks: Intra-Task communication

TASK(singleTask) {

subSystem1_step ();

write_sub1_Out2 ();

...

read_sub2_In1 ();

subSystem2_step ();

}

TypeX X;

inline void write_sub1_Out2 ()

{

X = subSystem1_Y.Out2;

}

inline void read_sub2_In1 ()

{

subSystem2_U.In1 = X;

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 9/20

Code generation issues

Communication between blocks: Intra-Task communication

TASK(singleTask) {

subSystem1_step ();

write_sub1_Out2 ();

...

read_sub2_In1 ();

subSystem2_step ();

}

TypeX X;

inline void write_sub1_Out2 ()

{

X = subSystem1_Y.Out2;

}

inline void read_sub2_In1 ()

{

subSystem2_U.In1 = X;

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 9/20

Code generation issues

Communication between blocks: Inter-Task communication

TASK(task_1) {

subSystem1_step ();

write_sub1_Out2 ();

}

TASK(task_2) {

read_sub2_In1 ();

subSystem2_step ();

}

TypeX X;

Mutex mutex_X;

inline void write_sub1_Out2 () {

GetResource(mutex_X );

X = subSystem1_Y.Out2;

ReleaseResource(mutex_X );

}

inline void read_sub2_In1 () {

GetResource(mutex_X );

subSystem2_U.In1 = X;

ReleaseResource(mutex_X );

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 10/20

Code generation issues

Communication between blocks: Inter-Task communication

TASK(task_1) {

subSystem1_step ();

write_sub1_Out2 ();

}

TASK(task_2) {

read_sub2_In1 ();

subSystem2_step ();

}

TypeX X;

Mutex mutex_X;

inline void write_sub1_Out2 () {

GetResource(mutex_X );

X = subSystem1_Y.Out2;

ReleaseResource(mutex_X );

}

inline void read_sub2_In1 () {

GetResource(mutex_X );

subSystem2_U.In1 = X;

ReleaseResource(mutex_X );

}

M. Bambagini c©2012 Scuola Superiore Sant’Anna 10/20

Code generation issues

Communication between blocks: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 11/20

Code generation issues

Communication between blocks: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 11/20

Evaluation example

Evaluation case: Ball&Plate system

I Target: keep the ball as close as possible to the plate center

I Sensing: a touch screen sensor on the top of the plate totrack the ball

I Actuation: two servomotors to control the pitch and rollangles of the plate

M. Bambagini c©2012 Scuola Superiore Sant’Anna 12/20

Evaluation example

Functional model (in Simulink): 5 subsystems and 3 custom blocks

The C functional functions subTouch step(), subController step(),subServoX step() and subServoY step() are generated

M. Bambagini c©2012 Scuola Superiore Sant’Anna 13/20

Evaluation example

Functional model (in Simulink): 5 subsystems and 3 custom blocks

The C functional functions subTouch step(), subController step(),subServoX step() and subServoY step() are generated

M. Bambagini c©2012 Scuola Superiore Sant’Anna 13/20

Design 1: Intra-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 14/20

Design 1: Intra-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 14/20

Design 1: Intra-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 14/20

Design 2: Inter-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 15/20

Design 2: Inter-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 15/20

Design 2: Inter-Task communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 15/20

Design 3: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 16/20

Design 3: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 16/20

Design 3: Inter-ECU communication

M. Bambagini c©2012 Scuola Superiore Sant’Anna 16/20

Performance measurement

M. Bambagini c©2012 Scuola Superiore Sant’Anna 17/20

Performance measurement

M. Bambagini c©2012 Scuola Superiore Sant’Anna 17/20

Performance measurement

M. Bambagini c©2012 Scuola Superiore Sant’Anna 17/20

Future work

Next step: functional model back-annotation with theestimated/measured communication delays

M. Bambagini c©2012 Scuola Superiore Sant’Anna 18/20

Future work

Next step: functional model back-annotation with theestimated/measured communication delays

M. Bambagini c©2012 Scuola Superiore Sant’Anna 18/20

Conclusions

A framework/methodology for code generation for real-timedistributed systems has been introduced

It aims at combining MBD and MDA approaches for covering allthe steps from the idea devising to the development

In the experiments, three different designs were considered bychanging only the architectural and mapping models, withoutwriting any line of C code

M. Bambagini c©2012 Scuola Superiore Sant’Anna 19/20

dummy

thank youm.bambagini@sssup.it

M. Bambagini c©2012 Scuola Superiore Sant’Anna 20/20

Recommended