AN HONORS UNIVERSITY IN MARYLAND UMBC. AvrX. Yousef Ebrahimi Professor Ryan Robucci

Similar documents
FreeRTOS. A Brief Overview. Christopher Kenna. October 1, Avionics. FreeRTOS 1 / 34

Context Switching & Task Scheduling

Use a semaphore to avoid the enqueue and dequeue functions from accessing and modifying count variable at the same time.

real-time kernel documentation

FreeRTOS. A Brief Overview. Christopher Kenna. October 1, Avionics. FreeRTOS 1 / 34

Software debouncing of buttons


Unit 13 Timers and Counters

embos Real Time Operating System CPU & Compiler specifics for RENESAS M16C CPUs and IAR compiler Document Rev. 5

Real-Time Programming

Unit 14 Timers and Counters 14.1

embos Real Time Operating System CPU & Compiler specifics for ARM core with ARM RealView Developer Suite 3.0 Document Rev. 1

GLOSSARY. VisualDSP++ Kernel (VDK) User s Guide B-1

Preemptive Scheduling

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega128 GCC

Interrupts (II) Lecturer: Sri Parameswaran Notes by: Annie Guo

embos Real-Time Operating System CPU & Compiler specifics for embos Visual Studio Simulation

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory

,$5$SSOLFDWLRQ1RWH$95 (IILFLHQWSURJUDPPLQJRI$WPHO V $95 PLFURFRQWUROOHUV

COMP 7860 Embedded Real- Time Systems: Threads

Micrium µc/os II RTOS Introduction EE J. E. Lumpp

Introduction to the ThreadX Debugger Plugin for the IAR Embedded Workbench C-SPYDebugger

Distributed Real-Time Control Systems. Chapter 10 Real-Time Digital Control

Topic 11: Timer ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

Distributed Real- Time Control Systems. Lecture 7 Real- Time Control

Processes. Dr. Yingwu Zhu

Using the FreeRTOS Real Time Kernel

Introduction to Real-Time Operating Systems

3.1 Introduction. Computers perform operations concurrently

IAR PowerPac RTOS for ARM Cores

CSCE 236 Embedded Systems, Spring 2012 Quiz/Test 2

5/11/2012 CMSIS-RTOS. Niall Cooling Feabhas Limited CMSIS. Cortex Microcontroller Software Interface Standard.

Micrium OS Kernel Labs

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

A New Real-time Kernel development on an embedded platform

Fundamental concept in computation Interrupt execution of a program to handle an event

Interrupts and Time. Real-Time Systems, Lecture 5. Martina Maggio 28 January Lund University, Department of Automatic Control

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

Putting it All Together

Designing Responsive and Real-Time Systems

ArdOS The Arduino Operating System Reference Guide Contents

EE 472 Embedded Systems. Name solutions. Instructions:

embos Real Time Operating System CPU & Compiler specifics for RENESAS SH2 CPUs and RENESAS HEW4 Document Rev. 1

Threads Chapter 5 1 Chapter 5

Operating System. Hanyang University. Hyunmin Yoon Operating System Hanyang University

BASICS OF THE RENESAS SYNERGY TM

School of Electrical, Computer and Telecommunications Engineering University of Wollongong Australia

EE 308: Microcontrollers

INTERRUPTS in microprocessor systems

Marten van Dijk, Syed Kamran Haider

OPERATING SYSTEM OVERVIEW

Chapter 9: Virtual-Memory

embos Real-Time Operating System embos plug-in for IAR C-Spy Debugger Document: UM01025 Software Version: 3.0 Revision: 0 Date: September 18, 2017

TIMSK=0b ; /* enables the T/C0 overflow interrupt in the T/C interrupt mask register for */

Lab 8 Real-time OS - 1

Page Replacement. 3/9/07 CSE 30341: Operating Systems Principles

Multitasking. Embedded Systems

CSC369 Lecture 2. Larry Zhang

EECS 482 Introduction to Operating Systems

onetesla Interrupter Firmware Guide General Overview

CSCE374 Robotics Fall 2013 Notes on the irobot Create

Interrupts. How can we synchronize with a peripheral? Polling

In Class Assignment 2

Embedding OS in AVR microcontrollers. Prof. Prabhat Ranjan DA-IICT, Gandhinagar

Lecture 3: Concurrency & Tasking

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega IAR

Interrupts and Time. Interrupts. Content. Real-Time Systems, Lecture 5. External Communication. Interrupts. Interrupts

Physics 120B: Lecture 11. Timers and Scheduled Interrupts

CS370 Operating Systems

embos Real Time Operating System CPU & Compiler specifics for Texas Instruments MSP430 CPUs and Rowley compiler for MSP430 Document Rev.

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Using the FreeRTOS Real Time Kernel

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Computer Systems Assignment 2: Fork and Threads Package

FreeRTOS X. Task Notifications Semaphores Family Critical Section FreeRTOS Producer Consumer Tasks

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Exam TI2720-C/TI2725-C Embedded Software

Microprocessors & Interfacing

embos Real-Time Operating System CPU & Compiler specifics for Renesas RH850 and IAR

Embedded System Curriculum

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

embos Real Time Operating System CPU & Compiler specifics for RENESAS M16C CPUs and HEW workbench Document Rev. 1

ArdOS The Arduino Operating System Quick Start Guide and Examples

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

What is a Real Time Operating System?

3. Process Management in xv6

Embedded Software TI2726 B. 7. Embedded software design. Koen Langendoen. Embedded Software Group

Introduction to Embedded Systems

Process Coordination and Shared Data

embos Real-Time Operating System embos plug-in for IAR C-Spy Debugger Document: UM01025 Software Version: 3.1 Revision: 0 Date: May 3, 2018

CS533 Concepts of Operating Systems. Jonathan Walpole

What we will learn. Threaded Systems: Threads. Threads. Threads. Bag of functions & procedures ST OS. AUCs. Threads. AUCs. Processes MT OS MP OS

EE458 - Embedded Systems Exceptions and Interrupts

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

INTERRUPT MANAGEMENT An interrupt is a hardware mechanism used to service an event that can be external or internal to

Corso di Elettronica dei Sistemi Programmabili

EECS 482 Introduction to Operating Systems

Embedded Real-Time Systems

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega128 IAR

Transcription:

AvrX https://github.com/kororos/avrx Yousef Ebrahimi Professor Ryan Robucci

Introduction AvrX is a Real Time Multitasking Kernel written for the Atmel AVR series of micro controllers. The Kernel is written in assembly. Total kernel size varies from ~500 to 700 words depending upon which version is being used. Since the kernel is provided as a library of routines, practical applications take up less space because not all functions are used. AvrX (RTOS) maintains state information for the programmer. Instead of a complicated state machine for each task, running off an interrupt timer, the designer can write linear code (do this, wait for something, then do that... etc). In general the linear code is much easier to design, debug, understand and it is almost always smaller.

Versions There are two versions of AvrX available: AvrX v2.3 for the IAR assembler. This is a tiny version that is suitable for Assembly programming only. It makes very efficient use of RAM and takes very few cycles to service interrupts. AvrX 2.6 for the IAR Systems and GCC C compiler. This version of AvrX is written for a small memory model (16 bit pointers) and a native C interface. The code size is larger than the 2.3 version (~700 words vs. 500) and all registers need to be swapped with each context change, so it is somewhat slower and uses more SRAM. As for speed, processing a system timer tick took 211 cycles in AvrX 2.3 but takes 234 in AvrX 2.6

OS Interrupt / System Tick To do scheduling, a HARDWARE timer with an interrupt is needed! Can also use it to allow having software timers. One of the available hardware timers can be used to cause an interrupt as the base timer for the AvrX RTOS. To choose the hardware timer, its tick rate and more we need to modify avrx_hardware_custom.h header file I have changed the header file to use Timer2 Its tick rate will be 1 millisecond Add following code to have the timer setup AVRX_SIGINT(AVRX_HARDWARE_TIMER_SIGNAL){ IntProlog(); // Switch to kernel stack/context AvrXTimerHandler(); // Call Time queue manager Epilog(); // Return to tasks

Structure of Interrupt Handler AvrX completely handles the saving and restoring of the interrupted context AVRX_SIGINT(INTERRUPT_NAME){ IntProlog(); ///handling code Epilog(); Get the INTERRUPT_NAME from avrx\avrx-signal.h file

System Tick setup In main you need to run following macro AVRX_HARDWARE_SETUP_COMMANDS; Macro has been defined at avrx_hardware_custom.h It simply sets the registers for Timer2 to generate the interrupt every 1ms --- ISR in previous slide IntProlog(): Pushes entire register context onto the stack, returning a frame pointer to the saved context. Usage: Internal use of AvrX and ISRs. Epilog(): Restore previous context (kernel or user). Usage: Internal use of AvrX and ISRs. AvrXTimerHandler(): internal function from AvrX to handle the scheduling of tasks/setting timers and

Toggling LED using Timer1 #include <avr/io.h> #include "avrx.h" #include "avrx_hardware_custom.h" AVRX_SIGINT(AVRX_HARDWARE_TIMER_SIGNAL){ -- system tick IntProlog(); // Switch to kernel stack/context AvrXTimerHandler(); // Call Time queue manager Epilog(); // Return to tasks void setuptimer1() { TCCR1B = 0b100; //select prescaler TCCR1B = (1<<WGM12); TCCR1A = 0; //set to CTC mode //Setting the compare match value OCR1A = 15625 ; // OCR1AH = 15625 >> 8; OCR1AL = 15265; TIMSK1 = 2; //only set interrupt for compare match on A

Toggling LED Cont d AVRX_SIGINT(SIG_OUTPUT_COMPARE1A){ //ISR IntProlog(); PORTB ^=(0x02); Epilog(); int main(void){ AvrXSetKernelStack(0); //next slide AVRX_HARDWARE_SETUP_COMMANDS; //setups system Timer setuptimer1(); DDRB = 0xff; // set PORTB as output Epilog();//starts scheduling of tasks while(1) ; Don t forget to include libavrx.a when building the project

Base of AvrX projects #include <avr/io.h> #include "avrx.h" #include "avrx_hardware_custom.h" AVRX_SIGINT(AVRX_HARDWARE_TIMER_SIGNAL){ // system tick IntProlog(); // Switch to kernel stack/context AvrXTimerHandler();// Call Time queue manager Epilog(); // Return to tasks int main(void){ AvrXSetKernelStack(0); AVRX_HARDWARE_SETUP_COMMANDS; //TODO:: Epilog(); while(1); AvrXSetKernelStack: Sets AvrX Stack to "newstack" or, if NULL then to the current stack.

AvrX Task To define a task (process) [this like applications that OS will schedule and run] start: name of the task c_stack: the additional stack required above the 35 bytes used for the standard context priority: priority of the task (lower value means more important) 16 levels* Example: AVRX_GCC_TASKDEF(start, c_stack, priority) *http://www.barello.net/avrx/overview.htm AVRX_GCC_TASKDEF(firstTask,0,1) { int i = 0; while(1){ ++i; if (i % 1000 == 0){ LED = LED ^ 0x04;

AvrX Task Cont d AvrXRunTask: To initialize and run the task. int main(void){ AvrXSetKernelStack(0); AVRX_HARDWARE_SETUP_COMMANDS; DDRB = 0xff; // set PORTB as output AvrXRunTask(TCB(firstTask)); Epilog(); while(1); TCB : Returns the pointer to the task control block allocated for the passed in task (firsttask).

Adding 2 nd Task Creating 2 nd task -- First task is same as before AVRX_GCC_TASKDEF(Task2,0,1){ int i = 0; while(1){ ++i; if (i % 1000 == 0){ PORTB ^= 0x08; AVRX_GCC_TASKDEF(firstTask,0,1) { Adding following line to main function AvrXRunTask(TCB(firstTask)); AvrXRunTask(TCB(Task2)); In scheduling the task, Higher priority task will take over the CPU and will not release it since we have forever loop!!! Same priority task must cooperate they must yield the CPU to other processes.

Software Timers Having a system tick allows AvrX to support software timers Not as accurate as hardware timers though. OS manages them. TimerControlBlock A structure to handle timer It has 16 bit counter our timers are 16-bit wide Following line defines 2 timers as global variables, TimerControlBlock timer1,timer2; or use macro AVRX_TIMER(timer1); AvrXStartTimer(TimerControlBlock* timecontrolblockptr, unsigned count); non-blocking API timecontrolblockptr : pointer to the timer to start. 2 nd parameter is timeout tick count.

Timer AvrXWaitTimer(&TimerControlBlock); Waits on a timer to expire. This suspends the task and takes it out of ready queue. (allows same/lower priority tasks get the CPU) Fixing Task 1 and 2 AVRX_GCC_TASKDEF(firstTask,4,1){ while(1){ AvrXStartTimer(&timer1, 1000); AvrXWaitTimer(&timer1); PORTB ^= 0x01; AVRX_GCC_TASKDEF(Task2,4,1){ while(1){ AvrXDelay(&timer2, 2000); PORTB ^= 0x08; AvrXDelay(& TimerControlBlock, unsigned); Calls AvrXStartTimer and then AvrXWaitTimer Stack size has increase to 4; Allow at least 2 bytes for level of internal function calls!!

Mutex AvrX supportsgmutex Semaphores. Theygcangbegunlockedgbygagprocessgdifferentgthangthegonegthatg lockedgthem. DefinegagMutex Mutex timeout; OrNuseNmacro AVRX_MUTEX;timeOut); UMBC Waitgforgit: Signalgit: NNNAVRX311_WAIT_P(timeOut); AVRX311_SIGNAL_V(timeOut);

Example AVRX_GCC_TASKDEFhfirstTaskPa=aP^l{ aaaawhileh^l{ aaaaaaaaavrx0^^_wait_phtimeoutl; aaaa PORTB ^= 0x01;aaaa aaaaa AVRX_GCC_TASKDEFhTask0Pa=aPa^l { aaaawhileh^l{ aaaaaaaaavrx0^^_wait_phtimeoutl; aaaaaaaa PORTB ^= 0x10; aaaa AVRX_GCC_TASKDEFhTask=PaxaP^l{ aaaawhileh^l{ aaaaaaaavrxdelayh{timer^p^;;;l; aaa AVRX311_SIGNAL_V(timeOut); AVRX311_SIGNAL_V(timeOut); PORTB ^= 0x08; aaaa UMBC ANtHONORStUNI VERSI TYtI NtM ARYL AND Remove one of the behavior. AVRX0^^_SIGNAL_V Mutex Semaphore is not binary in AvrX and observe the

Creating Tasks Objective action Define a task with code: Declare task data structure and the top level C declaration (AVRX_TASK + C function declaration) Code AVRX_TASKDEF(start, stacksz, priority) UMBC Declare a task: Declare task data structures and forward reference to task Declare external task: Declare external task data structures AVRX_TASK(start, stacksz, priority) AVRX_EXTERNTASK(start)

Basic Task Control Assume taskxyz declared with AVRX_GCC_TASKDEF(taskXYZ, Objective action Run/Start a task Terminate a Task Code AvrXRunTask(TCB(taskXYZ)); AvrXTerminate(PID(taskXYZ)); UMBC Suspend a task Resume a task Cause task itself to give up CPU to next ready task Cause task itself terminate AvrXSuspend(PID(taskXYZ)); AvrXResume(PID(taskXYZ)); AvrXYield(); or any wait like AVRXDelay(&timerXYZ, 1); Use AVRXDelay if any problems found with AvrXYield AvrXTaskExit(void);

CSEE CMPE 311 Yousef Ebrahimi UMBC Interrupt Handler AvrX has its own API for creating interrupt handlers Objective action Declare the top level C declaration for an interrupt handler Code AVRX_SIGINT(vector); 19

Task Referencing Assume taskxyz declared with AVRX_GCC_TASKDEF(taskXYZ, Objective action Get pointer to task s PID Get pointer to task s TCB Get pointer to task s own PID Code PID(taskXYZ); TCB(taskXYZ); AvrXSelf();