Interrupt and Time Management in µC/OS-III

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Resource management and Synchronization Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
CSCI 4717/5717 Computer Architecture
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Computer System Organization S H Srinivasan
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
ΜC/OS-III Tasks Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Embedded Systems 7763B Mt Druitt College of TAFE
Introduction to Embedded Systems
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Getting Started with the µC/OS-III Real Time Kernel Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Scheduling in µC/OS-III Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
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.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Outlines  Introduction  Kernel Structure  Porting.
Scheduler activations Landon Cox March 23, What is a process? Informal A program in execution Running code + things it can read/write Process ≠
WORKING OF SCHEDULER IN OS
Getting Started with Micriμm’s μC/OS-III Kernel
REAL-TIME OPERATING SYSTEMS
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Processes and threads.
Process concept.
Interrupts and signals
Microprocessor Systems Design I
CS 6560: Operating Systems Design
Topics Covered What is Real Time Operating System (RTOS)
Protection of System Resources
Scheduler activations
Getting Started with the µC/OS-III Real Time Kernel
Computer System Overview
Scheduling in µC/OS-III
Module 2: Computer-System Structures
Processor Fundamentals
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Lecture Topics: 11/1 General Operating System Concepts Processes
Transmitter Interrupts
Architectural Support for OS
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Module 2: Computer-System Structures
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
CS333 Intro to Operating Systems
Architectural Support for OS
Module 2: Computer-System Structures
COMP3221: Microprocessors and Embedded Systems
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Module 2: Computer-System Structures
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Presentation transcript:

Interrupt and Time Management in µC/OS-III Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University

Interrupt Basics Context Interrupt Service Routine (ISR) Enable/Disable Nesting Interrupt disable time Interrupt response: time between interrupt and start of user ISR execution Interrupt recovery: time required to return to interrupted code (or higher priority task) Task latency: time to return to task level code

Interrupt Handling Interrupt controller handles many issues including providing the address of the required ISR in many cases Two models: All interrupts vector to a single interrupt handler Each interrupt vector directly to its own ISR

µC/OS-III ISR Pseudo Code MyISR: Disable all interrupts; Save CPU registers; OSIntNestingCtr++; if (OSIntNestingCtr == 1) OSTCBCurPtr->StkPtr = current task’s CPU stackpointer register value Clear interrupting device; Re-enable interrupts (optional); Call user ISR; OSIntExit(); Restore CPU registers; Return from interrupt; ISR Prologue ISR Epilogue Written in assembly Context: some CPUs do this automatically Some CPUs have separate stack (and SP) for interrupts (µC/OS-III port can implement this in software saving space on all task stacks) User code typically needs to call one of the Post() functions Must call OSIntExit()

Short ISR When no Post() call is needed No OSIntExit() call is needed MyShortISR: Disable all interrupts; Save necessary CPU registers; Clear interrupting device; DO NOT re-enable interrupts; Call user ISR; Restore saved CPU registers; Return from interrupt; When no Post() call is needed No OSIntExit() call is needed Should be the exception as the OS does not know about this at all…

One Common Master ISR ISR Prologue; while (there are still interrupts to process) { Get vector address from interrupt controller; Call interrupt handler; } ISR Epilogue; The while loop above can be part of a user ISR written in C Interrupt controller may provide an actual address of the required ISR or just an index that can be used to get the address from a table in memory ISR needs to look like this (one for each kind of interrupt): void MyISRHandler(void) Note that there is no nested interrupts even though it does handle multiple interrupts, so ISR Prologue and Epilogue need to be called only once

Direct Post Interrupt Latency = maximum interrupt disable time; Interrupt Response = interrupt latency + vectoring to ISR + ISR prologue; Interrupt Recovery = handling of device + Post() + ISR epilogue; Task Latency = interrupt response + interrupt recovery + scheduler lock time

Deferred Post Interrupt Latency = maximum interrupt disable time; Interrupt Response = interrupt latency + vectoring to ISR + ISR prologue; Interrupt Recovery = handling of device + Post() + ISR epilogue; Task Latency = interrupt response + interrupt recovery + re-issue Post() + context switch to task + scheduler lock time

Direct vs. Deferred

Tick Handling void OS_CPU_SysTickHandler (void) /* ISR */ { CPU_CRITICAL_ENTER(); OSIntNestingCtr++; /* Tell uC/OS-III that we are starting an ISR */ CPU_CRITICAL_EXIT(); OSTimeTick(); /* Call uC/OS-III's OSTimeTick() */ OSIntExit(); /* Tell uC/OS-III that we are leaving the ISR */ } void OSTimeTick(void) OSTimeTickHook(); #if OS_CFG_ISR_POST_DEFERRED_EN > 0u Get timestamp; Post “time tick” to the interrupt queue; #else Signal the Tick Task; Run round robin scheduling if enabled; Signal the Timer Task; #end Hook is called first to give the application more precise timing Your low power app may not need tick processing at all: it is OK, but no time delays and timeouts can be used.

Pend Lists The first few fields are the same: OS_PEND_OBJ Type: four characters for easy debugging Head and Tail pointer point to OS_PEND_DATA and not TCB

Pend Lists cont’d. Prev and Next: doubly linked list TCBPtr: corresponding TCB PenObjPtr: object task is pending on Rest: only needed when pending on multiple objects

Pend List example

Time Management: Relative Delay OS_OPT_TIME_DELAY Timing is not precise: The only thing guaranteed is that the task will be delayed at least: ((ticks – 1) * tick-period)

Absolute Delay Void MyTask(void *p_arg) { OS_ERR err; OS_TICK current; : current = OSTimeGet(); while (1) { current = current + 10; OSTimeDly(current, OS_OPT_TIME_MATCH, &err); if (err == OS_ERR_NONE) { /* code resumes here after waiting for 10 ticks or resumed by another task */ } else { /* some error in Dly function call */ Regardless of CPU load, the task remains “synchronized”: for example, it will be called 100 times during 1000 ticks. In relative mode under heavy CPU load, it may miss ticks, so it might get called less than 100 times. A time-of-day clock may be “late” if relative mode is used.

Time Management OSTimeDlyHMSM() only works in relative mode OS_OPT_TIME_HMSM_STRICT : only valid ranges OS_OPT_TIME_HMSM_NON_STRICT: hr: 0-999, sec: 0-9999 OSTimeDlyResume() OSTimeSet() OSTimeGet()

Timers Counters that perform an action via a callback function when 0 is reached OS_CFG_TMR_EN Timer rate is typically (much) lower than tick rate Callback is run from the context of the Timer Task: must not make blocking calls void OSTmrCreate (OS_TMR *p_tmr, CPU_CHAR *p_name, OS_TICK dly, /* initial delay */ OS_TICK period, /* repeat period */ OS_OPT opt, OS_TMR_CALLBACK_PTR p_callback, void *p_callback_arg, OS_ERR *p_err)

One-shot Timers Can be retriggered Can be used to implement watchdog timers

Periodic Timers

Timer States

Timing Tick ISR signals Timer Task at the timer rate Timer Task eventually runs and calls callback functions of all timers that have expired

Timer wheel The exact same concept as the tick wheel: only a fraction of the timers need to be looked at any one time