Interrupt/Timer/DMA 1

Similar documents
Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

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

Hercules ARM Cortex -R4 System Architecture. Processor Overview

Microprocessors & Interfacing

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

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

Chapter 4. Enhancing ARM7 architecture by embedding RTOS

Design and Implementation Interrupt Mechanism

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

Computer System Overview

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

Question Bank Microprocessor and Microcontroller

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

18-349: Introduction to Embedded Real-Time Systems

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

Chapter 7 Central Processor Unit (S08CPUV2)

INPUT/OUTPUT ORGANIZATION

INPUT/OUTPUT ORGANIZATION

Input Output (IO) Management

Lecture 10 Exceptions and Interrupts. How are exceptions generated?

Chapter 2. Overview of Architecture and Microcontroller-Resources

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

Programming Embedded Systems

ARM Cortex core microcontrollers

Chapter 3. Top Level View of Computer Function and Interconnection. Yonsei University

Interrupts in Zynq Systems

MACHINE CONTROL INSTRUCTIONS: 1. EI

2. List the five interrupt pins available in INTR, TRAP, RST 7.5, RST 6.5, RST 5.5.

Mobile Operating Systems Lesson 01 Operating System

HANDLING MULTIPLE DEVICES

Migrating to Cortex-M3 Microcontrollers: an RTOS Perspective

1 MALP ( ) Unit-1. (1) Draw and explain the internal architecture of 8085.

Unit 3 and Unit 4: Chapter 4 INPUT/OUTPUT ORGANIZATION

INTERRUPTS in microprocessor systems

Outline. Operating Systems: Devices and I/O p. 1/18

Exceptions and Interrupts ARM Cortex M3

ARM Processors for Embedded Applications

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

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

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

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

UNIT- 5. Chapter 12 Processor Structure and Function

EE458 - Embedded Systems Exceptions and Interrupts

8086 Interrupts and Interrupt Responses:

Programmed I/O Interrupt-Driven I/O Direct Memory Access (DMA) I/O Processors. 10/12/2017 Input/Output Systems and Peripheral Devices (02-2)

Types of Interrupts:

ECE 485/585 Microprocessor System Design

October, Saeid Nooshabadi. Overview COMP 3221

6 Direct Memory Access (DMA)

Pin Description, Status & Control Signals of 8085 Microprocessor

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

Reset, Interrupts, Exceptions, and Break ECE 3534

ARM Advanced Interrupt Controller

Microprocessor Architecture

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

CPUs. Input and output. Supervisor mode, exceptions, traps. Co-processors. Computers as Components 4e 2016 Marilyn Wolf

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

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

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

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

Input/Output Systems

S.R.M. INSTITUTE OF SCIENCE & TECHNOLOGY SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING

Input / Output. School of Computer Science G51CSA

Unit 1. Chapter 3 Top Level View of Computer Function and Interconnection

Chapter 13: I/O Systems

9/25/ Software & Hardware Architecture

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

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

SECTION 5 RESETS AND INTERRUPTS

CISC RISC. Compiler. Compiler. Processor. Processor

Microprocessors/Microcontrollers

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

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

PC Interrupt Structure and 8259 DMA Controllers

Northern India Engineering College, Delhi (GGSIP University) PAPER I

Interrupt-Driven Input/Output

EN1640: Design of Computing Systems Topic 07: I/O

ARM Embedded Systems: ARM Design philosophy, Embedded System Hardware, Embedded System Software

ARM Interrupts. EE383: Introduction to Embedded Systems University of Kentucky. James E. Lumpp

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

Instruction Set Architecture of MIPS Processor

Overview of Microcontroller and Embedded Systems

Input/Output Programming

Interconnects, Memory, GPIO

Generic Model of I/O Module Interface to CPU and Memory Interface to one or more peripherals

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

William Stallings Computer Organization and Architecture 10 th Edition Pearson Education, Inc., Hoboken, NJ. All rights reserved.

ARM Cortex-M and RTOSs Are Meant for Each Other

Chapter 13: I/O Systems

Chapter 13: I/O Systems. Chapter 13: I/O Systems. Objectives. I/O Hardware. A Typical PC Bus Structure. Device I/O Port Locations on PCs (partial)

Computer and Hardware Architecture I. Benny Thörnberg Associate Professor in Electronics

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 12 Processor Structure and Function

Unit DMA CONTROLLER 8257

Hardware OS & OS- Application interface

The Purpose of Interrupt

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

