Timer and Interrupts.

Slides:



Advertisements
Similar presentations
CPU Structure and Function
Advertisements

ECE 353 Introduction to Microprocessor Systems
Lab III Real-Time Embedded Operating System for a SoC System.
Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
CSCI 4717/5717 Computer Architecture
Chapter 12: Software interrupts (SWI) and exceptions
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
A look at interrupts What are interrupts and why are they needed in an embedded system? Equally as important – how are these ideas handled on the Blackfin.
A look at interrupts What are interrupts and why are they needed.
ARM 7 Datapath. Has “BIGEND” input bit, which defines whether the memory is big or little endian Modes: ARM7 supports six modes of operation: (1) User.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
Exception and Interrupt Handling
Introduction to Embedded Systems
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
ARM Timers.
System Clocks.
CORTEX-M0 Structure Discussion 2 – Core Peripherals
MSP430 Mixed Signal Microcontroller – Parte 2 Afonso Ferreira Miguel Source: slau056d – Texas instruments.
MICROPROCESSOR INPUT/OUTPUT
Introduction to Embedded Systems Rabie A. Ramadan 6.
ECE 353 Introduction to Microprocessor Systems Discussion 11.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
AT91 Interrupt Handling. 2 Stops the execution of main software Redirects the program flow, based on an event, to execute a different software subroutine.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
MICROPROCESSOR DETAILS 1 Updated April 2011 ©Paul R. Godin prgodin gmail.com.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Interrupt 마이크로 프로세서 (Micro Processor) 2015년 2학기 충북대학교 전자공학과 박 찬식
1 Computer System Overview Chapter 1. 2 Operating System Exploits the hardware resources of one or more processors Provides a set of services to system.
Chapter 12: Software interrupts (SWI) and exceptions
HCS12 Exceptions Maskable Interrupts
Interrupts and exceptions
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Homework Reading Machine Projects Labs
Interrupts In 8085 and 8086.
Programmable Interval Timer
Chapter 10 And, Finally... The Stack
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
Chapter 10 The Stack.
Computer System Overview
Interrupts Interrupt is a process where an external device can get the attention of the microprocessor. The process starts from the I/O device The process.
Real-Time Embedded Operating System for a SoC System
BIC 10503: COMPUTER ARCHITECTURE
Chapter 12: Software interrupts (SWI) and exceptions
COMPUTER PERIPHERALS AND INTERFACES
Architectural Support for OS
Interrupts.
Chapter 10 And, Finally... The Stack
Interrupts and Exception Handling
Computer Architecture
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Wireless Embedded Systems
ARM Introduction.
Computer System Overview
Architectural Support for OS
CPU Structure and Function
Chapter 11 Processor Structure and function
COMP3221: Microprocessors and Embedded Systems
Interrupts and Exception Handling
Interrupts & Syscalls.
Presentation transcript:

Timer and Interrupts

clock (external or internal) General Purpose Timer The basic unit – counter (up or down) a clock source generate timing events (interrupts or timer output) if overflow or reach 0 if match with a preset value measure time – read counter values (captured) free running, reset or reload, compare clock (external or internal) 32 bit counter control circuit

input capture register Measurement Input-capture : identify the moment that an event occurs latch the counter value when triggered CPU can read the value later Output compare : control the timing of output bit CPU sets a value in output compare register compare with counter every clock cycle if equal, send an output signal External event counting Measuring elapsed time, pulse width, frequency, and period 32 bit counter input capture register clock load interrupt or ready flag event edge detection

Hardware Timer Typical approach – hardware unit generates an interrupt per unit of time (e.g. millisecond) Avoid overflow with a software counter (in memory) – incremented when interrupts assume the input clock of 2MHz (0.5x10-3 ms) set a compare counter to 1999 start counting with the input clock and, when equals to the compare register interrupt restart the counter from 0 interrupt or toggle output = 32 bit counter input clock (2MHz) restart compare register (1999)

