TAMU ECEN 449 - Microprocessor System Design

Unformatted text preview:

1Texas A&M UniversityECEN 449 – Microprocessor System DesignHardware-Software Communication2Texas A&M UniversityObjectives of this Lecture Unit• Learn basics of Hardware-Software communication• Memory Mapped I/O• Polling/Interrupts3Texas A&M UniversityMotivation• Many reasons why we want hardware devices to interact with software programs– Input: keyboards, mice, scanners– Output: CRT, printer– Interact with real world: contact sensor, chemical analyzer, MEMS devices– Performance: ASIC/System-on-chip designs• Many applications require more compute power, compute-per-dollar, or compute-per-watt than microprocessors can deliver• Exploit 90-10 rule of software by implementing critical parts of application in HW, non-critical as SW– Issue: embedded apps getting more complex, less likely to have one module that consumes most of the execution time.4Texas A&M UniversityHardware-Software Interfaces• What features do we want?5Texas A&M UniversityHardware-Software Interfaces• What features do we want?– Some way to get data between HW and SW components– Some way for HW to notify SW of asynchronous events– Flexibility• Don’t want to have to have special HW in CPU for each device• Only load SW into memory for devices that are present– Bandwidth• Demands may vary wildly: compare keyboard to Gb Ethernet– Security:• Multiple users/processes may need to share HW6Texas A&M UniversityGetting Data to/from CPU: Hardware SideProcessorI/O BusI/O DeviceI/O DeviceProcessorI/O DeviceI/O DeviceI/O DeviceI/O DeviceI/O DeviceNaïve Direct connectionCSCS7Texas A&M UniversityThe Software Side: Memory-Mapped I/OOperatingSystemAddress SpaceI/O DeviceMemory and ControlRegistersmmap()call8Texas A&M UniversityMemory-Mapped I/O• Basic Idea – Make control registers and I/O device memory appear to be part of the system’s main memory– Reads and writes to that region of the memory are translated by OS/hardware into accesses of hardware device– Makes it easy to support variable numbers/types of devices – just map them onto different regions of memory• Managing new devices is now like memory allocation• Example: accessing memory on a PCMCIA card– Once card memory mapped into address space, just hand out pointers like conventional memory– Accessing I/O device registers and memory can be done by accessing data structures via the device pointers• Most device drivers are now written in C. Memory mapped I/O makes it possible without special changes to the compiler9Texas A&M UniversityMemory-Mapped I/O• Important abstraction– A given processor may have multiple busses/connections to devices• Ex: PPC in Virtex-II Pro has OCM bus to talk to BlockRAM, PLB bus to talk to other hardware, but they look the same once you call mmap()• Can interact a bit oddly with caches– References to memory-mapped addresses may not go to the right bus if the address is cached– Solution: declare any data structures that are memory-mapped I/O regions as volatile• Ex: volatile int *region;• Tells system that it can’t keep the address in the cache10Texas A&M UniversityHandling Asynchronous Events• Issue: External devices operate on different time signals than processor– Humans don’t have clock rates• Want:– Way to let processor handle events on external hardware that it can’t predict– Processor to be able to do other things while it’s waiting for an event– Fast response to events– Low overhead (few wasted CPU cycles when no event happens)11Texas A&M UniversityAlternative 1: Polling• Every so often, processor checks each device to see if it has a request– Takes CPU time even if no requests pending– Tradeoff between overhead and average response time– How does software know when to let the system poll?12Texas A&M UniversityAlternative 2: Interrupts• Give each device a wire (interrupt line) that it can use to signal the processor– When interrupt signaled, processor executes a routine called an interrupt handler to deal with the interrupt– No overhead when no requests pendingProcessorDeviceInterruptControllerDeviceDeviceDevice13Texas A&M UniversityPolling vs. Interrupts“Polling is like picking up the phone every few seconds to see if you have a call. Interrupts are like waiting for the phone to ring”• Interrupts are better if the processor has other work to do and the time to respond to events isn’t absolutely critical• Polling can be better if the processor has nothing better to do and has to respond to an event ASAPPerformance of interrupt hardware is a critical factor on processors for embedded systems.14Texas A&M UniversitySo, What Happens When an Interrupt Occurs?Acts a lot like a context switch.• Interrupt controller signals processor that interrupt has occurred, passes interrupt number• Processor uses interrupt number to determine which handler to start– interrupt vector associates handlers with interrupts• Processor halts current program– Multi-cycle operations may be halted or squashed and restarted• Current program state saved (like context switch)• Processor jumps to interrupt handler• When interrupt done, program state reloaded and program resumes• Interrupts are assigned priorities to handle simultaneous interrupts15Texas A&M UniversityExample: Interrupts on 80386EX• 80386 core has one interrupt line, one interrupt acknowledge line• Interrupt sequence:– Interrupt controller raises INT line– 80386 core pulses INTA line low, allowing INT to go low– 80386 core pulses INTA line low again, signaling controller to put interrupt number on data busINT:INTA:Data bus:Interrupt #16Texas A&M UniversityUsing Interrupts in Linux• OS handles interaction with interrupt hardware– Necessary to support multiple processor types• You need to worry about three things1. Writing the interrupt handler2. Registering the interrupt handler with the OS• Tells the OS that it should run the handler when the interrupt occurs3. Interaction between the interrupt handler and user programs• Handlers need to be run in very little time • Handlers run as part of the operating system– Linux doesn’t allow them to access user data• One general approach: User program does the work, interrupt handler just signals it when it’s time to do something17Texas A&M UniversityInterrupts in Linux, Part II• Documentation on interrupts, etc. in Linux: http://www.xml.com/ldd/chapter/book/index.html– Entire Linux Device


View Full Document

TAMU ECEN 449 - Microprocessor System Design

Download Microprocessor System Design
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Microprocessor System Design and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Microprocessor System Design 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?