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

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

Corso di Elettronica dei Sistemi Programmabili

FreeRTOS. Gary J. Minden October 19, 2017

Context Switching & Task Scheduling

Free-RTOS Implementation

Corso di Elettronica dei Sistemi Programmabili

An Analysis and Description of the Inner Workings of the FreeRTOS Kernel

Using the FreeRTOS Real Time Kernel ARM Cortex-M3 Edition

Using the FreeRTOS Real Time Kernel

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

Content. Task management Task communication Message queues Task synchronization Binary semaphores Counting semaphores Mutexes

Using the FreeRTOS Real Time Kernel

SAFERTOS. User s Manual

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

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

FreeRTOS. Alberto Bosio. February 27, Université de Montpellier Alberto Bosio (UM) FreeRTOS February 27, / 52

real-time kernel documentation

Real-Time Programming

FreeRTOS - Common Task Design Patterns in Multi-tasking Applications

Contents. List of Figures... vi. List of Code Listings... viii. List of Tables... xi. List of Notation... xii

Introduction to Real-Time Operating Systems

Atmel AT13723:Getting Started with FreeRTOS on Atmel SAMV/S/E MCUs. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

VORAGO VA108xx FreeRTOS port application note

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

Refinement-based Verification of FreeRTOS in VCC 1

Lesson FreeRTOS + LPC17xx. FreeRTOS & Tasks LPC17xx Memory Map Lab Assignment: FreeRTOS Tasks

Software Development with an Open Source RTOS

ADAPTING MODE SWITCHES INTO THE HIERARCHICAL SCHEDULING DANIEL SANCHEZ VILLALBA

EE 472 Embedded Systems. Name solutions. Instructions:

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

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

COMP 7860 Embedded Real- Time Systems: Threads

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

ArdOS The Arduino Operating System Reference Guide Contents

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

Queue Management. LS 12, TU Dortmund

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

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

Timers 1 / 46. Jiffies. Potent and Evil Magic

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document C28X CCS

MCUXpresso IDE FreeRTOS Debug Guide. Rev November, 2017

Lecture 3: Concurrency & Tasking

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document AVR32A GCC

AUTOBEST: A United AUTOSAR-OS And ARINC 653 Kernel. Alexander Züpke, Marc Bommert, Daniel Lohmann

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

Tasks. Task Implementation and management

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

EE458 - Embedded Systems Lecture 8 Semaphores

Embedded Systems - FS 2018

RTOS Real T i Time me Operating System System Concepts Part 2

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ARM Cortex-M3 CCS

EECS 473 Advanced Embedded Systems

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

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

Zilog Real-Time Kernel

Multitasking. Embedded Systems

Lecture 3. Introduction to Real-Time kernels. Real-Time Systems

THREADS ADMINISTRIVIA RECAP ALTERNATIVE 2 EXERCISES PAPER READING MICHAEL ROITZSCH 2

Exam TI2720-C/TI2725-C Embedded Software

Mutex Implementation

Interrupt/Timer/DMA 1

The components in the middle are core and the components on the outside are optional.

Short Term Courses (Including Project Work)

Xinu on the Transputer

FreeRTOS and LPC Microcontrollers. Richard Barry Design West, San Jose, 2013


Embedded System Curriculum

Nios II. uc/os-ii porting with Nios II Altera Corporation

ERIKA Enterprise Minimal API Manual....multithreading on a thumb!

RT3 - FreeRTOS Real Time Programming

Process Coordination and Shared Data

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Module 1. Introduction:

EECS 473 Advanced Embedded Systems

CS 326: Operating Systems. CPU Scheduling. Lecture 6

EE458 - Embedded Systems Exceptions and Interrupts

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

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document MSP430/X CCS

Process Monitoring in Operating System Linux

Processes and Non-Preemptive Scheduling. Otto J. Anshus

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

Designing Responsive and Real-Time Systems

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

Reference Model and Scheduling Policies for Real-Time Systems

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Concurrency: Deadlock and Starvation

Real Time Operating System: Inter-Process Communication (IPC)

805xRTOS. Generated by Doxygen 1.6.3

