RIOS: A Lightweight Task Scheduler for Embedded Systems



Similar documents
RIOS: A Lightweight Task Scheduler for Embedded Systems

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

Keil C51 Cross Compiler

MPLAB Harmony System Service Libraries Help

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

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

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

Manchester Coding Basics. Application Note. Manchester Coding Basics. 1. Modulation

Help on the Embedded Software Block

MQX Lite Real-Time Operating System User Guide

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

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

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

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Operating System Manual. Realtime Communication System for netx. Kernel API Function Reference.

Lecture Outline Overview of real-time scheduling algorithms Outline relative strengths, weaknesses

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers. 8-bit Atmel Microcontrollers. Application Note.

the high-performance embedded kernel User Guide Version 5.0 Express Logic, Inc Toll Free 888.THREADX FAX

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

C++FA 5.1 PRACTICE MID-TERM EXAM

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

Linux Load Balancing

Priority Based Implementation in Pintos

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Lecture 3 Theoretical Foundations of RTOS

APPLICATION NOTE. Atmel AT02607: Wireless Product Development Using Atmel Studio and ASF. Atmel MCU Wireless. Description.

8-bit Microcontroller. Application Note. AVR286: LIN Firmware Base for LIN/UART Controller. LIN Features. 1. Atmel LIN/UART Controller

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

J a v a Quiz (Unit 3, Test 0 Practice)

NSPK Protocol Security Model Checking System Builder

Lesson-16: Real time clock DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK

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

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

TivaWare Utilities Library

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Fast Arithmetic Coding (FastAC) Implementations

Data Transfer between Serial Link and TCP/IP Link Using ez80f91 MCU

ELEG3924 Microprocessor Ch.7 Programming In C

Stacks. Linear data structures

Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

RTOS Program Models Used in Embedded Systems

UM1734 User manual. STM32Cube USB device library. Introduction

Pemrograman Dasar. Basic Elements Of Java

Jorix kernel: real-time scheduling

Linux scheduler history. We will be talking about the O(1) scheduler

Comparison between scheduling algorithms in RTLinux and VxWorks

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Operating Systems. III. Scheduling.

USING THE FREERTOS REAL TIME KERNEL

Real- Time Scheduling

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16

Operating Systems. Privileged Instructions

CPU Scheduling. Basic Concepts. Basic Concepts (2) Basic Concepts Scheduling Criteria Scheduling Algorithms Batch systems Interactive systems

CPU Scheduling Outline

Atmel AVR4950: ASF - USB Host Stack. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

LAB 5: Scheduling Algorithms for Embedded Systems

Real Time Operating Systems. Tajana Simunic Rosing Department of Computer Science and Engineering University of California, San Diego.

Scheduling and Thread Management with RTEMS

TLM-2.0 in Action: An Example-based Approach to Transaction-level Modeling and the New World of Model Interoperability

C++FA 3.1 OPTIMIZING C++

Freescale Semiconductor, I

Project 11: FreeRTOS TM Real-Time Control of a Stepper Motor

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Linux Scheduler. Linux Scheduler

Getting Started. Building Applications with RL-ARM. For ARM Processor-Based Microcontrollers.

Application Note: AN00141 xcore-xa - Application Development

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

MeshBee Open Source ZigBee RF Module CookBook

Interfacing an HTML Form to the ez80f91 MCU

Using the TASKING Software Platform for AURIX

An Introduction to MPLAB Integrated Development Environment

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

On Demand Loading of Code in MMUless Embedded System

Linux O(1) CPU Scheduler. Amit Gud amit (dot) gud (at) veritas (dot) com

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

Using Protothreads for Sensor Node Programming

Chapter 5 Process Scheduling

Field Software Updates Using TPMS LF An example using the Low Frequency radio (LFR) for wireless software updating

Scheduling 0 : Levels. High level scheduling: Medium level scheduling: Low level scheduling

AVR Butterfly Training. Atmel Norway, AVR Applications Group

Performance Comparison of RTOS

Object Oriented Software Design

Real Time Operating Systems. Tajana Simunic Rosing Department of Computer Science and Engineering University of California, San Diego.

Job Scheduling Model

CSC230 Getting Starting in C. Tyler Bletsch

USER GUIDE. AVR2050: BitCloud Developer Guide. Atmel MCU Wireless. Description. Features

What is COM/DCOM. Distributed Object Systems 4 COM/DCOM. COM vs Corba 1. COM vs. Corba 2. Multiple inheritance vs multiple interfaces

Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

CS 241 Data Organization Coding Standards

Binary storage of graphs and related data

Transcription:

