Taking Back Embedded
The Erlang Embedded Project

Omer Kilic || @OmerK
omer@erlang-solutions.com
Outline
•
•
•
•
•
•

Current state of Embedded Systems
Overview of Erlang and the Actor Model
Modelling and developing sys...
Embedded Systems

“

An embedded system is a computer system designed for
specific control functions within a larger syste...
Embedded Systems

• Specific functions
• Designed for a particular
application

22/03/2013

Erlang Factory SF Bay 2013

• ...
Current Challenges
• Complex SoC platforms
• “Internet of Things”
– Connected and distributed systems

• Multicore and/or ...
Internet of Things

22/03/2013

Erlang Factory SF Bay 2013

Slide 6 of 46
Internet of Fridges?

22/03/2013

Erlang Factory SF Bay 2013

Slide 7 of 46
Distributed Bovine Networks?

22/03/2013

Erlang Factory SF Bay 2013

Slide 8 of 46
Exciting times

22/03/2013

Erlang Factory SF Bay 2013

Slide 9 of 46
TI OMAP Reference System

22/03/2013

Erlang Factory SF Bay 2013

Slide 10 of 46
Samsung Exynos Reference System

22/03/2013

Erlang Factory SF Bay 2013

Slide 11 of 46
#include <stats.h>

Source: http://embedded.com/electronics-blogs/programming-pointers/4372180/Unexpected-trends

22/03/20...
Embedded Systems
• Bare Metal
– No underlying OS or high level abstractions

• RTOS
– Minimal interrupt and switching late...
RTOS Concepts
• Notion of “tasks”
• OS-supervised interprocess messaging
– Shared memory

