[email protected]
Mohamed Mediouni
1
Interrupt Handling Interrupt is just a particular exception • Caught by kernel code • Dealt with prior to resuming user code • But hardware is independent of OS
1. Interrupt Occurs
Vector Table Vector1
2
Status Register
PSR
ISR NN ISR
.
.
.
.
.
.
IDT- Vector table
Driver is assigned interrupt by the PNP manager Driver registers with kernel it’s ISR When IRQ fires, IDT table links the IRQ to the ISR
• •
ISR code must set PIC IRQ mask handles PIC EOI
ISR
.
.
Lightweight code to quiet interrupt 3
.
IISR Kernel OAL
Except. Handler
.
Vector 0 Vector2
Vector N VectorN
Memory
Driver
2. Exception Handler fetchs Status register & 3. links IRQ to ISR based on IDT (registered ISR)
App
Memory
HW
1
None Mohamed Mediouni
2
App
2. Exception Handler fetchs Status register & 3. links IRQ to ISR
Driver registers IISR DLL with the Kernel with the call to LoadIntChainHandler()
Support for hardware IRQ sharing Distinct SYSINTR ID from same IRQ
Driver
1. Interrupt Occurs
4. ISR decodes IRQ from hardware, calls kernel to query IISRs in binding order
SYSINTR_CHAIN
PSR
SYSINTR_xx SYSINTR_NOP
4
3
NKCallIntChain(IRQ)
2
ISR
None
Higher Priority IRQs Enabled Mohamed Mediouni
HW
1
Kernel OAL
Except. Handler
IISRn IRQ go away
IISR2
IISR
IISR1
3
App
5. IISR scheduled code to service hardware and return value indicates status
6. IRQ go away
Driver
1. Interrupt Occurs
2. Exception Handler fetchs Status register & 3. links IRQ to ISR 4. ISR decodes IRQ, calls kernel to query IISRs
SYSINTR_CHAIN
IISR2
IISR
IISR1
IISRn
Except. Handler
SYSINTR_xx SYSINTR_NOP
PSR
2
4NKCallIntChain(IRQ)
3
ISR
Higher Priority IRQs Enabled ( Mohamed Mediouni
HW
None
6
Kernel OAL
5
4
App
6. IISR return value indicates status SYSINTR_CHAIN indicates IRQ not recognized OAL ISR translates IRQ to SYSINTR as before SYSINTR_NOP indicates IISR run-to-completion IISR must make IRQ go away! Other values indicate IISR owns interrupt OAL ISR code must set PIC IRQ mask
7. ISR handles PIC EOI and returns ID
Driver
1. Interrupt Occurs
2. Exception Handler fetchs Status register & 3. links IRQ to ISR 4. ISR decodes IRQ, calls kernel to query IISRs 5. IISRs service hardware and return status
SYSINTR_CHAIN
5
Except. Handler PSR
SYSINTR_xx SYSINTR_NOP
IISRn 6
Set Event
4
3
NKCallIntChain(IRQ)
7
SYSINTR_ID
ISR
Kernel OAL
1
IISR2
IISR
IISR1
2 Higher Priority IRQs Enabled Mohamed Mediouni
IRQ Masked
HW
None
5
App
6. IISR return value indicates status SYSINTR_CHAIN indicates IRQ not recognized OAL ISR translates IRQ to SYSINTR as before SYSINTR_NOP indicates IISR run-to-completion IISR must make IRQ go away! Other values indicate IISR owns interrupt OAL ISR code must set PIC IRQ mask
7. ISR handles PIC EOI and returns ID
IISR1
5
Except. Handler PSR
SYSINTR_xx SYSINTR_NOP
IISRn
8
6
Set Event
4
3
NKCallIntChain(IRQ)
7
SYSINTR_ID
ISR
Kernel OAL
1
IISR2
IISR
8. Kernel signals event, IST becomes runnable
SYSINTR_CHAIN
Driver
1. Interrupt Occurs
2. Exception Handler fetchs Status register & 3. links IRQ to ISR 4. ISR decodes IRQ, calls kernel to query IISRs 5. IISRs service hardware and return status
2 Higher Priority IRQs Enabled Mohamed Mediouni
IRQ Masked
HW
None
6
2. Exception Handler fetchs Status register & 3. links IRQ to ISR
App
4. ISR decodes IRQ, calls kernel to query
1. Interrupt Occurs
Driver
IISRs 5. IISRs service hardware and return status 6. IISR return value indicates status
8. Kernel signals event, IST becomes runnable 9. Scheduler runs the IST 10. IST runs and resets the IST interrupt
7. ISR handles PIC EOI and returns ID
Except. Handler PSR
4
3
NKCallIntChain(IRQ)
7
8
SYSINTR_ID
ISR
Kernel OAL
1
IISR
IISR1
11. IST Creates an event object associated with IISRn the logical 6 5 interrupt by calling CreateEvent Set function Event (as Event Source)
2 Higher Priority IRQs Enabled Mohamed Mediouni
IRQ Masked
HW
None
7
Fitting It All Together
Interrupt Occurs
Interrupt Handler calls registered ISR
ISR runs, tells kernel which event to signal
IST runs and resets the interrupt
Scheduler runs the IST
Kernel signals event, IST becomes runnable
Mohamed Mediouni
8
Event-driven architecture IST as Event dispatcher –( JRE)
10
9
11
1
8 KERNEL: Set Event IST: registered within the Kernel 2. event fired
(JRE)
1. add listener
IST as source of events dispatches Event Object to Application Listener objects which invoke the event handler Mohamed Mediouni
Dispatcher
to IST as source of Events
3. Look up Handler
4. Send to Handler 9
Executing events Application Event handler IST (within JRE) KERNEL: Set Event
Events queue
Events dispatcher
Event handler
Interruptenqueue(event) Interruptenqueue(event)
dequeue() event
handle(event)
dequeue() event
Mohamed Mediouni
handle(event)
10
4 Steps 1st step: Create sources of events (ex. two buttons)
2nd step: Add the sources (ex. buttons) to the frame 3rd step: Register listeners to the sources
4th step: Implement handler
Mohamed Mediouni
11
public class TestActionEvent extends Jframe implements ActionListener { // 1st step: Create sources of events (two buttons) private JButton jbtOK = new Jbutton(“OK”); private JButton jbtCL = new Jbutton(“Cancel”); // Constructor public TestActionEvent () { setTitle(); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); // 2nd step: Add the sources (buttons) to the frame cp.add(jbtOK); cp.add(jbtCL); // 3rd step: Register listeners to the sources; jbtOK.addActionListener(this); jbtCL.addActionListener(this);
}
Mohamed Mediouni
12
// 4th step:implement handler public void actionPerformed(ActionEvent e) { if(e.getSource() == jbtOK) { System.out.println(“The OK button is clicked”); } if(e.getSource() == jbtCL) { System.out.println(“The Cancel button is clicked“); }// actionPerformed }
Test Application public static void main(String[] args) { TestActionEvent frame = new TestActionEvent(); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); frame.setSize(100,100); frame.setVisible(true); }//main }// class Mohamed Mediouni
13