EECS 373 Design of Microprocessor-Based Systems Mark Brehob

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

Computer Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 5: Memory and Peripheral Busses September 21, 2010.
CSCI 4717/5717 Computer Architecture
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 6: AHB-Lite, Interrupts (1) September 18, 2014 Slides developed.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
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.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 7: Exceptions and Interrupts September 27, 2011.
Basic Input/Output Operations
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Memory-Mapped I/O, Bus Architectures January 20, 2015.
The 8051 Microcontroller and Embedded Systems
COMP201 Computer Systems Exceptions and Interrupts.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 5: Memory and Peripheral Busses September 20, 2011.
MICROPROCESSOR INPUT/OUTPUT
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Computer Architecture System Interface Units Iolanthe II approaches Coromandel Harbour.
Interrupts, Buses Chapter 6.2.5, Introduction to Interrupts Interrupts are a mechanism by which other modules (e.g. I/O) may interrupt normal.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 6: Interrupts Sept. 19 th 2013 Slides developed in part by.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 6: Interrupts January 30 th Slides developed in part by Prof.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
EEE440 Computer Architecture
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 4: Bit of ssembly, Memory-mapped I/O, APB January 21, 2014.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
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.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Module 11 Adapted By and Prepared James Tan © 2001.
EECS 373 Design of Microprocessor-Based Systems Prabal Dutta
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
CS 478: Microcontroller Systems University of Wisconsin-Eau Claire Dan Ernst Bus Protocols and Interfacing Bus basics I/O transactions MPC555 bus Reference:
Bus Protocols and Interfacing (adopted Steven and Marios’s slides) Bus basics I/O transactions MPC823 bus Reference: Chapter 13 of “White Book”
Copyright © 2007 by Curt Hill Interrupts How the system responds.
Chapter 3 System Buses.  Hardwired systems are inflexible  General purpose hardware can do different tasks, given correct control signals  Instead.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
Aditya Dayal M. Tech, VLSI Design ITM University, Gwalior.
Presented By Aditya Dayal ITM University, Gwalior.
Slides developed in part by Mark Brehob & Prabal Dutta
Interrupts and exceptions
Microprocessor Systems Design I
Slides developed in part by Mark Brehob & Prabal Dutta
EECS 373 Design of Microprocessor-Based Systems Prabal Dutta
Computer Architecture
EECS 373 Design of Microprocessor-Based Systems Prabal Dutta
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
Chapter 10 The Stack.
EECS 373 Design of Microprocessor-Based Systems Mark Brehob
EECS 373 Design of Microprocessor-Based Systems Mark Brehob
BIC 10503: COMPUTER ARCHITECTURE
Interrupts.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
COMP3221: Microprocessors and Embedded Systems
Lecture 12 Input/Output (programmer view)
EECS 373 Design of Microprocessor-Based Systems Prabal Dutta
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 5: Memory-mapped I/O review, APB, start interrupts. Mostly APB though  Sept 17th, 2013

Today Announcements Memory-mapped I/O and bus architecture review ARM’s APB bus in detail Start on interrupts

Announcements HW1a return Exam timing issues Can’t have in class. Need to pick night (ick) Office hours shifts (updated on website) Thursdays now 3:30-5:00 Mondays now 9:00-10:30

Reading Scan chapter 9.2 of LeeSeshia. I’d like you to read the whole thing but not worry too much about getting it all. Be aware their terminology is in some cases non-standard (but then so is everyones) They are software engineers, thinking about how software should be written for an embedded system. A higher-level of abstraction than we work at, but well worth seeing!

Today Announcements Memory-mapped I/O and bus architecture review ARM’s APB bus in detail Start on interrupts

The idea is really simple Memory-mapped I/O The idea is really simple Instead of real memory at a given memory address, have an I/O device respond. Huh? Example: Let’s say we want to have an LED turn on if we write a “1” to memory location 8. Further, let’s have a button we can read (pushed or unpushed) by reading address 4. If pushed, it returns a 1. If not pushed, it returns a 0.

Write assembly programs. LED on if button pressed LED off if button pressed

Now write button pressed=LED on in C. #define SW ((volatile uint32 *) 0x4) #define LED ((volatile uint32 *) 0x8) main(int argc, char * argv[]) { while(1) *LED=*SW; } What is uint32? Why volatile? What does that do? Could I get rid of the dereference in the code? Should I?