• Mutexes/Semaphores/Locks
• Sch...
Embedded Linux
• Not a new concept, increased popularity due
to abundant supply of cheap boards
– Raspberry Pi, Beagleboar...
Erlang Embedded
• Knowledge Transfer Partnership between
Erlang Solutions and University of Kent
– Aim of the project: Bri...
Erlang? (I)
{declarative, functional,
concurrent, parallel, garbagecollected, soft real-time,
fault-tolerant, robust,
port...
Erlang? (II)
• First version developed in 1986
– Open-sourced in 1998.

• Battle-tested at Ericsson and many other
compani...
High Availability/Reliability
• Simple and consistent error recovery and
supervision hierarchies
• Built in fault-toleranc...
External Interfaces
• Facilities to interface the Erlang runtime to the
outside world
• Used for device drivers and kernel...
External Interfaces

22/03/2013

Erlang Factory SF Bay 2013

Slide 21 of 46
Actor Model
• Proposed in 1973 by Hewitt, Bishop and Steiger
– “Universal primitives for concurrent computation”

• No sha...
Actor Model
• Asynchronous message passing
– Messages kept in a mailbox and processed in the
order they are received in

•...
Process Error Handling
• Let it Fail!
– Abstract error handling away from the modules
– Results in leaner modules

• Super...
Propagating Exit Signals
{'EXIT', PidA, Reason}
PidA

PidB

{'EXIT', PidB, Reason}
PidC

22/03/2013

Erlang Factory SF Bay...
Trapping Exits
process_flag(trap_exit, true)

{'EXIT', PidA, Reason}
PidA

PidB

PidC

22/03/2013

Erlang Factory SF Bay 2...
TI OMAP Reference System

22/03/2013

Erlang Factory SF Bay 2013

Slide 27 of 46
Fine Grain Abstraction
• Advantages
– Application code becomes simpler
– Concise and shorter modules
– Testing becomes eas...
Limitations of the Actor Model
• No notion of inheritance or general hierarchy
– Specific to language and library implemen...
Erlang, the Maestro

(flickr/dereckesanches)

22/03/2013

Erlang Factory SF Bay 2013

Slide 30 of 46
Accessing hardware
• Peripherals are memory mapped
• Access via /dev/mem
– Faster, needs root, potentially dangerous!

• U...
GPIO Interface (I)
init(Pin, Direction) ->
{ok, FdExport} = file:open("/sys/class/gpio/export", [write]),
file:write(FdExp...
GPIO Interface (II)
write(Fd, Val) ->
file:position(Fd, 0),
file:write(Fd, integer_to_list(Val)).
read(Fd) ->
file:positio...
Example: GPIO
PidA
PidB

PidC

Pin17

???
22/03/2013

Erlang Factory SF Bay 2013

Slide 34 of 46
Example: GPIO
PidA
PidB

PidC
GPIO
Proxy

Pin17

22/03/2013

Erlang Factory SF Bay 2013

Slide 35 of 46
GPIO Proxy
• Replaces ‘locks’ in traditional sense of
embedded design
– Access control/mutual exclusion

• Can be used to ...
Concurrency Demo

http://vimeo.com/40769788
22/03/2013

Erlang Factory SF Bay 2013

Slide 37 of 46
Universal Peripheral/Component Modules

22/03/2013

Erlang Factory SF Bay 2013

Slide 38 of 46
Universal Peripheral/Component Modules

22/03/2013

Erlang Factory SF Bay 2013

Slide 39 of 46
Hardware Projects – Ponte

22/03/2013

Erlang Factory SF Bay 2013

Slide 40 of 46
Hardware Projects – Demo Board

22/03/2013

Erlang Factory SF Bay 2013

Slide 41 of 46
Hardware Simulator

22/03/2013

Erlang Factory SF Bay 2013

Slide 42 of 46
Future Explorations
Parallella:

22/03/2013

Erlang Factory SF Bay 2013

Slide 43 of 46
Packages for Embedded Architectures

https://www.erlang-solutions.com/downloads/download-erlang-otp

22/03/2013

Erlang Fa...
Erlang Embedded Training Stack
• A complete package for people interested in
developing the next generation of concurrent
...
Thank you
• http://erlang-embedded.com
• embedded@erlang-solutions.com
• @ErlangEmbedded

“

The world is concurrent.
Thin...
Upcoming SlideShare
Loading in...5
×

Taking Back Embedded: The Erlang Embedded Framework

876

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
876
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Taking Back Embedded: The Erlang Embedded Framework"

  1. 1. Taking Back Embedded The Erlang Embedded Project Omer Kilic || @OmerK omer@erlang-solutions.com
  2. 2. Outline • • • • • • Current state of Embedded Systems Overview of Erlang and the Actor Model Modelling and developing systems using Erlang The Erlang Embedded Project Future Explorations Q&A 22/03/2013 Erlang Factory SF Bay 2013 Slide 2 of 46
  3. 3. Embedded Systems “ 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. - Infinite Wisdom of Wikipedia 22/03/2013 Erlang Factory SF Bay 2013 Slide 3 of 46
  4. 4. Embedded Systems • Specific functions • Designed for a particular application 22/03/2013 Erlang Factory SF Bay 2013 • General purpose • Can be used for pretty much any computing needs Slide 4 of 46
  5. 5. Current Challenges • Complex SoC platforms • “Internet of Things” – Connected and distributed systems • Multicore and/or heterogeneous devices • Time to market constraints – The Kickstarter Era – Rapid prototyping – Maker Culture 22/03/2013 Erlang Factory SF Bay 2013 Slide 5 of 46
  6. 6. Internet of Things 22/03/2013 Erlang Factory SF Bay 2013 Slide 6 of 46
  7. 7. Internet of Fridges? 22/03/2013 Erlang Factory SF Bay 2013 Slide 7 of 46
  8. 8. Distributed Bovine Networks? 22/03/2013 Erlang Factory SF Bay 2013 Slide 8 of 46
  9. 9. Exciting times 22/03/2013 Erlang Factory SF Bay 2013 Slide 9 of 46
  10. 10. TI OMAP Reference System 22/03/2013 Erlang Factory SF Bay 2013 Slide 10 of 46
  11. 11. Samsung Exynos Reference System 22/03/2013 Erlang Factory SF Bay 2013 Slide 11 of 46
  12. 12. #include <stats.h> Source: http://embedded.com/electronics-blogs/programming-pointers/4372180/Unexpected-trends 22/03/2013 Erlang Factory SF Bay 2013 Slide 12 of 46
  13. 13. Embedded Systems • Bare Metal – No underlying OS or high level abstractions • RTOS – Minimal interrupt and switching latency, scheduling guarantees, minimal jitter • Embedded Linux – Slimmed down Linux with hardware interfaces 22/03/2013 Erlang Factory SF Bay 2013 Slide 13 of 46
  14. 14. RTOS Concepts • Notion of “tasks” • OS-supervised interprocess messaging – Shared memory • Mutexes/Semaphores/Locks • Scheduling – Pre-emptive: event driven – Round-robin: time multiplexed 22/03/2013 Erlang Factory SF Bay 2013 Slide 14 of 46
  15. 15. Embedded Linux • Not a new concept, increased popularity due to abundant supply of cheap boards – Raspberry Pi, Beagleboard/Beaglebone, Gumstix et al. • Familiar set of tools for software developers, new territory for embedded engineers – No direct mapping for RTOS concepts, especially tasks • Complex device driver framework – Here be dragons 22/03/2013 Erlang Factory SF Bay 2013 Slide 15 of 46
  16. 16. Erlang Embedded • Knowledge Transfer Partnership between 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 22/03/2013 Erlang Factory SF Bay 2013 Slide 16 of 46
  17. 17. Erlang? (I) {declarative, functional, concurrent, parallel, garbagecollected, soft real-time, fault-tolerant, robust, portable, distributed message-passing, hot code loading} 22/03/2013 Erlang Factory SF Bay 2013 Slide 17 of 46
  18. 18. Erlang? (II) • First version developed in 1986 – Open-sourced in 1998. • Battle-tested at Ericsson and many other companies – Originally designed for Embedded Systems! • Implements the Actor model – Support for concurrency and distributed systems out of the box • Easy to create robust systems 22/03/2013 Erlang Factory SF Bay 2013 Slide 18 of 46
  19. 19. High Availability/Reliability • Simple and consistent error recovery and supervision hierarchies • Built in fault-tolerance – Isolation of Actors • Support for dynamic reconfiguration – Hot code loading 22/03/2013 Erlang Factory SF Bay 2013 Slide 19 of 46
  20. 20. External Interfaces • Facilities to interface the Erlang runtime to the outside world • Used for device drivers and kernel abstractions in the embedded domain 22/03/2013 Erlang Factory SF Bay 2013 Slide 20 of 46
  21. 21. External Interfaces 22/03/2013 Erlang Factory SF Bay 2013 Slide 21 of 46
  22. 22. Actor Model • Proposed in 1973 by Hewitt, Bishop and Steiger – “Universal primitives for concurrent computation” • No shared-state, self-contained and atomic • Building blocks for modular, distributed and concurrent systems • Implemented in a variety of programming languages 22/03/2013 Erlang Factory SF Bay 2013 Slide 22 of 46
  23. 23. Actor Model • Asynchronous message passing – Messages kept in a mailbox and processed in the order they are received in • Upon receiving messages, actors can: – Make local decisions and change internal state – Spawn new actors – Send messages to other actors 22/03/2013 Erlang Factory SF Bay 2013 Slide 23 of 46
  24. 24. Process Error Handling • Let it Fail! – Abstract error handling away from the modules – Results in leaner modules • Supervision hierarchies 22/03/2013 Erlang Factory SF Bay 2013 Slide 24 of 46
  25. 25. Propagating Exit Signals {'EXIT', PidA, Reason} PidA PidB {'EXIT', PidB, Reason} PidC 22/03/2013 Erlang Factory SF Bay 2013 Slide 25 of 46
  26. 26. Trapping Exits process_flag(trap_exit, true) {'EXIT', PidA, Reason} PidA PidB PidC 22/03/2013 Erlang Factory SF Bay 2013 Slide 26 of 46
  27. 27. TI OMAP Reference System 22/03/2013 Erlang Factory SF Bay 2013 Slide 27 of 46
  28. 28. Fine Grain Abstraction • Advantages – Application code becomes simpler – Concise and shorter modules – Testing becomes easier – Code re-use (potentially) increases • Disadvantage – Architecting fine grain systems is difficult 22/03/2013 Erlang Factory SF Bay 2013 Slide 28 of 46
  29. 29. Limitations of the Actor Model • No notion of inheritance or general hierarchy – Specific to language and library implementation • Asynchronous message passing can be problematic for certain applications – Ordering of messages received from multiple processes – Abstract definition may lead to inconsistency in larger systems • Fine/Coarse Grain argument 22/03/2013 Erlang Factory SF Bay 2013 Slide 29 of 46
  30. 30. Erlang, the Maestro (flickr/dereckesanches) 22/03/2013 Erlang Factory SF Bay 2013 Slide 30 of 46
  31. 31. Accessing hardware • Peripherals are memory mapped • Access via /dev/mem – Faster, needs root, potentially dangerous! • Use kernel modules/sysfs – Slower, doesn’t need root, easier, relatively safer 22/03/2013 Erlang Factory SF Bay 2013 Slide 31 of 46
  32. 32. GPIO Interface (I) 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"); out -> file:write(FdPinDir, "out") end, file:close(FdPinDir), {ok, FdPinVal} = file:open("/sys/class/gpio/gpio" ++ integer_to_list(Pin) ++ "/value", [read, write]), FdPinVal. 22/03/2013 Erlang Factory SF Bay 2013 Slide 32 of 46
  33. 33. GPIO Interface (II) 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). 22/03/2013 Erlang Factory SF Bay 2013 Slide 33 of 46
  34. 34. Example: GPIO PidA PidB PidC Pin17 ??? 22/03/2013 Erlang Factory SF Bay 2013 Slide 34 of 46
  35. 35. Example: GPIO PidA PidB PidC GPIO Proxy Pin17 22/03/2013 Erlang Factory SF Bay 2013 Slide 35 of 46
  36. 36. GPIO Proxy • Replaces ‘locks’ in traditional sense of embedded design – Access control/mutual exclusion • Can be used to implement safety constraints – Toggling rate, sequence detection, direction control, etc. 22/03/2013 Erlang Factory SF Bay 2013 Slide 36 of 46
  37. 37. Concurrency Demo http://vimeo.com/40769788 22/03/2013 Erlang Factory SF Bay 2013 Slide 37 of 46
  38. 38. Universal Peripheral/Component Modules 22/03/2013 Erlang Factory SF Bay 2013 Slide 38 of 46
  39. 39. Universal Peripheral/Component Modules 22/03/2013 Erlang Factory SF Bay 2013 Slide 39 of 46
  40. 40. Hardware Projects – Ponte 22/03/2013 Erlang Factory SF Bay 2013 Slide 40 of 46
  41. 41. Hardware Projects – Demo Board 22/03/2013 Erlang Factory SF Bay 2013 Slide 41 of 46
  42. 42. Hardware Simulator 22/03/2013 Erlang Factory SF Bay 2013 Slide 42 of 46
  43. 43. Future Explorations Parallella: 22/03/2013 Erlang Factory SF Bay 2013 Slide 43 of 46
  44. 44. Packages for Embedded Architectures https://www.erlang-solutions.com/downloads/download-erlang-otp 22/03/2013 Erlang Factory SF Bay 2013 Slide 44 of 46
  45. 45. Erlang Embedded Training Stack • A complete package for people interested in developing the next generation of concurrent and distributed Embedded Systems • Training Modules: – Embedded Linux Primer – Erlang/OTP 101 – Erlang Embedded Framework Get in touch if you’re interested. 22/03/2013 Erlang Factory SF Bay 2013 Slide 45 of 46
  46. 46. Thank you • http://erlang-embedded.com • embedded@erlang-solutions.com • @ErlangEmbedded “ The world is concurrent. Things in the world don't share data. Things communicate with messages. Things fail. - Joe Armstrong Father of Erlang 22/03/2013 Erlang Factory SF Bay 2013 Slide 46 of 46
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×