Programming Embedded Systems

Similar documents
Interrupts (Exceptions) (From LM3S1968) Gary J. Minden August 29, 2016

Interrupts (Exceptions) Gary J. Minden September 11, 2014

Exceptions and Interrupts ARM Cortex M3

Design and Implementation Interrupt Mechanism

Interrupt/Timer/DMA 1

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

Measuring Interrupt Latency

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

ARM Cortex core microcontrollers

COEN-4720 Embedded Systems Design Lecture 4 Interrupts (Part 1) Cristinel Ababei Dept. of Electrical and Computer Engineering Marquette University

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

EE458 - Embedded Systems Exceptions and Interrupts

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

The control of I/O devices is a major concern for OS designers

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

STM32 MICROCONTROLLER

Process Scheduling Queues

ELC4438: Embedded System Design ARM Cortex-M Architecture II

Operating System Control Structures

Interrupts in Zynq Systems

Input / Output. School of Computer Science G51CSA

ARM Cortex-M and RTOSs Are Meant for Each Other

Interrupts Peter Rounce

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Today: Computer System Overview (Stallings, chapter ) Next: Operating System Overview (Stallings, chapter ,

PC Interrupt Structure and 8259 DMA Controllers

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

Final Exam Study Guide

Microprocessors & Interfacing

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

ARM architecture road map. NuMicro Overview of Cortex M. Cortex M Processor Family (2/3) All binary upwards compatible

Interrupts and Low Power Features

Introduction. ! Exception*are*events*! They*occur*during*the*execution*of*the*program! Type*of*ARM*exceptions*! Exceptions*that*result*by*a*command

Hardware OS & OS- Application interface

DSP/BIOS Kernel Scalable, Real-Time Kernel TM. for TMS320 DSPs. Product Bulletin

Interrupts Peter Rounce - room 6.18

Course Introduction. Purpose: Objectives: Content: 27 pages 4 questions. Learning Time: 20 minutes

introduction to interrupts

Mobile Operating Systems Lesson 01 Operating System

ECE 372 Microcontroller Design Parallel IO Ports - Interrupts. ECE 372 Microcontroller Design Parallel IO Ports - Interrupts

STM32: Peripherals. Alberto Bosio November 29, Univeristé de Montpellier

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

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Real-Time Performance of Linux. OS Latency

UNIT IV I/O PROGRAMMING AND SCHEDULE MECHANISM

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

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

Input/Output Systems

Embedded System Design

Experiment 3. Interrupts. Hazem Selmi, Ahmad Khayyat

Hercules ARM Cortex -R4 System Architecture. Processor Overview

18-349: Introduction to Embedded Real-Time Systems

Computer Architecture CS 355 Busses & I/O System

TDDD07 Real-time Systems Lecture 10: Wrapping up & Real-time operating systems

Types of Interrupts:

Zilog Real-Time Kernel

The ARM Cortex-M0 Processor Architecture Part-1

ZiLOG Real-Time Kernel Version 1.2.0

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Input/Output Problems. External Devices. Input/Output Module. I/O Steps. I/O Module Function Computer Architecture

Software Development with an Open Source RTOS

These three counters can be programmed for either binary or BCD count.

INTERRUPTS in microprocessor systems

Last Time. Think carefully about whether you use a heap Look carefully for stack overflow Especially when you have multiple threads

In Class Assignment 2

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

Module Introduction. PURPOSE: The intent of this module is to explain MCU processing of reset and interrupt exception events.

[08] IO SUBSYSTEM 1. 1

Lab 4 Interrupt-driven operations

Microcontroller basics

I/O - input/output. system components: CPU, memory, and bus -- now add I/O controllers and peripheral devices. CPU Cache

EEL 4744C: Microprocessor Applications. Lecture 7. Part 2. M68HC12 Interrupt. Dr. Tao Li 1

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

Interrupts. Why Interrupts

L2 - C language for Embedded MCUs

Concurrent programming: Introduction I

IT 540 Operating Systems ECE519 Advanced Operating Systems

An Operating System in Action

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

EE458 - Embedded Systems Lecture 8 Semaphores

Embedded System Curriculum

Chapter 13: I/O Systems

AN2585 Application note

Module 2. Embedded Processors and Memory. Version 2 EE IIT, Kharagpur 1

Process Coordination and Shared Data

A. This Errata sheet represents the known bugs, anomalies and work-arounds for the ADuC812 MicroConverter.

The von Neuman architecture characteristics are: Data and Instruction in same memory, memory contents addressable by location, execution in sequence.

Operating System Design Issues. I/O Management

Operating Systems. Lecture 3- Process Description and Control. Masood Niazi Torshiz

Chapter 4. Enhancing ARM7 architecture by embedding RTOS

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

Lecture 10 Exceptions and Interrupts. How are exceptions generated?

32-Bit RISC Microcontroller. TMPM3H Group(2) Reference Manual Exception (EXCEPT-M3H(2)) Revision

Migrating to Cortex-M3 Microcontrollers: an RTOS Perspective

操作系统概念 13. I/O Systems

COSC 243. Input / Output. Lecture 13 Input/Output. COSC 243 (Computer Architecture)

6/20/2018. Lecture 2: Platforms & RTOS. Outline. Lab Setup (20 min) Labs work. Lecture: Platform + RTOS

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

CSE398: Network Systems Design

Transcription:

Programming Embedded Systems Lecture 5 Interrupts, modes of multi-tasking Wednesday Feb 1, 2012 Philipp Rümmer Uppsala University Philipp.Ruemmer@it.uu.se 1/31

Lecture outline Interrupts Internal, external, software Interrupt service routines Deferred interrupt handlers Different kinds of multi-tasking 2/31

Interrupts Hardware feature of processor to react to events Clock interrupts ( system tick ): drives scheduler, determines time slices Other internal interrupts: timers, etc. Software interrupts/traps/faults: raised by executing particular instructions External interrupts: events from peripherals, pins, etc. 3/31

Interrupts (2) When interrupt occurs, MCU executes an interrupt service routine (ISR) at a pre-defined code location ISR locations are stored in interrupt vector table For complete list of possible interrupts on STM32F10x/CORTEX M3: see reference manual, http://www.st.com/stonline/products/literature/rm/13902.pdf 4/31

Clock interrupts Usually set up to occur regularly (period 1ms); frequency can be chosen In assignments/labs: every 1ms Driven by internal/external real-time clock ISR is the scheduler, which might decide to switch in another task when tick occurs 5/31

Internal interrupts Timers can be set up to raise interrupts; Most importantly: upon overflow 6/31

Software interrupts/traps Used to implement system calls if kernel is running in privileged mode (SVCall interrupt) Signal fault conditions: memory faults, bus faults, etc. 7/31

External interrupts Explicit external-interrupt lines (general-purpose I/O ports) Part of interface to peripherals and buses (signal packet arrival, finished transmission, etc): DMA, CAN, I2C, USB, SPI, UART, Reset: initialisation, invocation of main Non-maskable interrupt (NMI): highest-priority, used e.g. for watchdogs 8/31

Setting up interrupts Typical parameters, chosen through special-purpose registers: Enabled/disabled (unmasked/masked) Priority (important when multiple interrupts occur simultaneously) ISR address Pulse/pending interrupts (cleared by itself/hardware or in ISR?) Which events to observe (e.g., rising or falling edges of signals) 9/31

Further parameters Pending: Interrupt has been triggered, is waiting for being served or currently being served Active: ISR is executing 10/31

Interrupt handling World/someone... Processor... ISR... 1. makes interrupt pending 2. finishes current activities 3. saves state of current task on stack (registers, PC) 4. decides which interrupt to serve (based on priorities) 5. blocks all interrupts with same/lower priority 6. marks interrupt as active 7. fetches address of ISR from vector table 8. invokes ISR (similar to function invocation) 12. unblocks interrupts, restores old state 9. takes care of event 10. clears pending bit 11. returns Interrupt latency 11/31

Interrupt latency Interrupt latency also depends on other, pending, higher-priority interrupts can vary Interrupt jitter: amount of variation of latency Determines how fast system can react to events In the very best case, latency is 12 cycles on CORTEX M3 12/31

Nested interrupts ISR can be interrupted itself by higherpriority interrupts Applies in particular to CORTEX M3 (NVIC, nested vectored interrupt controller) used by default Can be prevented by disabling interrupts in ISR 13/31

Interrupt tail-chaining Directly execute a sequence of ISRs, without returning to normal program in between Safes some time (storing/restoring program state unnecessary) Also done by CORTEX M3 by default 14/31

Deferred interrupt handling 15/31

Motivation Interrupts are generally problematic in real-time systems outside of normal scheduling, usually not pre-emptable for scheduler can occur with high frequency, create high system loads With many OS kernels (e.g., FreeRTOS), certain/most functions must not be called from ISRs ISRs are normally not reentrant, or even a critical section 16/31

Solutions Avoiding interrupts (more later) Deferred/split-interrupt handling Common in most OSs, not only in real-time systems 17/31

Deferred interrupt handling Keep ISR minimal ( Immediate Interrupt Service ) Actual handling of event done later in an ordinary task ( Scheduled Interrupt Service ) 18/31

Processor... ISR... 2. finishes current activities 3. saves state of current task on stack (registers, PC) 4. decides which interrupt to serve (based on priorities) 1. 5. makes blocks interrupt all interrupts with pending same/lower priority 6. marks interrupt as active Interrupt handling World/someone... Processor... ISR... 7. fetches address of ISR from vector table 8. invokes ISR (similar to function invocation) 12. unblocks interrupts, restores old state 2. finishes current activities 3. saves state of current task on stack (registers, PC) 4. decides which interrupt to serve (based on priorities) schedules actual 5. blocks all interrupts with 9. takes care of event interrupt service same/lower priority 6. marks 10. interrupt clears pending as active bit communication 7. fetches 11. address returns of ISR through queue from vector table or semaphore 8. invokes ISR (similar to function invocation) 13. Scheduler switches in service task 12. unblocks interrupts, restores old state 9. takes care of event 10. 14. clears Service pending task bit handles event 11. returns 19/31

FreeRTOS example Interrupt raised by timer ISR + scheduled interrupt task are C functions, communicate via binary semaphore ISR is specified in file STM32F10x.s STM32F10x uses 4bit priorities [0, 16) (split into preemption- and sub-priority) Important: most FreeRTOS functions (including semaphore functions) must not be used in ISR 20/31

FreeRTOS example (2) External interrupt line, connected to PORTA.0 21/31