Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Programming Gogo

A book about gogo: a tiny actor VM for microcontrollers, programmed in a subset of Go, with Erlang-style actors, supervisors and ports.

It is written for programmers who know some Go or another C-like language, and assumes no knowledge of embedded programming or Erlang.

Contents

  1. Preface: what gogo is, what it is good for, and what it is not
  2. Getting Started: gogo setup, build the tools, run a program, flash a board
  3. Language Basics: the Go subset, what it leaves out, and what to write instead
  4. Actors: Spawn, Send, Receive, type switches, Call/Reply, names, timers, actors on other boards (with chapter 20)
  5. Failure and Recovery: exit reasons, links, monitors, TrapExit, supervisors, “let it crash”
  6. Memory Model: per-actor heaps and limits, copied messages, mailbox quotas, Bytes and Buffer
  7. Ports and Peripherals: ports, GPIO, events, debouncing, owners, Handoff
  8. Keyboard and Power: the kbd and power ports
  9. Storage: /flash and /sd, gogo/fs, gogo/kv, gogo/ringlog
  10. Networking: DHCP, DNS, UDP, TCP, the HTTP client and server, the wall clock (gogo/sys, gogo/sntp)
  11. Configuration and Devices: gogo config, sys.Config, Wi-Fi, the two boards
  12. Toolchain Reference: gogo build, run, dis, flash, monitor, firmware, config, setup
  13. Appendices: library quick reference, exit reasons, error codes, limits, differences from Go, requirement names
  14. Hot Loading: loading code at run time, modules, supervised upgrades
  15. IMU and IR: the motion sensor, infrared send and receive, streams (Chunk, Out, Done)
  16. Audio: the microphone and speaker, recording to WAV files, playing them back
  17. HTTPS: https URLs, the clock, the keep-alive http.Client, streaming uploads, the "tls" port
  18. Embedding gogo: running gogo images inside a C program: libgogo.a, the host table and the latched wake, stepping, posts, host ports, a sandboxed /flash
  19. Text UI: the "screen" port, gogo/tui: frames, windows, colours, menus, progress bars, status lines, a line editor, keys on both boards
  20. Distributed Actors: gogo/node: a server node and boards, remote PIDs, names, what a message may hold, lost nodes, security
  21. Best Practices: actors as small machines, messages and Bytes, backpressure, shared state, Call discipline, restarts, receive order, C or gogo, high-bandwidth streams (audio, sensors, cameras), streaming TCP and HTTP, a checklist
  22. Extending gogo with C: why there is no FFI, port drivers in C (the driver table, events, memory, requirements, optional features, host simulation), a tested driver with generic types, host ports, pitfalls
  23. Bluetooth LE: the "ble" port, a peripheral a phone app talks to: services and characteristics, events, values a phone reads, notifications with flow control, nRF Connect, the host simulation, memory and Wi-Fi

Known issues lists gogo’s open limitations, with workarounds.

Examples

Every program in the book is a complete, runnable example in examples/, one directory per program, named after its chapter (04-call, 09-kv-boot, …). The output printed in the book is the real output of the host VM, kept next to each program in expected.out and expected.err. To run them all and check that the book is still right:

make vm
go build -o build/gogo ./cmd/gogo
docs/book/examples/run.sh

Chapter 23’s programs need a phone: each has a phone script that tests/ble plays over gogovm’s Bluetooth socket (go test ./tests/ble/, part of make test), and run.sh skips them.

Chapter 20’s programs need several VMs: they are the server and boards of tests/dist/progs, run as separate host VMs over real TCP by go test ./tests/dist/.

Chapter 18’s C programs are in examples/embed-c/; make example-embed builds them, runs them and checks that every C snippet in the chapter is cut from them. Chapter 22’s driver is in examples/dice-driver/; make example-driver runs it on its test board and checks the chapter’s snippets against the tree.