MICROPROCESSOR MICROPROCESSOR. From the above description, we can draw the following block diagram to represent a microprocessor based system: Output

Computer Organization ECE514. Chapter 5 Input/Output (9hrs)

Control Unit: The control unit provides the necessary timing and control Microprocessor resembles a CPU exactly.

Transcription:

Interrupt/Timer/DMA 1

Exception An exception is any condition that needs to halt normal execution of the instructions Examples - Reset - HWI - SWI 2

Interrupt Hardware interrupt Software interrupt Trap 3

Hardware devices sources of interrupts Hardware sources can be internal or external of ongoing routine and thereby diversion to corresponding ISR The internal sources from devices differ in different process or microcontroller or devices and their version and their families External sources and ports also differ in different processors or microcontrollers 4

Interrupt sources Each of the interrupt sources demands a temporary transfer of control from the presently executed routine to the ISR corresponding to the source 5

Internal Hardware Device Sources Parallel port UART port (receive and transmit) ADC (start and end conversion) Real-time clock time-outs Watch dog timer reset Pulse Accumulator overflow 6

Keyboard interrupt Take about 10ms to send the code for a key and maximum 10 keys per second Interval between two successive keys are not fixed Interrupt driven mode, when a key is pressed 7

Example of keyboard interrupt 8

Printer Interrupt Maximum 300 characters can be printed in 1 second When does a print operation completes is not fixed Intervals between two successive print are not fixed Interrupt driven mode when a print action is completed 9

Example of printer interrupt 10

Interrupt type Maskable interrupt To execute timing critical interrupt Non-maskable interrupt 11

Interrupt driven data transfer 12

Flow chart for interrupt service 13

Interrupt in a typical microcontroller 14

Example of Interrupt table 15

Bus arbitration To service more than one device Priority arbiter Daisy chain arbiter 16

Priority arbiter 1. The processor is executing its program 2. Peripheral1 needs servicing so asserts Ireq1. Peripheral2 also needs servicing so assert Ireq2. 3. Priority arbiter sees at least one Ireq input asserted, so asserted Int. 4. Processor stops executing its program and stores its state. 5. Processor asserts Inta 6. Priority arbiter asserts Iack1 to acknowledge Perpheral1 7. Peripheral1 puts its interrupt address vector on the system bus 8. Processor jumps to the address of ISR read from data bus, ISR executes, and return 17

Priority arbiter 18

Daisy chain arbiter 1. The processor is executing its program 2. Any Peripheral needs servicing asserts Req out goes to the Req in of the subsequent device in the chain 3. Thus, the peripheral nearest to the processor asserts Int 4. The processor stops executing its program and stores its state 5. Processor asserts Inta the nearest device 6. The Inta passes through the chain till it finds a flag which is set by the device which has generated the interrupt. 7. The interrupting device sends the Interrupt Address Vector to the processor for its interrupt service routine 8. The processor jumps to the address of ISR read from data bus, ISR executes and returns. 9. The flag is reset 19

Daisy chain arbiter 20

Sources of Software Interrupt Software sources of interrupt are related to software detecting computation error or exceptional condition during execution or execute a software interrupt instruction (SWI) 21

Software interrupt Example Division by Zero by hardware Over-flow detection by hardware Under-flow detection by hardware Illegal opcode detection by hardware Software Interrupt instruction 22

Trap Special case of Software Interrupt Used for trapping some run-time error conditions (called throwing exceptions) and execute exception handlers on catching the exceptions Also used in debugger 23

Question? An Embedded System has three periodic devices Service time: how long it takes to run interrupt handler for each device Interrupt latency: maxim elapse time between an interrupt request and the start of interrupt handler routine If program P takes 100 seconds with interrupt disabled,how long will it takes with interrupt enabled, assuming no interrupt overlapped? 24

Solution Device 1 shall take (150+50)/800 = 0.25 Device 2 shall take (50+50)/1000 = 0.10 Device 3 shall take (100+100)/800 = 0.25 In one unit real time, it will take 0.6 unit time to service interrupt For a program with 100 seconds, it will take 250 seconds to finish the entire program with interrupt enabled 25

ARM Interrupt ARM has 7 modes of operation Switching between modes can be done by modifying CPSR register Most applications execute in user mode Non-user modes are entered to serve interrupts or exceptions 26

Modes of operation 27

Exceptions and modes Each exception causes ARM to enter to different modes 28

Vector Tables It is a table address of ARM core branches to when exception is raised and there is always branching instructions that direct the core to ISR 29

