U of U ECE 3720 - Lecture 6 - Interrupt Synchronization
Pages 7

Unformatted text preview:

Slide 1'&$%ECE/CE 3720: Embedded System DesignChris J. MyersLecture 6: Interrupt SynchronizationSlide 2'&$%Introduction• Interrupts provide guarantee on response time.• Interrupts allow response to rare but important events.• Periodic interrupts used for data aquisition and control.• Interrupts can provide a way to buffer I/O data.1Slide 3'&$%What are Interrrupts?• An automatic transfer of software execution in responseto hardware that is asynchronous with current software.• Hardware can be external I/O device or internal event.• When hardware needs service, it requests an interrupt.• Calls interrupt service routine as a background thread.• Thread is terminated with rti instruction.• Threads may communicate using FIFO queues andsynchronize using semaphores.• Threads share global variables while processes do not.• Each potential interrupt has separate arm bit.• Interrupt enable bit, I, found in condition code.Slide 4'&$%Shared versus Dedicated(See Figures 4.1 and 4.2)2Slide 5'&$%Shared versus Dedicated• Wire- or negative-logic interrrupt requests:1. Can add additional I/O devices w/o redesigning H/W.2. No limit to number of interrupting I/O devices.3. Microcomputer hardware is simple.• Dedicated edge-triggered interrupt requests:1. Software is simpler, easier to debug, and faster.2. Less coupling between software modules.3. Easier to implement priority.Slide 6'&$%Interrupt Service Routines (ISR)• Software executed when hardware requests an interrupt.• Polled interrupts - one large ISR handles all requests.• Vectored interrupts - many small, specific ISRs.• When the device is armed, the I bit is zero, and aninterrupt is requested, it is serviced as follows:1. Execution of main program is suspended.2. All registers are pushed onto the stack.3. The ISR, or background thread, is executed.4. The ISR executes rti instruction.5. All registers are restored from the stack.6. The main program is resumed.3Slide 7'&$%Interrupt Execution(See Figure 4.3)Slide 8'&$%When to Use InterruptsGadfly Interrupts DMAPredicatable Variable arrival times Low latencySimple I/O Complex I/O High bandwidthFixed load Variable loadSingle thread MultithreadNothing else to do Infrequent alarmsProgram errorsOverflow, illegal opIllegal memory accessMachine/memory errorsPower failureReal-time clocksData acquisition/control4Slide 9'&$%Interthread Communication• Interrupt threads have logically separate registers/stack,so communication must occur through global memory.(See Figure 4.4)Slide 10'&$%Input Device Interrupts(See Figures 4.5, 4.6, and 4.7)5Slide 11'&$%Output Device Interrupts(See Figures 4.8, 4.9, and 4.10)Slide 12'&$%Other Interrupt Issues1. Periodic interrupts are neither input or output.2. Essential for data acquisition and control systems.3. ISR should only occur when needed, come in clean,perform function, and return right away.4. Gadfly loops and iterations should be avoided in ISRs.5. Percent of time in ISRs should be minimized.6. Interface latency is time between new input available andwhen software reads the input data.7. device latency is response time of external I/O device.8. A real-time system guarantees bound on interface latency.6Slide 13'&$%Reentrant Programming• A program segment is reentrant if it can be concurrentlyexecuted by two (or more) threads.• Reentrant software must place local variables on stack.• A nonreentrant subroutine has a section of code called avulnerable window or critical section, and error occurs if:1. One thread calls the nonreentrant subroutine,2. That thread is executing in the “vulnerable” windowwhen interrupted by a second thread, and3. Second thread calls same sub or shared variable.• Need to implement mutual exclusion which is typicallydone by disabling interrupts.Slide 14'&$%Nonrentrant Subroutine in AssemblySecond rmb 2 Temporary global variable* Input parameters: Reg X,Y contain 2 16 bit numbers* Output parameter: Reg X is returned with the averageAVE sty Second Save the second number in memoryxgdx Reg D contains first numberaddd Second Reg D=First+Secondlsrd (First+Second)/2adcb #0 round up?adca #0xgdxrts7Slide 15'&$%Bad Sequence of Events(See Figure 4.11)Slide 16'&$%Nonrentrant Subroutine in Cint Result; /* Temporary global variable */int AVE(int x,y){Result = y; /* Save second number */Result = (Result + x) >> 1; /* (1st+2nd)/2 */return(Result);}(See Figure 4.12)8Slide 17'&$%Atomic Operations• Atomic operation is one that once started is guaranteedto finish.• In most computers, machine instructions are atomic.• The following is atomic:inc counter where counter is global variable• The following is nonatomic:ldaa counter where counter is global variableincastaa counterSlide 18'&$%Read-Modify-Write Example1. Software reads global variable, producing a copy of the data.2. Software modifies the copy.3. Software writes modification back into global variable.unsigned int Money; /* bank balance (global) *//* add 100 dollars */void more(void){Money += 100;}Money rmb 2 bank balance implemented as a global* add 100 dollars to the accountmore ldd Money where Money is a global variableaddd #100std Money Money=Money+100rts9Slide 19'&$%Write Followed by Read Example1. Software writes to a global variable.2. Software reads from global variable expecting original data.int temp; /* global temporary *//* calculate x+2*d */int mac(int x, int d){temp = x+2*d; /* write to a global variable */return (temp);} /* read from global */temp rmb 2 global temporary result* calculate RegX=RegX+2*RegDmac stx temp Save X so that it can be addedlsld RegD=2*RegDaddd temp RegD=RegX+2*RegDxgdx RegX=RegX+2*RegDrtsSlide 20'&$%Nonatomic Multistep Write1. Software write part of new value to a global variable.2. Software write rest of new value to a global variable.int info[2]; /* 32-bit global */void set(int x, int y){info[0]=x;info[1]=y;}Info rmb 4 32-bit data implemented as a global* set the variable using RegX and RegYset stx Info Info is a 32 bit global variablesty Info+2rts10Slide 21'&$%Make a Subroutine Reentrant Using a Stack Variable* Input parameters: Reg X,Y contain 2 16 bit numbers* Output parameter: Reg X is returned with the averageAVE pshy Save the second number on the stacktsy Reg Y points the Second numberxgdx Reg D contains first numberaddd 0,Y Reg D=First+Secondlsrd (First+Second)/2adcb #0 round up?adca #0xgdxpulyrtsSlide 22'&$%A Nonreentrant SubroutineStatus rmb 1 0 means empty, -1 otherwiseMessage rmb 1 data to be


View Full Document

U of U ECE 3720 - Lecture 6 - Interrupt Synchronization

Course: Ece 3720-
Pages: 7
Download Lecture 6 - Interrupt Synchronization
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 Lecture 6 - Interrupt Synchronization 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 Lecture 6 - Interrupt Synchronization 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?