Real-Time Multitasking in Arduino. Pasquale Buonocunto, Alessandro Biondi, Pietro Lorefice

Similar documents
ERIKA Enterprise pre-built Virtual Machine

MeshBee Open Source ZigBee RF Module CookBook

Surveillance System Using Wireless Sensor Networks

Trampoline OSEK-VDX & AUTOSAR Compliant Open Source Real-Time Operating System

Embedded OS. Product Information

Simple Cooperative Scheduler for Arduino ARM & AVR. Aka «SCoop»

Real-Time Component Software. slide credits: H. Kopetz, P. Puschner

CGI-based applications for distributed embedded systems for monitoring temperature and humidity

Company description

DESIGN AND IMPLEMENTATION OF ONLINE PATIENT MONITORING SYSTEM

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

RTOS based Home Automation System using Android

Cypress Semiconductor: Arduino Friendly PSoC Shield

Application Note: AN00121 Using XMOS TCP/IP Library for UDP-based Networking

OSEK/VDX. Operating System. Version February 17 th, 2005

Linux A multi-purpose executive support for civil avionics applications?

Embedded Systems. 6. Real-Time Operating Systems

Complete Integrated Development Platform Copyright Atmel Corporation

Internet of things (IOT) applications covering industrial domain. Dev Bhattacharya

An introduction to nxpusblib. March 2012

Performance Comparison of RTOS

XMOS Programming Guide

Servo Motor API nxt_motor_get_count nxt_motor_set_count nxt_motor_set_speed

A Co-operative First Approach to Software Development for Reliable Embedded Systems

Embedded Software Development: Spottbillige Hardware + OSS = Zum Spielen zu Schade!

TivaWare Utilities Library

OPART: Towards an Open Platform for Abstraction of Real-Time Communication in Cross-Domain Applications

Real- Time Wireless Sensor- Actuator Networks

Cyclic Architectures in UML

Mobile Operating Systems Lesson 03 PalmOS Part 1

Mobile Operating Systems Lesson 05 Windows CE Part 1

Predictable response times in event-driven real-time systems

MQX Lite Real-Time Operating System User Guide

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

AN1229. Class B Safety Software Library for PIC MCUs and dspic DSCs OVERVIEW OF THE IEC STANDARD INTRODUCTION

VoIP support on Qtopia. Vladimir Minenko, Ph.D.

AC : A SIMPLE MULTITASKING LIBRARY FOR STUDENT PROJECTS AND INTRODUCING EMBEDDED OPERATING SYSTEMS PRINCIPLES

STM32JAVA. Embedded Java Solutions for STM32

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

S and STEP 7 Basic V10.5

Keys To Developing an Embedded UA Server

The Real-Time Operating System ucos-ii

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

ECU State Manager Module Development and Design for Automotive Platform Software Based on AUTOSAR 4.0

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Prototyping Connected-Devices for the Internet of Things. Angus Wong

Bug hunting. Vulnerability finding methods in Windows 32 environments compared. FX of Phenoelit

Board also Supports MicroBridge

Chapter 1 Lesson 3 Hardware Elements in the Embedded Systems Chapter-1L03: "Embedded Systems - ", Raj Kamal, Publs.: McGraw-Hill Education

Arduino Lesson 16. Stepper Motors

EE 472 Lab 2 (Group) Scheduling, Digital I/O, Analog Input, and Pulse Generation University of Washington - Department of Electrical Engineering

Technical Report CS : A Performance Analysis of MANTIS and TinyOS

Workshop Intel Galileo Board

Building Internet of Things applica5ons with COMPOSE and JavaScript Charalampos

Application Note: AN00141 xcore-xa - Application Development

Arduino Wifi shield And reciever. 5V adapter. Connecting wifi module on shield: Make sure the wifi unit is connected the following way on the shield:

Company Overview & Capabilities

Notes and terms of conditions. Vendor shall note the following terms and conditions/ information before they submit their quote.