Exception Priority Newer ARM, Primask,Faultmask, and Basepri are used instead 30

Link Register Used to return the PC to the appropriate place in the interrupt task since this is not always the old PC value. It is modified depending on the type of execution. 31

Exception Handler Entering exception handler 1) Save the address of the next instruction in the appropriate LR 2) Save CPSR 3) Modify CPSR for the new mode 4) Fetch next instruction from the vector table Leaving exception handler 1) Return CPSR before calling the handler 2) Clear the interrupt disable flag (if set) 3) Move LR to the PC 32

Interrupts Assigning interrupts It is up to the system designer who can decide which HW peripheral can produce with interrupt Standard design: SWI are used to called privilege OS routines IRQ are designed to call general purpose interrupts FIQ is reserved for one single interrupt source that require fast response time 33

Interrupt latency It is the interval of time from an internal interrupt signal being raised to the first fetch of an instruction of ISR of the raised interrupt signal System architect tries to achieve two main goals: To handle multiple interrupt simultaneously To minimize the interrupt latency It can be done by 2 methods Allow nested interrupt handling Give priorities to different interrupt sources 34

Enable/Disable Interrupt This can be done by modifying CPSR using 4 ARM instructions: MRS to read CPSR MRS to store CPSR BIC Bit clear instruction ORR Or instruction 35

Interrupt Stack Stacks are needed extensively for context switching between different modes when interrupt are raised The design of stack depends on OS requirements Target hardware 36

Interrupt stack Two design decision are needed to be made Location Size 37

Non-nested Interrupt Handle Simple interrupt Handler Interrupt is disabled until the control is returned back to the interrupted task One interrupted can be served at a time Not suited for complex embedded system Scheme 38

Interrupt latency Device 1 : interrupt latency 50 s, ISR time 150 s Device 2 : interrupt latency 50 s, ISR time 50 s Device 3 : interrupt latency 100 s, ISR time 200 s What s the average interrupt latency if all interrupt happens at the same time? 39

Nested Interrupt Handler Handling more than one interrupt at a time Latency is improved System is more complex Normal interrupt can block critical interrupt 40

Nested Interrupt Handler Scheme Handler tests the flag that is updated by ISR Re-enabling interrupt requires switching out of current interrupt mode to either SVC or system mode Context switching involving emptying IRQ stack into reserved block 41

Interrupt latency Device 1 : interrupt latency 50 s, ISR time 150 s Device 2 : interrupt latency 50 s, ISR time 50 s Device 3 : interrupt latency 100 s, ISR time 200 s What s the average interrupt latency if all interrupt happens at the same time? 42

Prioritize Interrupt Handler Associate a priority level with a particular interrupt source Handling prioritization can be done either by software or hardware When an interrupt is raised, a fixed amount of comparison is done 43

Interrupt latency Device 1 : interrupt latency 50 s, ISR time 150 s Device 2 : interrupt latency 50 s, ISR time 50 s Device 3 : interrupt latency 100 s, ISR time 200 s What s the average interrupt latency if all interrupt happens at the same time? Assume that the shortest total latency time has the highest priority. 44

Other Schemes Re-entrant interrupt handler: re-enable interrupts earlier Priority standard interrupt handler: arranges priorities in a special way to decide which interrupt get higher priorities Prioritized group interrupt handler: group some interrupts into subset 45

Advantages/Drawback Non-Nested Interrupt handler Easy to implement and debug High interrupt latency Sequential service Not suitable for complex system Nested Interrupt handler Handle multiple interrupts No prioritization Medium interrupt latency Prioritize Interrupt handler Low latency Handle multiple interrupts Deterministic interrupt latency More complex Need time for priority comparison 46

Timer Timer is a device, which count the input at a regular interval T using clock pulse at its input The counts increment on each pulse and store in a register called count register 47

Evaluation of the time The count multiplies with the interval T gives the time The (present counts initial count ) * T gives the time interval between initial time and current time 48

Timer Has an input pin or a control bit in a control register for resetting the count bits Has an output pin or a status bit in a control register for the output value 49

Counter A device, which count the input due to the events at regular or irregular intervals The counts give the number of input events or pulses since it was last read. Has a register to enable read of present counts Functions as timer when counting regular interval clock pulses 50

Timer or Counter Interrupt When a timer or counter becomes 0x00 or 0x0000 after 0xFF or 0xFFFF(Maximum value), it can generate an Interrupt or output Time-Out signal or setting a status bit Timer Overflow (TOV) 51