RIOS: A Lightweight Task Scheduler for Embedded Systems Bailey Miller*, Frank Vahid*, Tony Givargis *Dept. Computer Science & Engineering University of California, Riverside {chuang,bmiller,vahid@cs.ucr.edu Center for Embedded Computer Systems University of California, Irvine givargis@uci.edu This work was supported in part by a U.S. Department of Education GAANN fellowship. 1/15

RIOS: Riverside-Irvine Operating System Task scheduler for embedded systems education Developed and used at UCR. 10+ classes at UCR, UCI, other universities. Why? Size Application Programming Interface (API) Complexity Details hidden from students 1000s of lines-of-code; multiple files; complex RTOS API RTOS RIOS 2/15

RIOS: Riverside-Irvine Operating System Minimal code Nonpreemptivescheduler: 12 lines-of-code Preemptive scheduler: ~20 lines-of-code Cooperative tasks Run-to-completion tasks Supports synch-sm programming model void TimerISR(){ RIOS Non-preemptive unsigned chari; if (processingrdytasks) { printf("timerticked before task processing done.\n"); else {// Heart of the scheduler code processingrdytasks= 1; for (i=0; i < tasksnum; ++i) { if (tasks[i].elapsedtime >= tasks[i].period) {// Ready tasks[i].state = tasks[i].tickfct(tasks[i].state); //execute task tick tasks[i].elapsedtime= 0; tasks[i].elapsedtime+= tasksperiodgcd; processingrdytasks= 0; Transparent Single stack Understandable RIOS 3/15

Context for teaching RIOS Progressive methodology 1. Coding in C review (1 week) 2. Capturing behavior with Synch-SMs (2 weeks) 3. Synch-SMs and timing with C code (1 week) 4. Introduce more complexity (multi synch-sm) (2 weeks) 5. Scheduling (3 weeks) Simple round-robin Priority-based scheduling of tasks with the same period RIOS cooperative, nonpreemptive priority-based scheduling Synch-SM template C code Round robin Single-period tasks RIOS Capturing simple behavior as synch-sms Multiple synch-sms Scheduling Simple (Round robin) Priority-based scheduling RIOS 4/15

Context for teaching RIOS Riverside-Irvine Microcontroller Simulator (RIMS) State machine builder (RIBS) RIBS C code RIMS RIOS Design sync-sms and generate C using RIBS RIMS executes generated C code http://www.youtube.com/watch?v=m0f3x4ogssw 5/15

RIOS: Non-preemptive priority-based scheduling (simple tasks) Task struct typedef struct task { unsigned long period; // Rate at which the task should tick unsigned long elapsedtime; // Time since task's last tick void (*TickFct)(void); // Function to call for task's tick task; int tasksnum = 0; task tasks[0]; Nonpreemptive Timer initialization unsigned char tasksperiodgcd = 0; unsigned char processingrdytasks = 0; void TimerISR() { unsigned char i; if (processingrdytasks) { printf("timer ticked before task processing done.\n"); else { // Heart of the scheduler code processingrdytasks = 1; for (i=0; i < tasksnum; ++i) { if (tasks[i].elapsedtime >= tasks[i].period) { // Ready tasks[i].tickfct(); //execute task tick tasks[i].elapsedtime = 0; tasks[i].elapsedtime += tasksperiodgcd; processingrdytasks = 0; Check if tasks are ready void main() { TimerSet(tasksPeriodGCD); // TimerISR activates at GCD of tasks TimerOn(); // Enable the timer Execute task tick 6/15 while(1) { Sleep();

RIOS: Non-preemptive priority-based scheduling (simple tasks) // Task: Toggle an output void TickFct_Toggle() { static unsigned char init = 1; if (init) { // Init behavior B0 = 0; init = 0; else { // Normal behavior B0 =!B0; Period=1000 // Task: Strobe a 1 across 3 outputs void TickFct_Sequence() { static unsigned char init = 1; unsigned char tmp = 0; if (init) { // Initialization behavior B2 = 1; B3 = 0; B4 = 0; init = 0; else { // Normal behavior tmp = B4; B4 = B3; B3 = B2; B2 = tmp; Period=200 http://www.youtube.com/watch?v=dscituvl6kk 7/15

RIOS: preemptive priority-based scheduling Scheduled tasks Period=1000 Delay = 500 ms Low priority Add task unsigned char runningtasks[3] = {255;//Track running tasks-[0] always idletask const unsigned long idletask = 255; // 0 highest priority, 255 lowest unsigned char currenttask = 0; //Index of highest priority task in runningtasks Platform-specific void TimerISR() { unsigned char i; context switch SaveContext(); //save temporary registers, if necessary for (i=0; i < tasksnum; ++i) { // Heart of scheduler code if ( (tasks[i].elapsedtime >= tasks[i].period) // Task ready && (runningtasks[currenttask] > i) // priority > current priority && (!tasks[i].running)) { // Task not running (no self-preemption) DisableInterrupts(); // Critical section tasks[i].elapsedtime = 0; // Reset time since last tick tasks[i].running = 1; // Mark as running currenttask += 1; runningtasks[currenttask] = i; // Add to runningtasks EnableInterrupts(); // End critical section tasks[i].tickfct(); // Execute tick Execute task Period=200 Delay = 25 ms High priority Remove task DisableInterrupts(); // Critical section tasks[i].running = 0; runningtasks[currenttask] = idletask; // Remove from runningtasks currenttask -= 1; EnableInterrupts(); // End critical section tasks[i].elapsedtime += tasksperiodgcd; RestoreContext(); 8/15

RIOS: preemptive priority-based scheduling (Synch-SMs) RunningTasks currenttask 1000 ms period 500 ms delay Low priority stack 200 ms period 25 ms delays High priority ISR ISR ISR Main() ISR 200 400 600 Time (ms) 9/15

RIOS: preemptive priority-based scheduling (Synch-SMs) 10/15

RIOS: Non-preemptive priority-based scheduling (Synch-SMs) TG_s1 _s3 _s1 _s2 typedef struct task { unsigned long period;// Rate at which the task should tick unsigned long elapsedtime; // Time since task's last tick int state; // state of task void (*TickFct)(void); // Function to call for task's tick task; enum _States { _s1, _s2, _s3 ; int TickFct_Sequence(int state) { switch(state) { // Transitions case -1: // Initial transition state = _s1; break; case _s1: state = _s2; break; case _s2: state = _s3; break; case _s3: state = _s1; break; default: state = -1; switch(state) { // State actions case _s1: B2 = 1; B3 = 0; B4 = 0; break; case _s2: B2 = 0; B3 = 1; B4 = 0; break; case _s3: B2 = 0; B3 = 0; B4 = 1; break; default: break; return state; 11/15 Next state Current state transitions actions void TimerISR() { unsigned char i; if (processingrdytasks) { printf("timer ticked before task processing done.\n"); else { // Heart of the scheduler code processingrdytasks = 1; for (i=0; i < tasksnum; ++i) { if (tasks[i].elapsedtime >= tasks[i].period) { tasks[i].state = tasks[i].tickfct(tasks[i].state); tasks[i].elapsedtime = 0; tasks[i].elapsedtime += tasksperiodgcd; processingrdytasks = 0; void main() { // Task initialization // while(1) { Sleep(); Update task state RIOS

RIOS requirements Required functions void TimerOn() void TimerSet(int ms) void TimerISR() Portable AVR microcontroller void TimerOn(){ TCCR1B = (1<<WGM12) (1<<CS12); //Clear timer on compare. TIMSK1 = (1<<OCIE1A); //Enables compare match interrupt SREG = 0x80; //Enable global interrupts void TimerSet(intmilliseconds){ TCNT1 = 0; OCR1A = milliseconds*ticks_per_ms; void TimerISR(){ // RIOS scheduler code ISR(TIMER1_COMPA_vect){ // Timer compare match ISR TimerISR(); Target platform must have timer with periodic interrupts RIOS uc 12/15

Comparison to RTOSs Sample application of 3 task program All implemented on AVR ATMega324P overhead (us) Overhead for 10 seconds of execution Sample application binary size Sample application binary size 5000 4000 3000 2000 1000 3.3X less overhead 3.5X smaller executable Only 116 lines of code Size (bytes) 4000 3000 2000 1000 0 0 0 RIOS FreeRTOS AtomThreads RIOS FreeRTOS AtomThreads RIOS FreeRTOS AtomThreads Scheduler Scheduler Scheduler Size (bytes) 5000 4000 3000 2000 1000 13/15

Observations Condensed summer class (5 weeks total). 8 days to complete final projects. http://www.youtube.com/watch?v=vkcyba6kxng Average of 5 concurrent tasks, scheduled with RIOS 14/15

Conclusion Minimaltask scheduler suitable for most embedded applications using cooperative tasks Small code size Understandable by students Portable Code / examples available from http://www.riosscheduler.org void TimerISR(){ RIOS Non-preemptive unsigned chari; if (processingrdytasks) { printf("timerticked before task processing done.\n"); else {// Heart of the scheduler code processingrdytasks= 1; for (i=0; i < tasksnum; ++i) { if (tasks[i].elapsedtime >= tasks[i].period) {// Ready tasks[i].state = tasks[i].tickfct(tasks[i].state); //execute task tick tasks[i].elapsedtime= 0; tasks[i].elapsedtime+= tasksperiodgcd; processingrdytasks= 0; 15/15