Erlang and RTEMS Embedded Erlang, two case studies Peer Stritzinger - - PowerPoint PPT Presentation

erlang and rtems
SMART_READER_LITE
LIVE PREVIEW

Erlang and RTEMS Embedded Erlang, two case studies Peer Stritzinger - - PowerPoint PPT Presentation

Erlang and RTEMS Embedded Erlang, two case studies Peer Stritzinger Talk at Erlang Factory Light Munich 2013 Outline Case 1: Hydraprog-3, Reflashing system for Automotive "Embedded Control Units" (= ECUs) Big picture


slide-1
SLIDE 1

Erlang and RTEMS

Embedded Erlang, two case studies Peer Stritzinger Talk at Erlang Factory Light Munich 2013

slide-2
SLIDE 2
  • Case 1: Hydraprog-3, Reflashing system for Automotive

"Embedded Control Units" (= ECUs)

  • Big picture
  • Erlang code structure
  • Lessons learnt
  • Case 2: Intelligent RFID Antenna
  • Porting Erlang on RTEMS (work in progress)

Outline


slide-3
SLIDE 3
slide-4
SLIDE 4
  • LIN ✓
  • LS-CAN ✓
  • HS-CAN ✓
  • FlexRay ✓
  • MOST ✓
  • OABR (Ethernet with special Phys. Layer) (... in development)
  • APIX1+2 ✓ - Ethernet via APIX (... in development)

Automotive Protocols

slide-5
SLIDE 5

Automotive Protocol Properties

  • Flash process in most cases defined over Diagnostic

protocol

  • Ping-Pong protocol => latency issues
  • Mapping to lower level: usually bursty with timing/buffer

negotiations

  • realtime requirements: semi-hard-realtime to really-hard
  • Big variety of link and physical layers
slide-6
SLIDE 6

Mainboard Mini ITX Intel Atom FreeBSD, Erlang Ethernet Switch / USB Hub Gateways custom Freescale MPC5517 RTEMS Gateways custom Freescale MPC5517 RTEMS USB USB Ethernet

slide-7
SLIDE 7

FreeBSD

  • Boots from read-only CF-card partition
  • 2 Partitions for upgrade
  • Partition for config storage copied to /etc in ramdisk
  • Extra partition for logging
  • Built with NanoBSD script
slide-8
SLIDE 8

Erlang

  • Runs as much of the automotive protocols as possible
  • Protocol layers stackable by user config
  • Uses libusb in a port to talk to the gateways
  • USB bus is scanned regularly
  • Supervised protocol stacks are started for each gateway
slide-9
SLIDE 9

Distributed Device

  • Multiple devices self network
  • Behave like one device with more channels
slide-10
SLIDE 10

RTEMS

  • Hard-Realtime embedded executive
  • Small core with several APIs
  • Posix API
  • TCP/IP stack
  • Several schedulers
slide-11
SLIDE 11

RTEMS cont.

  • About the same age as Erlang
  • Also very robust
  • Runs in many satellites and planetary probes
  • Industrial and Automotive applications
  • Great support in Europe: www.embedded-brains.de
slide-12
SLIDE 12

RTEMS in Hydraprog-3 Gateways

  • Gets commands and data packets from USB
  • Controls and switches power to the connected ECUs
  • Protocol parts that require hard realtime or low latency
  • Talks to Low-Speed CAN, High-Speed CAN, FlexRay,

MOST, LIN

  • Controls the display LEDs
slide-13
SLIDE 13

Talking to (internal) USB Devices

  • C executable + libusb via port
  • Easy error handling
  • Problem: USB device enumeration doesn’t tell you what is

where

  • Solution: Id + Serial number + Hw-Config file
  • Also: USB is weird
  • But bulk endpoints are easy once they are established
slide-14
SLIDE 14

USB Hot-Plugging

scan_usb gateway_sup sup sup sup worker worker worker temporary transient

slide-15
SLIDE 15

Gateway queue handling