Embedded Systems Programming - PA8001

V. 2. ( Copyright 2004, 2006 Yuri Tiomkin

2. Introduction to Software for Embedded Systems

Concurrent Programming. Implementation Alternatives. Content. Real-Time Systems, Lecture 2. Historical Implementation Alternatives.

Concurrent Programming

AVR Subroutine Basics

Deterministic Futexes Revisited

Systemy RT i embedded Wykład 11 Systemy RTOS

Multirate Feedback Control Using the TINYREALTIME Kernel

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

A New Real-time Kernel development on an embedded platform

FreeRTOS Kernel: Reference Manual

Transcription:

A Brief Overview Christopher Kenna Avionics October 1, 2010 1 / 34

Introduction Outline 1 Introduction About Kernel Overview 2 Tasks Tasks versus Co-Routines Task Details 3 IPC and Synchronization Queues Semaphores and Mutexes 4 Scheduler Scheduler Background Scheduler Code 2 / 34

Introduction About Background Information The Project supports 25 official architecture ports, with many more community developed ports. The RT kernel is portable, open source, royalty free, and very small. OpenRTOS is a commercialized version by the sister company High Integrity Systems. Richard Barry: I know has been used in some rockets and other aircraft, but nothing too commercial. We have customers that use it on ship systems, and WITTENSTEIN sell SafeRTOS which has been certified to various standards, but not DO-178B. 3 / 34

Introduction About Licensing Information (0/2) The license is a modified GNU GPL according to the table below. Modified GPL OpenRTOS Commercial Free?! # Use it in a commercial application?!! Royalty free?!! Must open source code that makes use of services? # 1 # Must open source kernel changes?! # 1 As long as code provides functionality that is distinct from that provided by. 4 / 34

Introduction About Licensing Information (1/2) The license is a modified GNU GPL according to the table below. Must document that the product uses? Required to offer code to application users? Modified GPL OpenRTOS Commercial! 2 #! # Technical support for OS? # 3! Warranty? #! 2 Web link to.org is sufficient. 3 There is an on-line community, though. 5 / 34

Introduction Kernel Overview Configuration The operation of is governed by.h, with application specific configuration appearing in Confg.h. Obviously, these are static configuration options. Some examples: configuse_preemption configcpu_clock_hz CPU clock frequency, not necessarily the bus frequency. configtick_rate_hz RTOS tick frequency that dictates interrupt frequency. configmax_priorities Total number of priority levels. Each level creates a new list, so memory sensitive machines should keep this to a minimum. And more... 6 / 34

Tasks Outline 1 Introduction About Kernel Overview 2 Tasks Tasks versus Co-Routines Task Details 3 IPC and Synchronization Queues Semaphores and Mutexes 4 Scheduler Scheduler Background Scheduler Code 7 / 34

Tasks Tasks versus Co-Routines Tasks in Tasks have their own context. No dependency on other tasks unless defined. One task executes at a time. Tasks have no knowledge of scheduler activity. The scheduler handles context switching. Thus, tasks each have their own stack upon which execution context can be saved. Prioritized and preemptable. 8 / 34

Tasks Tasks versus Co-Routines Co-Routines Co-routines are intended for use on small processors that have severe RAM constraints. Co-Routines share a single stack. Co-routines are implemented through macros. Prioritized relative to other co-routines, but preempted by tasks. The structure of co-routines is rigid due to the unconventional implementation. Lack of stack requires special consideration. Restrictions on where API calls can be made. Cannot communicate with tasks. Will examine tasks in more detail, but not co-routines. 9 / 34

Tasks Task Details Task States Running Actively executing and using the processor. Ready Able to execute, but not because a task of equal or higher priority is in the Running state. Blocked Waiting for a temporal or external event. E.g., queue and semaphore events, or calling vtaskdelay() to block until delay period has expired. Always have a timeout period, after which the task is unblocked. Suspended Only enter via vtasksuspend(), depart via xtaskresume() API calls. 10 / 34

Tasks Task Details Task Priorities Each task gets a priority from 0 to configmax_priorities 1 Priority can be set on a per application basis. Tasks can change their own priority, as well as the priority of other tasks. tskidle_priority = 0 11 / 34

Tasks Task Details The Idle Task The idle task is created automatically when the scheduler is started. 12 / 34

Tasks Task Details The Idle Task The idle task is created automatically when the scheduler is started. It frees memory allocated by the RTOS to tasks that have since been deleted. Thus, applications that use vtaskdelete() to remove tasks should ensure the idle task is not starved. 12 / 34

Tasks Task Details The Idle Task The idle task is created automatically when the scheduler is started. It frees memory allocated by the RTOS to tasks that have since been deleted. Thus, applications that use vtaskdelete() to remove tasks should ensure the idle task is not starved. The idle task has no other function, so cases when the idle task need never run exist. 12 / 34

Tasks Task Details The Idle Task The idle task is created automatically when the scheduler is started. It frees memory allocated by the RTOS to tasks that have since been deleted. Thus, applications that use vtaskdelete() to remove tasks should ensure the idle task is not starved. The idle task has no other function, so cases when the idle task need never run exist. There is an idle task hook, which can do some work at each idle interval without the RAM usage overhead associated with running a task at the idle priority. 12 / 34

Tasks Task Details Task Control Block (TCB) (0/2) A TCB is allocated to each task. It stores the task s context. Source/tasks.c typedef struct tsktaskcontrolblock { : : Top of task s stack. Must be f i r s t member b/c of context switch volatile portstack_type * pxtopofstack ; : : code ( l a t e r s l i d e s ). # if ( portusing_mpu_wrappers == 1 ) : : The MPU s e t t i n g s a r e d e f i n e d as p a r t o f the p o r t l a y e r. xmpu_settings xmpusettings ; : : Must be 2nd member of s t r u c t. # endif : : L i s t item used to place the TCB i n ready and blocked queues. xlistitem xgenericlistitem ; : : Used to p l a c e the TCB i n event l i s t s. xlistitem xeventlistitem ; : : The p r i o r i t y o f the t a s k where 0 i s the l o w e s t p r i o r i t y. unsigned portbase_type uxpriority ; : : P o i n t s to the s t a r t o f the s t a c k. portstack_type * pxstack ; : : D e s c r i p t i v e name g i v e n to the t a s k when c r e a t e d. : : F a c i l i t a t e s debugging o n l y. signed char pctaskname [ configmax_task_name_len ]; 13 / 34

Source/tasks.c Tasks Task Details Task Control Block (TCB) (1/2) # if ( portstack_growth > 0 ) : : Used f o r s t a c k o v e r f l o w checking on a r c h i t e c t u r e s where the : : stack grows up from low memory. portstack_type * pxendofstack ; # endif... # if ( configuse_trace_facility == 1 ) : : Used o n l y f o r t r a c i n g the s c h e d u l e r, making debugging e a s i e r. unsigned portbase_type uxtcbnumber ; # endif # if ( configuse_mutexes == 1 ) : : The p r i o r i t y l a s t a s s i g n e d to the task, used by the p r i o r i t y : : i n h e r i t a n c e mechanism. unsigned portbase_type uxbasepriority ; # endif... # if ( configgenerate_run_time_stats == 1 ) : : Used f o r c a l c u l a t i n g how much CPU time each t a s k i s u t i l i z i n g. unsigned long ulruntimecounter ; # endif } tsktcb ; 14 / 34

Tasks Task Details Implementing a Task Source/include/projdefs.h /* Defines the prototype to which task functions must conform. */ typedef void (* pdtask_code )( void * ); void vataskfunction ( void * pvparameters ){ for ( ;; ){ : : Task a p p l i c a t i o n code here. } } Tasks are always a function that returns void and takes a void pointer. Tasks should never return (loop forever). Not much to it, really. 15 / 34

Tasks Task Details Creating a Task (0/3) The kernel creates a task by instantiating and populating a TCB. New tasks are placed in the Ready state and added to the Ready list. If the task is the highest priority task, then it is set as the currently running task. Created by calling xtaskcreate() and deleted by calling vtaskdelete(). xtaskcreate() takes the following parameters. A pointer to the function that implements the task (type pdtask_code from earlier). A name for the task. The depth of the task s stack. The task s priority. A pointer to any parameters needed by the task s function. 16 / 34

Tasks Task Details Creating a Task (1/3) An interesting step in task creation is preparing the task for its first context switch. The TCB stack is initialized to look as if the task was already running, but had been interrupted by the scheduler. The return address is set to the start of the task function with pxportinitialisestack. See code on next slide. 17 / 34

Tasks Task Details Creating a Task (2/3) Source/portable/GCC/ATMega323.c (edited) portstack_type * pxportinitialisestack ( portstack_type * pxtopofstack, pdtask_code pxcode, void * pvparameters ) { : : Place some known v a l u e s on bottom of stack, f o r debugging. * pxtopofstack = 0 x11 ; pxtopofstack - -; * pxtopofstack = 0 x22 ; pxtopofstack - -;... : : S t a r t o f t a s k code w i l l be popped o f f l a s t, so push i t on f i r s t. unsigned short usaddress = ( unsigned short ) pxcode ; * pxtopofstack = ( portstack_type ) ( usaddress & ( unsigned short ) 0x00ff ); pxtopofstack - -; usaddress >>= 8; * pxtopofstack = ( portstack_type ) ( usaddress & ( unsigned short ) 0x00ff ); pxtopofstack - -; : : And then push v a l u e s f o r CPU r e g i s t e r s, t a k i n g i n t o account : : what the c o m p i l e r e x p e c t s f o r t h i s a r c h i t e c t u r e.... 18 / 34

IPC and Synchronization Outline 1 Introduction About Kernel Overview 2 Tasks Tasks versus Co-Routines Task Details 3 IPC and Synchronization Queues Semaphores and Mutexes 4 Scheduler Scheduler Background Scheduler Code 19 / 34

IPC and Synchronization Queues Queue Overview Queues are the primary form of inter-task communications. They can send messages between tasks as well as between interrupts and tasks. Supports appending data to the back of a queue, or sending data to the head of a queue. Queues can hold arbitrary items of a fixed size. The size of each item and the capacity of the queue are defined when the queue is created. Items are enqueued by copy, not reference. 20 / 34

IPC and Synchronization Queues Queues and Blocking Access to queues is either blocking or non-blocking. The scheduler blocks tasks when they attempt to read from or write to a queue that is either empty of full, respectively. If the xtickstowait variable is zero and the queue is empty (full), the task does not block. Otherwise, the task will block for xtickstowait scheduler ticks or until an event on the queue frees up the resource. This includes attempts to obtain semaphores, since they are special cases of queues. 21 / 34

IPC and Synchronization Semaphores and Mutexes Binary Semaphores Used for both mutual exclusion and synchronization. Commonly used by Interrupt Service Routines (ISRs) to wake tasks and avoid polling. Consider the following example. Example: waking a task from an ISR 22 / 34

IPC and Synchronization Semaphores and Mutexes Binary Semaphores Used for both mutual exclusion and synchronization. Commonly used by Interrupt Service Routines (ISRs) to wake tasks and avoid polling. Consider the following example. Example: waking a task from an ISR 1 A binary semaphore is created along with a task that blocks on this semaphore. 22 / 34

IPC and Synchronization Semaphores and Mutexes Binary Semaphores Used for both mutual exclusion and synchronization. Commonly used by Interrupt Service Routines (ISRs) to wake tasks and avoid polling. Consider the following example. Example: waking a task from an ISR 1 A binary semaphore is created along with a task that blocks on this semaphore. 2 An ISR is written for a peripheral that sets the semaphore when the peripheral requires servicing using xsemaphoregivefromisr(). 22 / 34

IPC and Synchronization Semaphores and Mutexes Binary Semaphores Used for both mutual exclusion and synchronization. Commonly used by Interrupt Service Routines (ISRs) to wake tasks and avoid polling. Consider the following example. Example: waking a task from an ISR 1 A binary semaphore is created along with a task that blocks on this semaphore. 2 An ISR is written for a peripheral that sets the semaphore when the peripheral requires servicing using xsemaphoregivefromisr(). 3 This awakens the task waiting on this semaphore. The task resets the semaphore, does some work, and then blocks again. 22 / 34

IPC and Synchronization Semaphores and Mutexes Counting Semaphores and Mutexes Counting Semaphores has support for counting semaphores, the standard down and up (wait and signal) operations. Semaphores are macros defined over the queue API. Therefore, semaphores use the same API calls as queues do. 23 / 34

IPC and Synchronization Semaphores and Mutexes Counting Semaphores and Mutexes Counting Semaphores has support for counting semaphores, the standard down and up (wait and signal) operations. Semaphores are macros defined over the queue API. Therefore, semaphores use the same API calls as queues do. Mutexes supports mutexes (binary semaphores with priority inheritance). As mutexes use the semaphore API, they also support the blocking timeout mechanism. Moreover, they are implemented using the queue API calls. 23 / 34

IPC and Synchronization Semaphores and Mutexes Counting Semaphores and Mutexes Counting Semaphores has support for counting semaphores, the standard down and up (wait and signal) operations. Semaphores are macros defined over the queue API. Therefore, semaphores use the same API calls as queues do. Mutexes supports mutexes (binary semaphores with priority inheritance). As mutexes use the semaphore API, they also support the blocking timeout mechanism. Moreover, they are implemented using the queue API calls. The queue data strictures are protected from corruption by disabling interrupts in some places and disabling the scheduler in others where it would be okay for an interrupt to occur, but not for another task to preempt the queuing task. 23 / 34

Scheduler Outline 1 Introduction About Kernel Overview 2 Tasks Tasks versus Co-Routines Task Details 3 IPC and Synchronization Queues Semaphores and Mutexes 4 Scheduler Scheduler Background Scheduler Code 24 / 34

Scheduler Scheduler Background General Scheduler Operation As mentioned, the scheduler can be co-operative or preemptive. The scheduler is an interrupt handler activated on each tick of hardware clock. Therefore, it contains hardware specific code. The ready list is arranged in order of priority with tasks of equal priority being served on a round-robin basis. The scheduler starts with the highest priority list and works its way downward. There is no explicit Running list or state. The kernel maintains pxcurrenttcb to identify the process in the Ready list that is currently running. 25 / 34

Scheduler Scheduler Background Performing a Context Switch (0/2) The scheduler first resets the counter timer. Without preemption enabled, the timer interrupt simply increments the tick count and returns. vporttickinterupt() Stack GCC Soft Registers Reset Timer Preemption or Co-op? Preemption Co-op Save Context Increment Tick Count vtaskincrementtick() Increment Tick Count vtaskincrementtick() Check for Context Switch Restore Context Un-Stack GCC Soft Registers Return 26 / 34

Scheduler Scheduler Background Performing a Context Switch (1/2) If the scheduler is preemptive, the scheduler pushes the current task context on the stack. Then it increments the tick count and checks to see if this action has caused a blocked task to unblock. If a task of higher priority unblocked, then a context switch is executed. Context is restored. The scheduler returns, potentially starting the execution of a different task than the one that was interrupted. vporttickinterupt() Stack GCC Soft Registers Reset Timer Preemption or Co-op? Preemption Co-op Save Context Increment Tick Count vtaskincrementtick() Increment Tick Count vtaskincrementtick() Check for Context Switch Restore Context Un-Stack GCC Soft Registers Return 27 / 34

Scheduler Scheduler Code ISR for Ticks (0/2) Source/portable/GCC/ATMega323/port.c (edited) # if configuse_preemption == 1 void SIG_OUTPUT_COMPARE1A ( void ) attribute (( signal, naked )); void SIG_OUTPUT_COMPARE1A ( void ){ vportyieldfromtick (); asm volatile ( " reti " ); } # else void SIG_OUTPUT_COMPARE1A ( void ) attribute ( ( signal ) ); void SIG_OUTPUT_COMPARE1A ( void ) { vtaskincrementtick (); } Explanation on next slide. 28 / 34

Scheduler Scheduler Code ISR for Ticks (1/2) Source/portable/GCC/ATMega323/port.c (edited) # if configuse_preemption == 1 void SIG_OUTPUT_COMPARE1A ( void ) attribute (( signal, naked ));... The signal attribute informs GCC the function is an ISR, which means GCC saves and restores every register the ISR modifies and the return uses reti instead of ret. The AVR microcontroller disables interrupts upon entering an ISR, and reti is required to re-enable them. But saves registers, so naked is used so that GCC won t generate any function entry or exit code. Macros portsave_context() and portrestore_context() save and restore the execution context. 29 / 34

Scheduler Scheduler Code The Context Saving Macro (0/2) Source/portable/GCC/ATMega323/port.c (edited) # define portsave_context () \ asm volatile ( " push r0 \n\t" \ : : Save r e g i s t e r r0. "in r0, SREG \n\t" \ : : See (1) below. " cli \n\t" \ : : D i s a b l e i n t e r r u p t s. " push r0 \n\t" \ : : Save p r o c e s s o r s t a t u s. " push r1 \n\t" \ : : Save o r i g i n a l r1 v a l u e. " clr r1 \n\t" \ : : See (2) below. " push r2 \n\t" \ : : Save r3 through r30.... " push r31 \n\t" \... 1 Before the microcontroller jumps to an ISR, it pushes the PC onto the stack, which is why this is not done here. 2 Move processor status register to r0. 3 The instruction clr r1 sets r1 to zero, because the GCC generated ISR expects it to be zero. 4 Continued on next slide. 30 / 34

Scheduler Scheduler Code The Context Saving Macro (1/2) Source/portable/GCC/ATMega323/port.c (edited)... " push r31 \n\t" \ " lds r26, pxcurrenttcb \n\t" \ : : See ( 1 ). " lds r27, pxcurrenttcb + 1 \n\t" \ "in r0, 0 x3d \n\t" \ : : (2) "st x+, r0 \n\t" \ "in r0, 0 x3e \n\t" \ : : (3) "st x+, r0 \n\t" \ ); 1 The X register allows data indirect addressing with pre-decrement. r26 is X low byte, 27 the high byte. The X processor register is loaded with the address to which the stack pointer is to be saved. 2 Save stack pointer low byte. 3 Save stack pointer high nibble. 4 This is the reason struct tsktcb s first member must be portstack_type *pxtopofstack. 31 / 34

Scheduler Scheduler Code Incrementing the Tick (0/2) Source/task.c (edited) void vtaskincrementtick ( void ){ if( uxschedulersuspended == ( unsigned portbase_type ) pdfalse ){ : : I n t h i s case, the s c h e d u l e r not suspended. ++ xtickcount ; : : Increment t i c k s. if( xtickcount == ( portticktype ) 0 ) { xlist * pxtemp ; /* Tick count has overflowed so we need to swap the delay lists. If there are any items in pxdelayedtasklist here then there is an error! */ pxtemp = pxdelayedtasklist ; pxdelayedtasklist = pxoverflowdelayedtasklist ; pxoverflowdelayedtasklist = pxtemp ; xnumofoverflows ++; } prvcheckdelayedtasks (); : : Has t i c k made a timeout e x p i r e? } else {... 32 / 34

Scheduler Scheduler Code Incrementing the Tick (1/2) Source/task.c (edited) }... } else { ++ uxmissedticks ; : : Scheduler i s suspended, so we missed a t i c k. : : The t i c k hook g e t s c a l l e d at r e g u l a r i n t e r v a l s, even i f the : : s c h e d u l e r i s l o c k e d. # if ( configuse_tick_hook == 1 ){ extern void vapplicationtickhook ( void ); vapplicationtickhook (); } # endif # if ( configuse_tick_hook == 1 ){ extern void vapplicationtickhook ( void ); /* Guard against the tick hook being called when the missed tick count is being unwound ( scheduler is being unlocked ). */ if( uxmissedticks == 0 ) vapplicationtickhook (); } # endif... 33 / 34

Scheduler Scheduler Code References website: www..org Atmel AVR Instruction Set Guide www.atmel.com/ateml/acrobat/doc0856.pdf 34 / 34