Introduction to the NI Real-Time Hypervisor

Mobile Operating Systems. Week I

Interfacing an HTML Form to the ez80f91 MCU

ESP 8266: A BREAKTHROUGH IN WIRELESS SENSOR NETWORKS AND INTERNET OF THINGS

ADL User Guide for Open AT V4.10

APPLICATION NOTE. AT04056: Getting Started with FreeRTOS on Atmel SAM Flash MCUs. Atmel SMART. Introduction

Chapter 13 Embedded Operating Systems

A Transport Protocol for Multimedia Wireless Sensor Networks

Arduino Lesson 1. Blink

Real Time Programming: Concepts

AN OSEK/VDX-BASED MULTI-JVM FOR AUTOMOTIVE APPLIANCES

Real-Time Operating Systems With Example PICOS18. What is an Operating System?

Module 8. Industrial Embedded and Communication Systems. Version 2 EE IIT, Kharagpur 1

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

Embedded Software development Process and Tools:

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

Resource Utilization of Middleware Components in Embedded Systems

LEGO NXT-based Robotic Arm

How To Control A Car With A Thermostat

What marketing won t tell you about the Internet of Things

Keil C51 Cross Compiler

NEW. EVEN MORE data acquisition and test stand automation

ecifs In Depth Copyright 2001, CodeFX

Lecture 1 Introduction to Android

REAL TIME OPERATING SYSTEMS. Lesson-10:

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

Open Source Software

Embedded & Real-time Operating Systems

Home Security System for Automatic Doors

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

Fastboot Techniques for x86 Architectures. Marcus Bortel Field Application Engineer QNX Software Systems

Communication Protocol

PART I: WELCOME TO THE WONDERFUL WORLD OF ACCESSORIES CHAPTER 1: INTRODUCTION TO ANDROID OPEN ACCESSORY 3

Object Oriented Software Design II

快 速 porting μc/os-ii 及 driver 解 說

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

Exploiting USB Devices with Arduino. Greg Ose Black Hat USA 2011

M85 OpenCPU Solution Presentation

MPLAB Harmony System Service Libraries Help

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

APPLICATION NOTE. AVR2130: Lightweight Mesh Developer Guide. Atmel MCU Wireless. Features. Description

Transcription:

Real-Time Multitasking in Arduino Pasquale Buonocunto, Alessandro Biondi, Pietro Lorefice 1

Who I am Pasquale Buonocunto PhD Fellow at Scuola Superiore Sant'Anna Graduated cum Laude (Oct 2012) in Computer Engineering at University of Pisa Nov 2012, now PhD Fellow on Embedded Systems at TeCIP Institute, Scuola Superiore Sant'Anna, Pisa. Research Interests Real-time operating systems: design and implementation; Real-time wireless communication Wearable, low power e-health devices 4

Who I am Alessandro Biondi PhD Fellow at Scuola Superiore Sant'Anna Graduated cum Laude in 2013 in Computer Engineering at University of Pisa, within the excellence program; Aug 2011, Oct 2011 Visiting student @ San Diego State University, California. Research Interests Real-time operating systems: design and implementation; Real-time schedulability analysis; Hierarchical systems; Synchronization protocols. 5

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 ) 6

Arduino Framework Very simple! Simple programming interface; Easy firmware loading; 7

Arduino Framework Low cost Arduino Uno ~20 ; Arduino Due ~35. 8

Arduino Framework Very popular 2013: 700,000+ official boards were in users' hands Very simple! Simple programming interface; Easy firmware loading. Low cost ~20$ official Embedded system programming for everyone 9

Arduino Framework Very simple! 10