control eeprom ls_can power Gateway usb_mux

control eeprom ls_can power

usb_port libusb-port.c usb

slide-16
SLIDE 16

Protocol Layer Plumbing

  • Dynamic configuration during startup
  • Minimize latency
  • Differing state requirements
  • Stateless -- encoders/decoders
  • Configuration state
  • Runtime state
slide-17
SLIDE 17

Example: MOST Stack

uds_most most_high most_nwm most most_tmm most_seg inic most_msgs codec_most {moco_hbi} codec_most {inic_ctrl} codec_most {moco_ctrl} devnull autosar_nm codec_can most_msgs most_msgs usb_mux

slide-18
SLIDE 18

Example: MOST Stack

[[[uds_most, most_high, most_nwm, most, most_tmm, most_seg, inic, [[most_msgs, {codec_most, [inic_ctrl, simple]}, {usb_mux, ['Usb_mux', inic_ctrl]}], [most_msgs, {codec_most, [moco_ctrl, simple]}, {usb_mux, ['Usb_mux', moco_ctrl]}], [most_msgs, {codec_most, [moco_hbi, simple]}, {usb_mux, ['Usb_mux', moco_hbi]}]]], [devnull, autosar_nm, {codec_can, []}, {usb_mux, ['Usb_mux', hs_can]}]]]}

  • Dynamic config: DAG like combination of modules
slide-19
SLIDE 19

Protocol-Stack config and Flash-Data Distribution

Data Logs

slide-20
SLIDE 20

Signed Autoexec Erlang App

*.h3x

Erlang app config

signed & encrypted

Auth keys extra modules User Data + Script

*.zip

slide-21
SLIDE 21

Scripting "language"

  • Re-used Erlangs parser
  • Interpreting the abstract syntax
  • Different, domain specific semantics
slide-22
SLIDE 22

Reducing Latency

  • Send - Expect Engine in Gateway
  • Complicates protocol implementation
  • Enables streaming + optimal performance
  • Libusb support as port driver
  • High stability requirements
  • Initially on separate nodes
slide-23
SLIDE 23

Lessons Learnt

  • Use gproc next time right away
  • Startup was messier than it needed to be without it
  • Use Quickcheck for testing right away
  • Start doing OTP Releases earlier
slide-24
SLIDE 24

Erlang and RTEMS in Hydraprog-3

  • Collaborates on different CPUs
  • Best of both worlds
  • Solution for larger devices
  • More on http://www.stritzinger.com
slide-25
SLIDE 25

What about Hard Realtime?

  • Erlang has very good soft realtime responsiveness
  • Embedded applications often need hard realtime
  • Erlang alone can't do this
  • Especially on "normal" operating systems
  • Usually only small part required to be hard realtime
slide-26
SLIDE 26

Erlang Running on RTEMS

  • Small embedded system
  • Only a small communication controller
  • Freescale MPC8309
  • Still want best of both worlds
  • RTEMS Posix API has almost everything Erlang needs
slide-27
SLIDE 27

Porting Erlang to RTEMS

  • Work in progress, at the moment (Feb 2013)
  • Erlang shell on RS232 console
  • Linked in drivers
  • Cross-built with otp_build using RTEMS build tools
  • RTEMS gets linked as a library
  • File access on target via NFS
slide-28
SLIDE 28

In Progress

  • Get distribution working (epmd needs porting or faking)
  • Build Erlang as loadable application with new RTEMS

Linker

  • Threads for async I/O
  • Support for NIFs with new dynamic linking support
  • Adding kqueue support to RTEMS
slide-29
SLIDE 29

Future

  • Support for some RTEMS primitives from Erlang
  • Get all necessary patches back to RTEMS and OTP
  • Have a documented standard way to build Erlang/RTEMS
  • Once RTEMS gets stable SMP

, support it from Erlang

slide-30
SLIDE 30

Questions

  • Contact: peer@stritzinger.com
  • Twitter: @peerstr
  • IRC: peerst