Co-routine - 2006. 12. 22. - YoonMo, Yeon. Co-routine generalize subroutines multiple entry points suspending and resuming of execution at certain locations.

Slides:



Advertisements
Similar presentations
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Advertisements

LCS Non-Dynamic Version int function lcs (x, y, i, j) begin if (i = 0) or (j = 0) return 0; else if (x[i] = y[j]) return lcs(x, y, i-1, j-1)+1; else return.
Real-Time Library: RTX
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
FreeRTOS.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
C++ Basics Variables, Identifiers, Assignments, Input/Output.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
Structure of a C program
Operating Systems Lecture # 3. Recap Hardware Operating System Application System Call Trap Hardware Trap Processor.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
MicroC/OS-II Embedded Systems Design and Implementation.
ISBN Chapter 9 Subprograms and Functions –Design Issues –Local Referencing Environments –Parameter-Passing Methods –Parameters that are Subprogram.
FreeRTOS.
Programming Introduction to C++.
© 2003 G. Drew Kessler and William M. Pottenger1 Subroutines (Part 1) CSE 262, Spring 2003.
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
ACE Address Configuration Executive. Why ACE? ACE provides access to several address resolution protocols under a single API ACE is the only API available.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Functions, Pointers, Structures Keerthi Nelaturu.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
FreeRTOS.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
The Cn Language over view The Cn language strongly on ANSI C. So if you are familiar with ANCI it is not so tough to deal with Cn language. Basic Data.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
MicroC/OS-II S O T R.  MicroC/OS-II (commonly termed as µC/OS- II or uC/OS-II), is the acronym for Micro-Controller Operating Systems Version 2.  It.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
ISBN Chapter 9 Subprograms. Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
Assembly Language Co-Routines
1 Round Robin Non-Preemptive Scheduler Lecture 12.
Task Management 김백규. Task states(1/2)  Running  currently utilising the processor.  Ready  tasks are those that are able to execute.  they are not.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
RTOS Implementation Yeon YoonMo.
Functions, Scope & File IO C++ Lecture 4 Bhaskar Bhattacharya.
LPC2148's RTOS Bruce Chhuon 4/10/07. What is a Real Time Operating System? ● A Real Time Operating System (RTOS) manages hardware and software resources.
Introduction In this lab , we will learn
C++ Lesson 1.
Programming with ANSI C ++
CS4101 嵌入式系統概論 Real-Time Operating System
Round Robin Non-Preemptive Scheduler
CS4101 嵌入式系統概論 Tasks and Scheduling
10.2 Implementation and Execution of Recursive Code
Introduction to C Programming Language
Mr. Shaikh Amjad R. Asst. Prof in Dept. of Computer Sci. Mrs. K. S
CMSC 104, Section 4 Richard Chang
CSCI 3370: Principles of Programming Languages Chapter 9 Subprograms
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
פרטים נוספים בסילבוס של הקורס
Conditional Statements
פרטים נוספים בסילבוס של הקורס
Multithreading.
Govt. Polytechnic,Dhangar
Variables, Identifiers, Assignments, Input/Output
Variables in C Topics Naming Variables Declaring Variables
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
SystemVerilog for Verification
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Introduction to C++.
Programming Language C Language.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
Presentation transcript:

Co-routine YoonMo, Yeon

Co-routine generalize subroutines multiple entry points suspending and resuming of execution at certain locations more generic and flexible than subroutines less widely used in practice recently added to FreeRTOS v4.0.0

State of co-routine Running Ready Blocked crDELAY()

Priority of co-routine min : 0 max : ( configMAX_CO_ROUTINE_PRIORITIES -1 ) defined within FreeRTOSConfig.h tasktask is always prior to co-routine

Implementation void vACoRoutineFunction( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { crSTART( xHandle ); for( ;; ) { -- co-routine application code here. -- } crEND(); }

CRCB (co-routine control block) typedef struct corCoRoutineControlBlock { crCOROUTINE_CODE pxCoRoutineFunction; xListItem xGenericListItem; xListItem xEventListItem; unsigned portBASE_TYPE uxPriority; unsigned portBASE_TYPE uxIndex; unsigned portSHORT uxState; } corCRCB;

crSTART() and crEND() #define crSTART( pxCRCB ) switch( ( ( corCRCB * )pxCRCB )->uxState ) { case 0: #define crEND() }

lists for co-routine static xList pxReadyCoRoutineLists [ configMAX_CO_ROUTINE_PRIORITIES ] ; static xList xDelayedCoRoutineList1 ; static xList xDelayedCoRoutineList2 ; static xList * pxDelayedCoRoutineList ; static xList * pxOverflowDelayedCoRoutineList; static xList xPendingReadyList ;

xCoRoutineCreate()

xCoRoutineCreate() cont.

Scheduling of co-routine call vCoRoutineSchedule() repeatedly best within the idle task hook void vApplicationIdleHook( void ) { vCoRoutineSchedule( void ); }

vCoRoutineSchedule()

Limitations and Restrictions Sharing a stack variables must be declared as ‘static’ void vACoRoutineFunction( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { static char c = 'a'; crSTART( xHandle ); for( ;; ) { c = 'b'; crDELAY( xHandle, 10 ); } crEND(); }

Limitations and Restrictions Sharing a stack (more) calls to API functions that could cause the co-routine to block can only be made from the co-routine function itself void vACoRoutineFunction( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { crSTART( xHandle ); for( ;; ) { crDELAY( xHandle, 10 ); vACalledFunction(); } crEND(); } void vACalledFunction( void ) { // Cannot make a blocking call here! }

Limitations and Restrictions Use of switch statements FreeRTOS does not permit a blocking call to be made from within a ‘switch’ statement void vACoRoutineFunction( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { crSTART( xHandle ); for( ;; ) { crDELAY( xHandle, 10 ); switch( aVariable ) { case 1 : break; default: } crEND(); }

Example #include "task.h" #include "croutine.h" #define PRIORITY_0 0 #define NUM_COROUTINES 8 void main( void ) { int i; for( i = 0; i < NUM_COROUTINES; i++ ) { xCoRoutineCreate( vFlashCoRoutine, PRIORITY_0, i ); } vTaskStartScheduler(); }

Example (cont.) const int iFlashRates[ NUM_COROUTINES ] = { 10, 20, 30, 40, 50, 60, 70, 80 }; const int iLEDToFlash[ NUM_COROUTINES ] = { 0, 1, 2, 3, 4, 5, 6, 7 }; void vFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { crSTART( xHandle ); for( ;; ) { crDELAY( xHandle, iFlashRate[ uxIndex ] ); vParTestToggleLED( iLEDToFlash[ uxIndex ] ); } crEND(); }

co-routine API xCoRoutineHandle xCoRoutineCreate crDELAY crQUEUE_SEND crQUEUE_SEND_FROM_ISR crQUEUE_RECEIVE_FROM_ISR vCoRoutineSchedule

xCoRoutineHandle Type by which co-routines are referenced

crDELAY macro delay co-routine by number of ticks