130 likes | 259 Views
Embedded Functional Programming in Hume. Gergely Patai patai@iit.bme.hu Péter Hanák hanak@iit.bme.hu Budapest University of Technology and Economics Department of Control Engineering and Information Technology. Outline. Introducing Hume Example: lift control Example: light measurement
E N D
Embedded Functional Programming in Hume Gergely Patai patai@iit.bme.hu Péter Hanák hanak@iit.bme.hu Budapest University of Technology and Economics Department of Control Engineering and Information Technology IASTED Software Engineering 2007, Innsbruck
Outline • Introducing Hume • Example: lift control • Example: light measurement • Conclusions The Hume language is developed at University of St Andrewsand Heriot-Watt University in Scotlandwithin theEmBounded Project (IST-510255).http://www.hume-lang.orghttp://www.embounded.org IASTED Software Engineering 2007, Innsbruck
Hume overview • An experimental functionally based language for embedded systems • Pure functions: no side effects • Inherently parallel • Visual program structure • Static space-time guarantees • Verifiable properties • Increased dependability • Viable on low-end platforms IASTED Software Engineering 2007, Innsbruck
Hume example: counter program stream display to "std_out"; type integer = int 32; inc x = x+1; box counter in (n::integer) out (n’::integer, nout::integer) match n -> (inc n, n); wire counter (counter.n’ initially 0) (counter.n, display); Counter n n’ nout display IASTED Software Engineering 2007, Innsbruck
Hume basics • Hume programs are ‘boxes’ connected with ‘wires’ • Wires: • are mailboxes that can hold one piece of data at a time • each connects strictly one output to one input • statically typed • Boxes: • map their inputs to their outputs with a pure function(combinational network) • the function consists of rules, exactly one of which is chosen by patternmatching on the input • if some outgoing wires needed by the rule are occupied,theresult is buffered until the wire is freed up by its consumer • Supersteps: global consume–produce cycles IASTED Software Engineering 2007, Innsbruck
Execution alternatives • Source-level interpreter • HAM (Hume Abstract Machine) interpreter • Hume → HAM assembly compilation • Optional transformation to bytecode • Native code • HAM → C conversion (macro expansion) • Compiled with a C compiler, linked to a lightweight runtime system (RTS) • No endianness issues, no malloc, no threads IASTED Software Engineering 2007, Innsbruck
Lift control • Task: single-shaft lift simulation • Hardware: mitmót • ARM7 (32-bit) @ 54MHz(Philips LPC2106) • 128k flash, 64k RAM • OS: eCos • User code: compiled to native code IASTED Software Engineering 2007, Innsbruck
Lift control software state cache →user state’ cache’ C→ C← D→ D← state position →R ←R →D ←D Requests Cabin state’ position’ ↑clk R↑ R↓ enabled state Door ↑C ↓C clk← enabled’ state’ IASTED Software Engineering 2007, Innsbruck
Light measurement • Task: remote measurement • Hardware: Tmote Sky • MSP430 (16-bit) @ 8MHz • 48k flash, 10k RAM • OS: Contiki with HAM interpreter • Stripped string and floating point support • Peripherals accessed as streams • User code: HAM bytecode loadable over the air IASTED Software Engineering 2007, Innsbruck
Light measurement software State (init/alive/dead) Calibration(thresholds, speeds) Control Photo diode Speed control UDP packet Receiver Command Ack/Light ( Init, _*, _, *) -> (Alive, (200, 400, 50, 10), 50, *) | ( _, _*, _, Reset) -> ( Init, *, *, 0) | ( Dead, _*, _, _*) -> ( Dead, *, *, *) | (Alive, _*, _, Calibrate t1 t2 d1 d2) -> (Alive, (t1, t2, d1, d2), *, 1) | (Alive, (t1, t2, d1, d2), p, *) -> if p < t1 then (Alive, (t1, t2, d1, d2), d1, p) else if p < t2 then (Alive, (t1, t2, d1, d2), d2, p) else (Dead, *, *, *); IASTED Software Engineering 2007, Innsbruck
Experiences • Short source code • Easy portability • Big native code (experimental compiler) • No significant speed loss with bytecode • Sufficiently fast for simple tasks • Great potentials for a future IDE IASTED Software Engineering 2007, Innsbruck
Future work • Improving the Tmote Sky port of the interpreter • New resource-constrained applications on a variety of platforms • Developing and evaluating extensions and tools for the language • Further information: http://www.inf.bme.hu/fp4es IASTED Software Engineering 2007, Innsbruck
Thank you for your attention! IASTED Software Engineering 2007, Innsbruck