Basic Hardware Timer 52

More complex timer 53

Timer with a terminal count 54

The timer count and its output 55

Block diagram of an Embedded System 56

Hardware Timer 57

Real-time clock Real-time clock ticks (System Heart Beats) Real-time clock is a clock which once the system starts, does not stop and can t be reset and its count value can t be reloaded Real-time clock is set for ticks using prescale bit in control register to control tick rate 58

Usage of a timer device To issue some service routing every some pre-set counter interval Count some special events within some timing interval Finding the time interval between two events Waiting for synchronization for other tasks such as from mutex, message queue 59

Usage of timer device Watchdog timer Bit-rate control for data communication Input-pulse counting for non-periodic inputs Context switch for multi-tasking OS Schedule tasks for RTOS Time division multiplexing (TDM) 60

Timer state 61

Timer state 62

Software Timer A software which executes and increases or decreases a count-variable on an interrupt from a system timer or from a real-time clock interrupt The software timer also generates interrupt on overflow of count-value or on finishing value of the count-variable 63

System clock An hardware-timing device is programmed to tick at constant intervals At each tick, there is an interrupt The interrupts are called system clock interrupts, when use to control the schedule and timings of the system 64

Software Timer (SWT) 65

SWT Actions are analogous to that of a hardware timer. While there is a physical limit of hardware timer, SWTs can be limited by the number of entry in the interrupt vector 66

Watchdog timer A timing device such that after preset time interval is set, an event must occur during the interval else the device will generate the timeout signal on failure If the event occurs, the watchdog timer is disabled Timeout may result in a service routine call, or even a processor reset 67

Example Assume that we anticipate that a set of tasks must finish in 100ms interval If the program finishes before 100ms, the watchdog timer is disabled and stopped If the program does not finish within 100ms, watchdog timers will generate an interrupt to reset the system 68

Watchdog timer application An application in mobile is that display is off in case that there is no user interaction takes place within watched time interval (e.g, 20 second) This can help save power of the mobile phone 69

Watchdog timer application An application in temperature control system: if the controller takes no action to switch off the boiler within preset watched time interval, a service routine is called to switch off the boiler Failure to switch off, may burst a boiler in which water is heated 70

Provision of watchdog timer A software interrupt can be programmed as a watchdog timer Microcontroller may provide hardware support for a watchdog timer 71

ARM SYSTICK Timer TICKINT to generate interrupt CLKSOURCE external or core clock COUNTFLAG timer history (1 means overflow) Reload value when timer reaches zero TENMS Calibration value for 10ms NoREF No external reference clock 72

Direct Memory Access (DMA) A DMA is required when multi-data set or burst of data or a block is to be transferred between the external device and system or two systems A device facilitates DMA transfer with a processor element and that device is called DMAC (DMA Controller) 73

Using a DMA controller DMA based method is useful when a block of bytes are transferred. E.g, disk to RAM or RAM to disk System performance improves by separate the processing of the transfer to the peripherals 74

An example of DMA architecture 75

DMA controller architecture 76

DMAC hold request After an ISR from CPU initializes and programs DMAC, the DMAC sends the hold request to the CPU CPU acknowledges and gives the control of the bus to DMAC 77

Three modes of data transfer Single transfer at a time and then release the control of the system bus Burst transfer at a time and then release the control of the system bus, a burst can be a few kb Bulk transfer and the release the control of the system bus after the transfer is complete 78

CPU and DMAC interaction At the start for DMAC programming and initializing At the end to return control back to CPU ISRs of the CPU is called only at the beginning and at the end of DMA transfer 79

Programming the DMAC registers The ISR from CPU will program the DMA registers for : Transfer command Data count Memory block address I/O bus address 80

Multiple channels DMAC Provides DMA action from system with two I/O devices or more Separate set of registers for programming each channels Separate interrupt signals in the case of multi-channel DMAC 81

Question? 82

Fly-by DMA transfer Single cycle, single address transfer Efficient data transfer First a device or CPU issues DMA request DMAC gains control of the bus from CPU DMAC sends acknowledge back to the device 83

Fly-by DMA transfer 84

Fetch-and-Deposit transfer Dual-cycle, dual address, flow-through Involves two memories or I/O cycles Data first transfer from I/O into a temporary register inside DMAC The data is written to memory or I/O in the next cycle Inefficient, but useful for interfacing devices with different bus sizes, e.g., read two 16 bits read and write one 32-bit data 85

Fetch-and-deposit DMA transfer 86