embedded elixir - coginierlang features supervision trees good behavior when hitting resource limits...
TRANSCRIPT
![Page 2: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/2.jpg)
What is Embedded Programming?
Systems that interact with the physical world
Resource constrained systems
Machines controlled by software
Robots
Appliances
![Page 3: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/3.jpg)
Systems that interact with thephysical world
Micro-controllers
– 8-bit, e.g. 8051, PIC, Atmel (Arduino)
– 16-bit, e.g. ARM
Digital I/O
Analog I/O
Pulse Width Modulation
Sensors
– Temperature
– Accelerometer
– GPS
![Page 4: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/4.jpg)
IoT
Data collection + networking
![Page 5: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/5.jpg)
We are the winners of the "cellphone wars"
Raspberry PI (Broadcom)
Beaglebone (TI)
C.H.I.P. (Microtek)
![Page 6: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/6.jpg)
Embedded Projects
GPS tracker + controller
VoIP IP-PBX
Logo inserter for satellite television
![Page 7: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/7.jpg)
GPS tracker + controller
4 MB RAM / 2 MB ROM / no MMU :-(
GPS / GPRS / GPIO
Embedded Linux (uCLinux)
Over the air updates
Over the air configuration
C/C++ initially, later Lua
![Page 8: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/8.jpg)
Robots
![Page 9: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/9.jpg)
VoIP IP-PBX
Appliance
Embedded Linux (Ubuntu, OpenEmbedded)
Xen VMs
– Firewall
– Configuration
– Application
Python
Lots of resources, challenge is configuration andmanagement
![Page 10: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/10.jpg)
Logo inserter for satellite television
Embedded Linux (Ubuntu)
Proprietary drivers for SDI card
C++ for image manipulation
Erlang for supervision and configuration
![Page 11: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/11.jpg)
Erlang was designed for this!
Telephone switch
Interfacing with switch hardware
"Soft" real time
SunOS, 32 MB of RAM
VxWorks RTOS
![Page 12: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/12.jpg)
Erlang Features
Functional programming
– Outputs depend only on inputs
– No side effects
– Pattern matching: reject invalid input
– Crash dumps with state of whole system
![Page 13: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/13.jpg)
Erlang Features
Supervision trees
Good behavior when hitting resource limits
Concurrency: isolate one request from another
Distributed programming: Reliability requires morethan one computer
OTP standardizes behaviors, e.g. supervisor,client server, event handling
![Page 14: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/14.jpg)
Erlang Features
Tracing live systems without big performanceimpact
Ability to see state of running system, e.g.observer
Built-in in-memory database, replicated acrossnodes
![Page 15: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/15.jpg)
Inter-process Communication: NIF
Embed C in Erlang VM
High performance but dangerous
Good for things like crypto
![Page 16: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/16.jpg)
Inter-process Communication: Port
VM supervises external process
Erlang code sends messages to port, which talksto external process
Communication over stdin/stdout
Lower performance but full isolation
Serialization overhead
![Page 17: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/17.jpg)
Inter-process Communication:Erlport / Snake
Interop between Erlang and Python or Ruby
Pool of worker processes to handle jobs
Data structure conversion
http://erlport.org/
https://github.com/arthurcolle/elixir-snake
![Page 18: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/18.jpg)
Inter-process communication:Erlang protocol libraries
Turn your code into an Erlang node
Protocol libraries for for C, Java and .NET
Reasonably good performance, still serializationoverhead
![Page 19: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/19.jpg)
Inter-process communication:Standard protocols
HTTP
AMQP
ZeroMQ
...
![Page 20: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/20.jpg)
Over the Air Updates
Quadcopter In-flight Firmware Upgrade
https://www.youtube.com/watch?v=96UzSHyp0F8
![Page 21: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/21.jpg)
Building embedded systems
Erlang Releases
– Combine VM and libraries used by the app
– Handle hot code updates
Watchdog
– Erlang VM has its own supervisor
– Start VM from /etc/inittab and you are done
![Page 22: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/22.jpg)
Nerves
http://nerves-project.org/
https://hexdocs.pm/nerves/getting-started.html
Linux Kernel + Erlang VM + goodies
Erlang VM as init / PID 1
![Page 23: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/23.jpg)
Nerves Modules
Configure network interfaces
Connect to WiFi networks
Use serial ports
Drive LEDs
Interface with input events /dev/input/event
Over-the-network firmware management
Simple Service Discovery Protocol (SSDP) Client andServer
![Page 24: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/24.jpg)
Nerves Howto: Install Nerves
mix archive.installhttps://github.com/nerves-project/archives/raw/master/nerves_bootstrap.ez
![Page 25: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/25.jpg)
Nerves Howto: Generate andcompile just like any Elixir project
mix nerves.new hello_nerves --target rpi3
cd hello_nerves
mix deps.get
mix compile
![Page 26: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/26.jpg)
Nerves Howto: Build your firmwareand burn it to an SD card
mix firmware
mix firmware.burn
![Page 27: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/27.jpg)
Nerves Howto
![Page 28: Embedded Elixir - CoginiErlang Features Supervision trees Good behavior when hitting resource limits Concurrency: isolate one request from another Distributed programming: Reliability](https://reader034.vdocuments.net/reader034/viewer/2022042802/5f39a27af3652479e51ac949/html5/thumbnails/28.jpg)
Questions?