DB-MX1: General Purpose Timer Maximum period of 512x65536 seconds at 32.768kHz or 436x65536 seconds at 38.4kHz 10ns resolution at 100MHz Programmable sources for the clock input, including external clock Input capture capability with programmable trigger edge Output compare with programmable mode Free-run and restart modes

GP Timer Module Registers Control register SW_reset, free-run/restart, capture edge, output mode, IRQ_en, clk_source, timer_en Counter, capture, compare registers Prescale register Status register (capture and compare events)

Waveform Generator Instead of interrupt, using a clock to generate a waveform To generate a square wave of 9600Hz, what value should be loaded into the comparator when the input clock is 10MHz? How to generate a waveform with a specific duty cycle 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3

Pulse Width Measurement Capture counter values on edges Read the difference to know the width If the pulse is much longer, counter may overflow set value 0xFFFFFFF on compare register and use software counter to count number of overflows. start counting stop counting

Exceptions and Interrupts in ARM The processor is usually in user mode, and enters one of the exception modes when an unexpected event occurs. There are three different types of exceptions (some are called interrupts): - As a direct result of executing an instruction, such as: Software Interrupt Instruction (SWI) Undefined or illegal instruction Memory error during fetching an instruction As a side- effect of an instruction, such as: Memory fault during data read/ write from memory Arithmetic error (e. g. divide by zero) As a result of external hardware signals, such as: Reset Fast Interrupt (FIQ) Normal Interrupt (IRQ)

When an Exception Occurs ARM completes current instruction as best as it can, and departs from current instruction sequence to handle the exception by performing the following steps: - changes the operating mode corresponding to the particular exception. saves the current PC in the r14 corresponding to the new mode. For example, if FIQ occurs, the PC value is stored in r14( FIQ). saves the old value of CPSR in the Saved Processor Status Register of the new mode. disables exceptions of lower priority (to be considered later). forces the PC to a new value corresponding to the exception. This is effectively a forced jump to the Exception Handler or Interrupt Service Routine .

Exception Vector Address Each vector (except FIQ) is 4 bytes long (i. e. one instruction) You put a branch instruction at this address: B exception_ handler ; or LDR PC, IRQ_Addr FIQ is special in two ways: - the actual FIQ handler can be put at 0x0000001C onwards, because FIQ vector occupies the highest address FIQ has many more shadow registers. So you don’t have to save as many registers on the stack as other exceptions - faster.

Exception Return The handler program (or Interrupt Service Routine) must restore the user state exactly as it was before the exception occurred: Any modified user registers must be restored from the handler’s stack The CPSR must be restored from the appropriate SPSR PC must be changed back to the instruction address in the user instruction stream The return address was saved in r14 before entering the exception handler To return from a SWI or undefined instruction trap, use: MOVS pc, r14 To return from an IRQ, FIQ or prefetch abort, use: SUBS pc, r14, #4 To return from a data abort to retry the data access, use: SUBS pc, r14, #8 The ‘S’ modifier is NOT used to set the flags, but instead to restore the CPSR

Interrupts in Dragonball MX1 Interrupt sources  interrupt controller (AITC)  ARM core peripheral modules – timer, UART, etc. external interrupts forced interrupts (by software) AITC supports up to 64 interrupt sources maskable configurable (fast or normal) software controlled priority Low interrupt latency

ISR in Dragonball MX1 Vector table FUNCT vect_IRQ[64] = {norm_source00_isr, …., norm_source63_isr] ; void norm_scr00_isr(void) // norm_scr00_isr (0) { if((NIPNDL & 0x00000001) == 0) { } //verify interrupt source if(((NIPRIORITY0)&0xF)!=(NIVECSR&0xF)) { } //verify interrupt priority … } Set up IRQ handler read NIVECSR to determine the source of interrupt void __irq IRQ_Handler(void) short vectNum; vectNum = NIVECSR >> 16; // determine highest pending normal interrupt vect_IRQ[vectNum](); // find the pointer to correct ISR in the // look up table