Arduino Framework void setup() { One-shot execution <instructions here> at startup void loop() { <instructions here> delay(1000); Cyclically executed until power off! 11

Arduino Framework A lot of libraries Standard Libraries Contributed Libraries EEPROM Ethernet GSM LiquidCrystal SD Servo SPI SoftwareSerial Stepper TFT WiFi Wire 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

Limitation of the Arduino Framework No support for concurrency; Execution limited to a single loop of instructions; No period can be expressed. void loop() { <instructions here> delay(1000); 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. Pass the control to func2() Pass the control to func1() 15

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

Scheduler Library Existing Solutions void setup() { Scheduler.startLoop(func1); Scheduler.startLoop(func2); void func1() { digitalwrite(led2, HIGH); delay(100); digitalwrite(led2, LOW); delay(100); No Real-Time No Periodic Activities void func2() { <instructions here> yield(); // Pass control to other tasks. No Preemption 17

Other Solutions: Existing Solutions Arduino Simple Task Scheduler; Looper; WrapOS; 18

Existing Solutions scheduler.createschedule(7*20*4, -1, false, put_leds_into_cycle); uint32_t pid = scheduler.createschedule(50, -1, false, void callback_function); Main(void) // entry point scheduler.beginprofiling(pid); { scheduler.stopprofiling(pid); SEM_ID sem1; scheduler.clearprofilingdata(pid); MSGQ_ID msgq1; char * temp = dumpprofilingdata(void); if (temp!= NULL) { Serial.println(temp); free(temp); /* Fires callback_function() after 790ms, and then cleans itself up. */ scheduler.createschedule(790, 0, true, callback_function); void task1(void) { /* Blinks an LED for (20*9)ms. */ scheduler.createschedule(20, 9, true, toggle_led); semcreate(sem1); // initial it. msgqcreate(msgq1, 100, 10); // create and start tasks. taskcreate("task1", 240, 0x7fff, (FUNCPTR)task1); taskcreate("task2", 250, 0x7fff, (FUNCPTR)task2); while (!done) { // main loop semtake(sem1, 10); // wait for the semaphore /* Makes a 500Hz beep that lasts for 0.5 seconds. */ scheduler.createschedule(1, 1000, true, toggle_speaker_pin); // Do task1 stuff here void put_leds_into_cycle() { // Pulse all the LEDs in sequence... scheduler.createschedule(20, 7, true, toggle_02_oclock_led_r); scheduler.delayschedule(scheduler.createschedule(20, void 7, task2(void) true, toggle_04_oclock_led_r), 7*20); { scheduler.delayschedule(scheduler.createschedule(20, while(!done) 7, true, { // main loop toggle_08_oclock_led_r), 7*20*2); // wait for a message to come. scheduler.delayschedule(scheduler.createschedule(20, msgqreceive(msgq1, 7, true, buf, size, WAIT_FOREVER); toggle_10_oclock_led_r), 7*20*3); // Do task2 stuff here. 19

Existing Solutions scheduler.createschedule(7*20*4, -1, false, put_leds_into_cycle); uint32_t pid = scheduler.createschedule(50, -1, false, void callback_function); Main(void) // entry point scheduler.beginprofiling(pid); { scheduler.stopprofiling(pid); SEM_ID sem1; scheduler.clearprofilingdata(pid); MSGQ_ID msgq1; char * temp = dumpprofilingdata(void); if (temp!= NULL) { Serial.println(temp); free(temp); /* Fires callback_function() after 790ms, and then cleans itself up. */ scheduler.createschedule(790, 0, true, callback_function); void task1(void) { /* Blinks an LED for (20*9)ms. */ scheduler.createschedule(20, 9, true, toggle_led); semcreate(sem1); // initial it. msgqcreate(msgq1, 100, 10); // create and start tasks. taskcreate("task1", 240, 0x7fff, (FUNCPTR)task1); taskcreate("task2", 250, 0x7fff, (FUNCPTR)task2); while (!done) { // main loop semtake(sem1, 10); // wait for the semaphore /* Makes a 500Hz beep that lasts for 0.5 seconds. */ scheduler.createschedule(1, 1000, true, toggle_speaker_pin); // Do task1 stuff here void put_leds_into_cycle() { // Pulse all the LEDs in sequence... scheduler.createschedule(20, 7, true, toggle_02_oclock_led_r); scheduler.delayschedule(scheduler.createschedule(20, void 7, task2(void) true, toggle_04_oclock_led_r), 7*20); { scheduler.delayschedule(scheduler.createschedule(20, while(!done) 7, true, { // main loop toggle_08_oclock_led_r), 7*20*2); // wait for a message to come. scheduler.delayschedule(scheduler.createschedule(20, msgqreceive(msgq1, 7, true, buf, size, WAIT_FOREVER); toggle_10_oclock_led_r), 7*20*3); // Do task2 stuff here. 20

ARTE: Arduino Real-Time Extension ARTE 21

ARTE: Arduino Real-Time Extension Support for real-time multitasking and periodic activities; Maintain a very simple programming interface compliant with the Arduino philosophy; Minimum amount of differences with respect to the original Arduino programming model. 22

What is Real-Time Multitasking? Scheduling Algorithm: Rules dictating the task that needs to be executed on the CPU at each time instant 23

What is Real-Time Multitasking? Preemptive & Priority driven scheduling Task have priorities (static); At each time, the highest priority task is executed ; Preemption: the execution of the running task can be interrupted by an higher priority task, and the CPU given to the new task. 24

What is Real-Time Multitasking? Periodic Activities T time Standard Real-time programming model: Periodic activities without explicit delay/suspensions; Be predictable: polling preferred to event reaction. 25

What is Real-Time Multitasking? Periodic Activities T time Typical Real-Time Applications: Sampling sensors and actuating (e.g., control loop, ); Multimedia and transmissions; 26

What is Real-Time Multitasking? Periodic Activities time Deadline: we want the task finishing before the next activation. 27

What is Real-Time Multitasking? Preemption 1) 2) 3) 28

Real-Time Multitasking and Arduino Idea: Exploit the power of Real-Time Multitasking with the simple and effective Arduino Programming Model; Extension to the Arduino Framework allowing concurrent, multiple, loops each one scheduled with a Real-Time OS 29

Erika Enterprise ERIKA Enterprise is an OSEK/VDX certified RTOS; ERIKA Enterprise implements an API inspired by the AUTOSAR OS API; Offers a suitable open-source license allowing the static linking of closed source code; Typical footprint around 2-4KB Flash; Used by several automotive/white goods companies. 30

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 int led1 = 13; int led2 = 14; int led3 = 15; int count = 0; void loop() { if (count%3 == 0) digitaltoggle(led1); if (count%7 == 0) digitaltoggle(led2); 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 int led1 = 13; int led2 = 14; int led3 = 15; void loop1(3000) { digitaltoggle(led1); Led1 3s Led2 7s Led2 11s void loop2(7000) { digitaltoggle(led2); void loop3(11000) { digitaltoggle(led3); 33

Example 34

Arduino Real-Time Extension ARTE is a real extension to the Arduino IDE, not an external library! It provides a code pre/post-processor that avoids tiring and error-prone user configurations; Automatic generation of the application configuration and skeleton code; The user is focused on the application logic. 35

Arduino Real-Time Extension ARTE has a real RTOS under the hood 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 ERIKA Enterprise is a static RTOS: All the RTOS configuration (tasks, resources, counters, hardware configuration) is decided at compiling time; Minimal impact on the RAM; OIL language is used to configure the RTOS. 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 Arduino build process as ERIKA application Link all together! 42

Build Process Flashing of the binary on the Arduino board 43

DEMO 44

Arduino Real-Time Extension Additional possible usage: Fast prototyping: an ERIKA application is automatically generated from the sketch; it can be used for extending the development by directly working with the RTOS. 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 alessandro.biondi@sssup.it Pasquale Buonocunto p.buonocunto@sssup.it 47