The Actor Model applied to the Raspberry Pi and the Embedded Domain
Omer Kilic || @OmerK
- mer@erlang-solutions.com
Raspberry Pi and the Embedded Domain Omer Kilic || @OmerK - - PowerPoint PPT Presentation
The Actor Model applied to the Raspberry Pi and the Embedded Domain Omer Kilic || @OmerK omer@erlang-solutions.com Agenda Current state of Embedded Systems Overview of the Actor Model Erlang Embedded Project Modelling and
Omer Kilic || @OmerK
03/12/2012 Tech Mesh London Slide 2 of 45
An embedded system is a computer system designed for specific control functions within a larger system, often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs.
03/12/2012 Tech Mesh London
Slide 3 of 45
Source: http://embedded.com/electronics-blogs/programming-pointers/4372180/Unexpected-trends
03/12/2012 Tech Mesh London Slide 4 of 45
– Connected and distributed systems
03/12/2012 Tech Mesh London Slide 5 of 45
– No underlying OS or high level abstractions
– Minimal interrupt and switching latency, scheduling guarantees, minimal jitter
– Slimmed down Linux with hardware interfaces
03/12/2012 Tech Mesh London Slide 6 of 45
– Shared memory
– Pre-emptive: event driven – Round-robin: time multiplexed
03/12/2012 Tech Mesh London Slide 7 of 45
to abundant supply of cheap boards
– Raspberry Pi, Beagleboard/Beaglebone, Gumstix et al.
new territory for embedded engineers
– No direct mapping for RTOS concepts, especially tasks
– Here be dragons
03/12/2012 Tech Mesh London Slide 8 of 45
– “Universal primitives for concurrent computation”
concurrent systems
languages
03/12/2012 Tech Mesh London Slide 9 of 45
– Messages kept in a mailbox and processed in the
– Make local decisions and change internal state – Spawn new actors – Send messages to other actors
03/12/2012 Tech Mesh London Slide 10 of 45
03/12/2012 Tech Mesh London Slide 11 of 45
03/12/2012 Tech Mesh London Slide 12 of 45
– Specific to language and library implementation
problematic for certain applications
– Ordering of messages received from multiple processes – Abstract definition may lead to inconsistency in larger systems
03/12/2012 Tech Mesh London Slide 13 of 45
Erlang Solutions and University of Kent
– Aim of the project: Bring the benefits of concurrent systems development using Erlang to the field of embedded systems; through investigation, analysis, software development and evaluation.
http://erlang-embedded.com
03/12/2012 Tech Mesh London Slide 14 of 45
companies
– Originally designed for embedded applications
systems out of the box
03/12/2012 Tech Mesh London Slide 15 of 45
supervision hierarchies
– Isolation of Actors
– Hot code loading
03/12/2012 Tech Mesh London Slide 16 of 45
spawn(math, fact, [5])
03/12/2012 Tech Mesh London
Pid1 Pid2
math:fact(5)
Slide 17 of 45
03/12/2012 Tech Mesh London
{Pid1, msg}
Pid1 Pid2
Pid2 ! {self(), msg}
Slide 18 of 45
03/12/2012 Tech Mesh London
Pid1 Pid2
link(Pid2)
Slide 19 of 45
– Abstract error handling away from the modules – Results in leaner modules
03/12/2012 Tech Mesh London Slide 20 of 45
03/12/2012 Tech Mesh London
PidA PidB PidC {'EXIT', PidA, Reason} {'EXIT', PidB, Reason}
Slide 21 of 45
03/12/2012 Tech Mesh London
PidA PidB PidC {'EXIT', PidA, Reason}
process_flag(trap_exit, true) Slide 22 of 45
ports used to interface external world to the Erlang runtime.
03/12/2012 Tech Mesh London Slide 23 of 45
(flickr/dereckesanches)
03/12/2012 Tech Mesh London Slide 24 of 45
Video, 3.5mm Stereo Jack, DSI, CSI-2)
03/12/2012 Tech Mesh London
Slide 25 of 45
UK registered charity.
the study of computer science and related topics, especially at school level, and to put the fun back into learning computing."
Future Engineers/Programmers!
03/12/2012 Tech Mesh London
(flickr/lebeus)
Slide 26 of 45
03/12/2012 Tech Mesh London Slide 27 of 45
– Faster, needs root, potentially dangerous!
– Slower, doesn’t need root, easier, relatively safer
03/12/2012 Tech Mesh London Slide 28 of 45
init(Pin, Direction) -> {ok, FdExport} = file:open("/sys/class/gpio/export", [write]), file:write(FdExport, integer_to_list(Pin)), file:close(FdExport), {ok, FdPinDir} = file:open("/sys/class/gpio/gpio" ++ integer_to_list(Pin) ++ "/direction", [write]), case Direction of in -> file:write(FdPinDir, "in");
end, file:close(FdPinDir), {ok, FdPinVal} = file:open("/sys/class/gpio/gpio" ++ integer_to_list(Pin) ++ "/value", [read, write]), FdPinVal.
03/12/2012 Tech Mesh London Slide 29 of 45
write(Fd, Val) -> file:position(Fd, 0), file:write(Fd, integer_to_list(Val)). read(Fd) -> file:position(Fd, 0), {ok, Val} = file:read(Fd, 1), Val. release(Pin) -> {ok, FdUnexport} = file:open("/sys/class/gpio/unexport", [write]), file:write(FdUnexport, integer_to_list(Pin)), file:close(FdUnexport).
03/12/2012 Tech Mesh London Slide 30 of 45
03/12/2012 Tech Mesh London Slide 31 of 45
http://vimeo.com/40769788
03/12/2012 Tech Mesh London
PidA Pin17 PidB PidC
Slide 32 of 45
03/12/2012 Tech Mesh London
PidA Pin17 PidB PidC GPIO Proxy
Slide 33 of 45
embedded design
– Access control/mutual exclusion
– Toggling rate, sequence detection, direction control, etc.
03/12/2012 Tech Mesh London Slide 34 of 45
– Application code becomes simpler – Concise and shorter modules – Testing becomes easier – Code re-use (potentially) increases
– Architecting fine grain systems is difficult
03/12/2012 Tech Mesh London Slide 35 of 45
Universal Peripheral/Component Modules
03/12/2012 Tech Mesh London Slide 36 of 45
Universal Peripheral/Component Modules
03/12/2012 Tech Mesh London Slide 37 of 45
03/12/2012 Tech Mesh London Slide 38 of 45
03/12/2012 Tech Mesh London Slide 39 of 45
03/12/2012 Tech Mesh London Slide 40 of 45
03/12/2012 Tech Mesh London Slide 41 of 45
Parallella:
03/12/2012 Tech Mesh London Slide 42 of 45
https://www.erlang-solutions.com/downloads/download-erlang-otp
03/12/2012 Tech Mesh London Slide 43 of 45
developing the next generation of concurrent and distributed Embedded Systems
– Embedded Linux Primer – Erlang/OTP 101 – Erlang Embedded Framework
Get in touch if you’re interested.
03/12/2012 Tech Mesh London Slide 44 of 45
03/12/2012 Tech Mesh London
The world is concurrent. Things in the world don't share data. Things communicate with messages. Things fail.
Co-inventor of Erlang
Slide 45 of 45