A different example… #include <stdio.h> #include <inttypes.h> #define REG_FOO 0x40000140 main () { uint32_t *reg = (uint32_t *)(REG_FOO); *reg += 3; printf(“0x%x\n”, *reg); // Prints out new value }

“*reg += 3” is turned into a ld, add, str sequence Load instruction A bus read operation commences The CPU drives the address “reg” onto the address bus The CPU indicated a read operation is in process (e.g. R/W#) Some “handshaking” occurs The target drives the contents of “reg” onto the data lines The contents of “reg” is loaded into a CPU register (e.g. r0) Add instruction An immediate add (e.g. add r0, #3) adds three to this value Store instruction A bus write operation commences The CPU indicated a write operation is in process (e.g. R/W#) The CPU drives the contents of “r0” onto the data lines The target stores the data value into address “reg”

Modern embedded systems have multiple busses Atmel SAM3U Expanded 373 focus Historical 373 focus

Any given transaction have an “initiator” and “target” Bus terminology Any given transaction have an “initiator” and “target” Any device capable of being an initiator is said to be a “bus master” In many cases there is only one bus master (single master vs. multi-master). A device that can only be a target is said to be a slave device. Some wires might be shared among all devices while others might be point-to-point connections (generally connecting the master to each target).

Today Announcements Memory-mapped I/O and bus architecture review ARM’s APB bus in detail Start on interrupts

APB is a fairly simple bus designed to be easy to work with. Low-cost Low-power Low-complexity Low-bandwidth Non-pipelined Ideal for peripherals

Let’s just look at APB writes (Master writing to device) as a starting point. We’ll add reads shortly.

Notation

PCLK PADDR PWRITE PWDATA APB bus signals Clock Address on bus 1=Write, 0=Read PWDATA Data written to the I/O device. Supplied by the bus master/processor.

APB bus signals PSEL PENABLE PREADY Asserted if the current bus transaction is targeted to this device PENABLE High during entire transaction other than the first cycle. PREADY Driven by target. Similar to our #ACK. Indicates if the target is ready to do transaction. Each target has it’s own PREADY

So what’s happening here?

Example setup For the next couple of slides, we will assume we have one bus master “CPU” and two slave devices (D1 and D2) D1 is mapped to address 0x00001000-0x0000100F D2 is mapped to 0x00001010-0x0000101F

Say the CPU does a store to location 0x00001004 with no stalls

What if we want to have the LSB of this register control an LED? Design a device which writes to a register whenever any address in its range is written What if we want to have the LSB of this register control an LED? PWDATA[31:0]   PWRITE PENABLE PSEL PADDR[7:0] PCLK PREADY 32-bit Reg D[31:0]   Q[31:0] EN   C We are assuming APB only gets lowest 8 bits of address here…

Reg A should be written at address 0x00001000 Reg B should be written at address 0x00001004 PWDATA[31:0]   PWRITE PENABLE PSEL PADDR[7:0] PCLK PREADY 32-bit Reg A D[31:0]   Q[31:0] EN   C 32-bit Reg B D[31:0]   Q[31:0] EN   C We are assuming APB only gets lowest 8 bits of address here…

Reads… The key thing here is that each slave device has its own read data (PRDATA) bus!

Let’s say we want a device that provides data from a switch on a read to any address it is assigned. (so returns a 0 or 1) PRDATA[31:0]   PWRITE PENABLE PSEL PADDR[7:0] PCLK PREADY Mr. Switch

Device provides data from switch A if address 0x00001000 is read from Device provides data from switch A if address 0x00001000 is read from. B if address 0x00001004 is read from PRDATA[31:0]   PWRITE PENABLE PSEL PADDR[7:0] PCLK PREADY Switch A Switch B

All reads read from register, all writes write… PWDATA[31:0]   PWRITE PENABLE PSEL PADDR[7:0] PCLK PREADY 32-bit Reg D[31:0]   Q[31:0] EN   C We are assuming APB only gets lowest 8 bits of address here…

A write transfer with wait states Setup phase begins with this rising edge Setup Phase Wait State Wait State Access Phase

A read transfer with wait states Setup phase begins with this rising edge Setup Phase Wait State Wait State Access Phase

Notice we are assuming that our device need not stall. Things left out… There is another signal, PSLVERR (APB Slave Error) which we can drive high if things go bad. We’ll just tie that to 0. Notice we are assuming that our device need not stall. We could stall if we needed. I can’t find a limit on how long, but I suspect at some point the processor would generate an error.

Verilog!

We’ll spend a bit more time on this next week… APB state machine IDLE Default APB state SETUP When transfer required PSELx is asserted Only one cycle ACCESS PENABLE is asserted Addr, write, select, and write data remain stable Stay if PREADY = L Goto IDLE if PREADY = H and no more data Goto SETUP is PREADY = H and more data pending We’ll spend a bit more time on this next week…

Today Announcements Memory-mapped I/O and bus architecture review ARM’s APB bus in detail Start on interrupts

Informs a program of some external events Breaks execution flow Interrupts Merriam-Webster: “to break the uniformity or continuity of” Informs a program of some external events Breaks execution flow Key questions: Where do interrupts come from? How do we save state for later continuation? How can we ignore interrupts? How can we prioritize interrupts? How can we share interrupts?

I/O Data Transfer Two key questions to determine how data is transferred to/from a non-trivial I/O device: How does the CPU know when data is available? Polling Interrupts How is data transferred into and out of the device? Programmed I/O Direct Memory Access (DMA)

Interrupts Interrupt (a.k.a. exception or trap): An event that causes the CPU to stop executing the current program and begin executing a special piece of code called an interrupt handler or interrupt service routine (ISR). Typically, the ISR does some work and then resumes the interrupted program. Interrupts are really glorified procedure calls, except that they: can occur between any two instructions are transparent to the running program (usually) are not explicitly requested by the program (typically) call a procedure at an address determined by the type of interrupt, not the program

Two basic types of interrupts (1/2) Those caused by an instruction Examples: TLB miss Illegal/unimplemented instruction div by 0 Names: Trap, exception

Two basic types of interrupts (2/2) Those caused by the external world External device Reset button Timer expires Power failure System error Names: interrupt, external interrupt

Something tells the processor core there is an interrupt How it works Something tells the processor core there is an interrupt Core transfers control to code that needs to be executed Said code “returns” to old program Much harder then it looks. Why?

… is in the details How do you figure out where to branch to? How to you ensure that you can get back to where you started? Don’t we have a pipeline? What about partially executed instructions? What if we get an interrupt while we are processing our interrupt? What if we are in a “critical section?”

Where If you know what caused the interrupt then you want to jump to the code that handles that interrupt. If you number the possible interrupt cases, and an interrupt comes in, you can just branch to a location, using that number as an offset (this is a branch table) If you don’t have the number, you need to poll all possible sources of the interrupt to see who caused it. Then you branch to the right code

Get back to where you once belonged Need to store the return address somewhere. Stack might be a scary place. That would involve a load/store and might cause an interrupt (page fault)! So a dedicated register seems like a good choice But that might cause problems later…

Snazzy architectures A modern processor has many (often 50+) instructions in-flight at once. What do we do with them? Drain the pipeline? What if one of them causes an exception? Punt all that work Slows us down What if the instruction that caused the exception was executed before some other instruction? What if that other instruction caused an interrupt?

If we get one interrupt while handling another what to do? Nested interrupts If we get one interrupt while handling another what to do? Just handle it But what about that dedicated register? What if I’m doing something that can’t be stopped? Ignore it But what if it is important? Prioritize Take those interrupts you care about. Ignore the rest Still have dedicated register problems.

We probably need to ignore some interrupts but take others. Critical section We probably need to ignore some interrupts but take others. Probably should be sure our code can’t cause an exception. Use same prioritization as before.

Over 100 interrupt sources Our processor Over 100 interrupt sources Power on reset, bus errors, I/O pins changing state, data in on a serial bus etc. Need a great deal of control Ability to enable and disable interrupt sources Ability to control where to branch to for each interrupt Ability to set interrupt priorities Who wins in case of a tie Can interrupt A interrupt the ISR for interrupt B? If so, A can “preempt” B. All that control will involve memory mapped I/O. And given the number of interrupts that’s going to be a pain in the rear.

Enabling and disabling interrupt sources

How to know where to go on an interrupt.