Concurrent Event-driven Programming in occam-pi for the Arduino
Christian L. Jacobsen, Matthew Jadud, Omer Kilic, and Adam Sampson
University of Copenhagen Allegheny College University of Kent University of Abertay Dundee
Concurrent Event-driven Programming in occam-pi for the Arduino - - PowerPoint PPT Presentation
Concurrent Event-driven Programming in occam-pi for the Arduino Christian L. Jacobsen, Matthew Jadud, Omer Kilic, and Adam Sampson University of Copenhagen Allegheny College University of Kent University of Abertay Dundee June 21st, 2011
University of Copenhagen Allegheny College University of Kent University of Abertay Dundee
1 Introduction 2 The Arduino 3 Implementation 4 Implementation 5 Interrupts 6 Case Study: A Room Usage Monitor 7 Conclusions and Future Work 8 Questions
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 2 / 30
A very brief history occam
1 occam on the Transputer 2 occam on SPARC, Alpha, etc. 3 occam-π on x86 4 occam-π on the Transterpreter
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 3 / 30
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 4 / 30
A very brief overview
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 5 / 30
A very brief overview
Figure: The Arduino, an open hardware platform.
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 6 / 30
A very brief overview
Figure: Concurrency.cc board
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 7 / 30
Goals in porting to the Arduino
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 8 / 30
The IDE is key
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 9 / 30
Variants, community, businesses
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 10 / 30
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 11 / 30
In C
boolean state[4] = {false, false, false, false}; unsigned long prev = 0; void setup () { Serial.begin(9600); for (int i = 0; i < 4; i++) { pinMode(10+i, OUTPUT); } } void toggle (int pin) { boolean val = state[pin − 10]; digitalWrite(pin, !val); state[pin − 10] = !val; }
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 12 / 30
In C
void loop () { unsigned long time = millis(); if (time != prev) { if ((time % 200) == 0) { toggle(13); } if ((time % 300) == 0) { toggle(12); } if ((time % 400) == 0) { toggle(11); } if ((time % 500) == 0) { toggle(10); } prev = time; } }
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 13 / 30
In occam
#INCLUDE "plumbing.module" PROC main () PAR blink (13, 500) blink (12, 400) blink (11, 300) blink (10, 200) :
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 14 / 30
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 15 / 30
... in one slide...
Scheduler Interpreter Error Handling
Virtual Machine Runtime Libraries Plumbing User Programs
Interrupts Implemented in C Implemented in occam
Linked as required Firmware Serial, PWM, TWI ... heartbeat, button.press ...
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 16 / 30
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 17 / 30
INITIAL INT vintr IS (− 1): SEQ set.interrups (avr.pin, vintr) WHILE TRUE ... wait.for.interrupt (vintr, any) ...
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 18 / 30
Power Consumption
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 19 / 30
A hardware interrupt is raised.
hardware Transterpreter
RESCHEDULE
wait
INT
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 20 / 30
It is lifted into a “soft interrupt” in the VM.
hardware Transterpreter
RESCHEDULE
wait
INT
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 21 / 30
A natural occam-pi rescheduling point is reached.
hardware Transterpreter
RESCHEDULE
wait
INT
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 22 / 30
wait.for.interrupt is unblocked.
hardware Transterpreter
RESCHEDULE
wait
GO
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 23 / 30
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 24 / 30
Context
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 25 / 30
Sensor
Figure: The Environmental Sensor
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 26 / 30
Results
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 27 / 30
The role of interrupts
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 28 / 30
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 29 / 30
Concurrent Event-driven Programming in occam-pi for the Arduino CPA 2011 – June 21st, 2011 30 / 30