Real Time Multitasking Con Arduino
Real Time Multitasking Con Arduino
Arduino
Who I am
Pasquale Buonocunto
Research
Interests
Who I am
Alessandro Biondi
Research
Interests
Arduino Framework
Arduino is a tool for making computers that can sense
and control more of the physical world than your
desktop computer.
Very popular
2013: 700,000+ official boards were in users' hands
(not counting unofficial clones)
Arduino Framework
Very simple!
Simple programming interface;
Easy firmware loading;
Arduino Framework
Low cost
Arduino Uno ~20;
Arduino Due ~35.
Arduino Framework
Very popular
Embedded system
Simple programming
interface;
programming
for
everyone
Easy firmware loading.
Low cost
~20$ official
9
Arduino Framework
Very simple!
10
Arduino Framework
void setup() {
<instructions here>
One-shot execution
at startup
void loop() {
<instructions here>
delay(1000);
Cyclically executed
until power off!
}
11
Arduino Framework
A lot of libraries
Standard Libraries
EEPROM
Ethernet
GSM
LiquidCrystal
SD
Servo
SPI
SoftwareSerial
Stepper
TFT
WiFi
Wire
Contributed Libraries
Messenger
NewSoftSerial
OneWire
PS2Keyboard
Simple Message System
SSerial2Mobile
Webduino
X10
XBee
SerialControl
Capacitive Sensing
Debounce
GLCD
Improved LCD
LedControl
LedDisplay
Matrix
PCD8544
Sprite
ST7735
FFT
Tone
TLC5940
DateTime
Metro
MsTimer2
PString
Streaming
12
}
13
Existing Solutions
Scheduler Library
Support for multiple concurrent loops;
Cooperative Scheduler: each task is
responsible to pass the baton;
No periodic activities can be expressed;
Experimental Library.
14
Existing Solutions
Scheduler Library
void setup() {
Scheduler.startLoop(func1);
Scheduler.startLoop(func2);
}
void func1() {
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);
}
void func2() {
<instructions here>
yield(); // Pass control to other tasks.
}
Existing Solutions
Scheduler Library
void setup() {
Scheduler.startLoop(func1);
Scheduler.startLoop(func2);
}
void func1() {
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);
}
void func2() {
<instructions here>
yield(); // Pass control to other tasks.
}
No Scheduling
Policy
The scheduling
pattern is established
by explicit call to
yield() or delay()
16
Existing Solutions
Scheduler Library
void setup() {
Scheduler.startLoop(func1);
Scheduler.startLoop(func2);
}
void func1() {
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);
}
void func2() {
<instructions here>
yield(); // Pass control to other tasks.
}
No Real-Time
No Periodic Activities
No Preemption
17
Existing Solutions
Other Solutions:
Arduino Simple Task Scheduler;
Looper;
WrapOS;
18
Existing Solutions
scheduler.createSchedule(7*20*4, -1, false, put_leds_into_cycle);
Main(void) // entry point
uint32_t pid = scheduler.createSchedule(50, -1, false, void
callback_function);
{
scheduler.beginProfiling(pid);
SEM_ID sem1;
scheduler.stopProfiling(pid);
MSGQ_ID msgQ1;
scheduler.clearProfilingData(pid);
char * temp = dumpProfilingData(void);
if (temp != NULL) {
Serial.println(temp);
free(temp);
}
} itself up. */
/* Fires callback_function() after 790ms, and then cleans
scheduler.createSchedule(790, 0, true, callback_function);
void task1(void)
{
/* Blinks an LED for (20*9)ms. */
scheduler.createSchedule(20, 9, true, toggle_led);
19
Existing Solutions
scheduler.createSchedule(7*20*4, -1, false, put_leds_into_cycle);
Main(void) // entry point
uint32_t pid = scheduler.createSchedule(50, -1, false, void
callback_function);
{
scheduler.beginProfiling(pid);
SEM_ID sem1;
scheduler.stopProfiling(pid);
MSGQ_ID msgQ1;
scheduler.clearProfilingData(pid);
char * temp = dumpProfilingData(void);
if (temp != NULL) {
Serial.println(temp);
free(temp);
}
} itself up. */
/* Fires callback_function() after 790ms, and then cleans
scheduler.createSchedule(790, 0, true, callback_function);
void task1(void)
{
/* Blinks an LED for (20*9)ms. */
scheduler.createSchedule(20, 9, true, toggle_led);
20
ARTE
21
23
24
time
Standard Real-time programming model:
Periodic activities without explicit
delay/suspensions;
Be predictable: polling preferred to event
reaction.
25
time
Typical Real-Time Applications:
Sampling sensors and actuating (e.g., control
loop,);
Multimedia and transmissions;
26
time
Deadline: we want the task finishing before the
next activation.
27
29
Erika Enterprise
Example
Make blinking three different leds, each one at a
different frequency.
Led1: 3s
Led2: 7s
Led3: 11s
Robotmill.com
31
Example
With classical
Arduino
programming
model
Led1
3s
Led2
7s
Led2
11s
if (count%11 == 0)
digitalToggle(led3);
if (count == 3*7*11)
count = 0;
count++;
delay(1000);
}
32
Example
ARTE
With Arduino
Real-Time
Extension
Led1
3s
Led2
7s
Led2
11s
33
Example
34
35
ARTE
36
Example
int led1 = 13;
int led2 = 14;
int led3 = 15;
void loop1(3000) {
digitalToggle(led1);
}
RT
Task 1
RT
Task 2
RT
Task 3
void loop2(7000) {
digitalToggle(led2);
}
void loop3(11000) {
digitalToggle(led3);
}
37
Erika Enterprise
38
Example
Mapping to an OSEK application
int led1 = 13;
int led2 = 14;
int led3 = 15;
void loop1(3000) {
digitalToggle(led1);
}
void loop2(7000) {
digitalToggle(led2);
}
void loop3(11000) {
digitalToggle(led3);
}
OIL
TASK loop1 {
PRIORITY = 0x01;
SCHEDULE = FULL;
STACK = SHARED;
};
ALARM Alarmloop1 {
COUNTER = TaskCounter;
ACTION = ACTIVATETASK {
TASK = loop1;
};};
TASK loop2 {
PRIORITY = 0x02;
SCHEDULE = FULL;
STACK = SHARED;
};
ALARM Alarmloop2 {
COUNTER = TaskCounter;
ACTION = ACTIVATETASK {
TASK = loop2;
};};
TASK loop3 {
PRIORITY = 0x03;
SCHEDULE = FULL;
STACK = SHARED;
};
ALARM Alarmloop3 {
COUNTER = TaskCounter;
ACTION = ACTIVATETASK {
TASK = loop3;
};};
39
Build Process
ARTE application
Core of the Arduino
Real-Time Extension
Generates an ERIKA
application code
starting from the
Arduino code
Parse the sketch an
automatically generates
the RTOS configuration
40
Build Process
OIL (OSEK
Implementation
Language)
41
Build Process
42
Build Process
43
DEMO
44
45
Conclusion
ARTE is an extension for the Arduino
framework to support Real-Time Multitasking;
Simple programming interface with minimal
impact on the Arduino programming model;
Relies on an OSEK/VDX RTOS (ERIKA Enterprise);
46
Thank you!
Alessandro Biondi
[email protected]
Pasquale Buonocunto
[email protected]
47