Transcript Ptolemy II

Component
Technologies for
Embedded Systems
Johan Eker
Ptolemy II
A Software Laboratory
Ptolemy II
–
–
–
–
–
–
Actor based models
Implemented in Java
Graphical modeling and
simulation environment
Multiple “models of
computation”
Hierarchical &
heterogeneous models
Code generation
The Caltrop Actor
Language
• a language for
writing dataflow
actors.
• It is designed as a
domain-specific
language.
• It compiles against
the Ptolemy API
(Pt/Java).
Component Technology
• Examples: Java beans, VB-components, etc
• Rationale
– Encapsulation
– Reuse
– Divide complexity
• Successful in many areas
• Problems with concurrent components
– Threads are not components
– Priorities are global parameters
• Difficult to design embedded systems
component with state-of-the art technology
Multipurpose tools
• Express almost anything,
guarantee almost nothing
• You only need to know one
programming language
– Quick starts, but sometimes
slower endings
• Programmers+language,
a lifelong marriage
• Examples:
– Java
– C/C++ with RTOS, ADA, Modula-2
– RMA & EDF scheduling
Sharpen your tools
• Use problem
specific tools
– Constrain the
solutions
• Choice of tools,
a major design
decision
• Combine several
tools
Hierarchical,
Heterogeneous Modeling
and Design in Ptolemy II
leader
follower
sensors
bang-bang
controller
PID
actuators
Models of
computation
Actor Interaction
Semantics
Are actors active? passive?
How is the flow of control determined?
g
u
f
y
Are communications timed? synchronized? buffered?
How is the communications mediated?
Ptolemy II Basics
• A model is a a set of interconnected
actors and one director
• Actor
– Input & output ports, states, & parameters
– Atomic or composite
– Communicates using tokens
– When it is fired it produces and consumes
tokens
Ports
producer
actor
consumer
actor
Ptolemy II Basics
• Director
– Manages the data flow and the scheduling
of the actors
– The director fires the actors
• Receiver
– Defines the semantics of the port buffers
• Models of Computation
– Define the interaction semantics
– Implemented in Ptolemy II by a domain
• Director + Receiver
Key: Orthogonalizing
the Concerns
• Write your actors so thatCommunication
communication and
scheduling can be
factored out
• Requires stylized Java
Scheduling
and many informal
contracts
• Solution: generate Java
actors from a more
abstract description such
Algorithm
as Caltrop
Caltrop Actor Language
• Imperative, but with a functional flavor
• Ports, states, parameters & actions
• Operates on token streams
actor Add () double A, double B  double C:
action [a], [b]  [c]:
c := a + b;
end
Output
Input
Output
Input
Action
expression
pattern
port
body
port
end
A:[1,2,3,...], B: [1,2,3,...] C: [2,4,6,...]
• Embedded in a host language
States
actor B ()
Double Input ==> Double Output:
Integer n := 0;
Double sum := 0;
action [a] ==> [sum / n] :
n := n + 1;
sum := sum + a;
end
end
Multiple actions,
action conditions
actor C ()
Double Input ==> Double Output:
action [a] ==> [a] where a >= 0 end
action [a] ==> [-a] where a < 0 end
end
actor D ()
Double Input ==> Double Output:
action [a] ==> [abs(a)] end
end
Port patterns
actor PairwiseSwap [T] ()
T Input ==> T Output:
action [a, b] ==> [b, a] end
end
• examples
– [a, b, c]
– [a, b, c | s]
– [| s]
Channel selectors
actor Switch [T] ()
multi T Data, Integer Select
==> T Output:
action [a] at i, [i] ==> [a] end
end
Action tags,
action selectors
actor FairMerge [T] ()
T Input1, T Input2
==> T Output:
A: action [a], [] ==> [a] end
B: action [], [a] ==> [a] end
selector
(A B)*
end
end
other selectors are conceivable, e.g.
• (A B)* | (B A)*
• ( (A B) | (B A) )*
Caltrop implementation
—the big picture.
source text
Caltrop AST
target
platform
parsing
Caltrop
transformation,
annotation
code generation
Caltrop(0)
Caltrop(1)
Caltrop(n)
split-phase CalCore
Matlab/Pålsjö

Koala OS
CalCore
Ptolemy II
Moses
DSP/FPGA
The Rest of Caltrop
• Expressions are side effect free
• Lambda, block and actor closures
• Statements
– foreach, while, if-then-else
• Few built-in types: list, map, set
• Immutable variable & no aliasing
• Allows analysis
– Deadlock, schedulability, memory
consumption
Summary
• “Don’t get it right, keep it right”
• Embedded system components
• Realized in the Ptolemy II framework
• Compiler is being developed at UCB
• More information
– Edward Lee “What’s Ahead for
Embedded Computing?”, IEEE
Computer, Sept. 2000
– http://ptolemy.eecs.berkeley.edu
– http://www.gigascale.org/caltrop