Sunteți pe pagina 1din 9

DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM

Ports A and B with no interrupt generation and interrupt service (handling)


mechanism:

Port A be in a PC, and port B be its modem input which puts the characters on
the telephone line.
Let In_A_Out_B be a routine that receives an input-character from Port A and
retransmits the character to Port B output.
Has to cyclically call the following steps a to e and executes the cycles of
functions i to v, thus ensuring the modem port A does not miss reading the
character

DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM

Interrupt and Interrupt Service Routine Concept:

Interrupt means event, which invites attention of the processor on occurrence


of some action at hardware or software interrupt instruction event
In response to the interrupt, the routine or program, which is running presently
interrupts and an interrupt service routine (ISR) executes
ISR is also called device driver in case of the devices and called exception or
signal or trap handler in case of software interrupts

Interrupt approach for the port or device functions :


Processor executes the program, called interrupt service routine or signal
handler or trap handler or exception handler or device driver, related to input
or output from the port or device or related to a device function on an
interrupt and does not wait and look for the input ready or output completion
or device-status ready or set

Types of interrupt
1. Hardware interrupt
2. Software interrupt
Hardware interrupt:

Examples of interrupts
1. When a device or port is ready
2. a device or port generates an interrupt
3. when it completes the assigned action
4. when a timer overflows
5. when a time at the timer equals a preset time in a compare register or on
setting a status flag (for
6. example, on timer overflow or compare or capture of time)
7. on click of mouse in a computer
Hardware interrupt generates call to an ISR

Software Interrupt:
When software run-time exception condition (for examples, In 8086 processor-
division by 0 or overflow or illegal opcode detected) the processor-hardware
generates an interrupt, called trap, which calls an ISR
When software run-time exception condition defined in a program occurs, then
a software instruction (SWI) is executed called software interrupt or exception or
signal, which calls an ISR
When a device function is to be invoked, for example, open (initialize/configure)
or read or write or close , then a software instruction (SWI) is executed called
software interrupt to execute the required device driver function for open or read
or write or close operations
Software can execute the software instruction (SWI) or Interrupt n (INT n) to
signal execution of ISR (interrupt service routine). The n is as per the handler
address.
Signal interrupt [The signal differs from the function in the sense that
execution of signal handler (ISR) can be masked and till mask is reset, the
handler will not execute on interrupt. Function on the other hand always
executes on the call after a call-instruction.]

Routine (function) and ISR call features:


On a function call, the instructions are executed from a new address Execute like in
as function in the C or in a method in Java.
ISR also the instructions are executed from a new address like in as function in the
C or in a method in Java
A function call is after executing present instruction in any program and is a
planned (user Programmed) diversion from the present instruction in sequence
of instructions to another sequence of instructions; this sequence of
instructions executes till the return from that.
An ISR call is after executing present instruction in any program and is
interrupt related diversion from the current sequence of instructions to
another sequence of instructions; this sequence of instructions executes till
the return from that or till another interrupt of higher priority

Nesting of function calls and ISRs:


Nesting the function-calls When a function 1 calls another function 2 and
that call another function 3, on return from 3, the return is to function 2 and
return from 2 is to function. Functions are said to be nested
The ISR calls in case of multiple interrupt occurrences can be nested or can
be as per priority of the interrupts
Interrupt driven IO and device accesses feature:
There is no continuous monitoring of the status bits or polling for status by the
application.
2. Between two interrupt calls the program task(s) continue. There are many
devicefunctions,
and each of which executes on a device interrupt

Example: - An automatic chocolate vending machine (ACVM)


Without interrupt mechanism, one way is the programmed I/O- transfer in
which that the device waits for the coin continuously, activates on sensing the
coin and runs the service routine
In the event driven way is that the device should also awakens and activates
on each interrupt after sensing each coin-inserting event
The system awakens and activates on an interrupt through a hardware or
software signal. The system on port interrupt collects the coin by running a
service routine. This routine is called interrupt handler routine for the coin-port

read.
Software Interrupts and Interrupt Service routines:
Software Interrupt (Throw an Exception) Concept:
A program needs to detect error condition or run time exceptional condition encountered during
the running
In a program either the hardware detects this condition or in a program
detects this condition, then an instruction SWI (software interrupt) is used
Called throwing an exception by the program.
An interrupt service routine (exceptional handler routine) executes, which is
called catch function as it executes on catching the exception thrown.
Executes on detecting the exceptional runtime condition during computations or communication
For example, on detecting that the square root of a negative number is being calculated or
detecting illegal argument in the function or detecting that connection to network not found.
The SWI (software interrupt) instructions in 8086 microprocessor , SWI a1 and SWI a2 will be
inserted for trapping (A- B) as ve number and trapping y > 100 or less than 0
Program:

Try{
If(A-B) <0.1) {
throw a1;
X=y+sqrt(A-B);
y = . // calculate y
}
If ( ( y > 100) | | ( y<0 ) ) {
throw a2;
}
}
Software instruction SWI a1
Causes processor interrupt.
In response, the software ISR function catch (Exception_1 a1) { } executes on throwing of the
exception a1 during try block execution.
SWI a1 is used after catching the exception a1 whenever it is thrown

Software instruction SWI a2


Causes processor interrupt.
In response, the software ISR function catch (Exception_1 a2) { } executes on throwing of the
exception a2 during try block execution.
SWI a2 is used after catching the exception a2 whenever it is thrown
Interrupt Service Threads as Second Level Interrupt Handlers:

ISR is executed in two parts


One part is short execution time service routine
Runs the critical part of the ISR and passes a signal or message to the OS for running the
remaining second part later
1. First level ISR (FLISR)
First part does the device dependent handling only. For example, it does not perform data
decryption of data received from the network. It simply does the transfer of data to the memory
buffer for the device data
Second part waits during execution of the interrupts of lesser priority.

2. Second level ISR (SLISR)


Second part is long service routine
The OS schedules the IST as per its priority.
Does the device independent handling.
IST is also the software interrupt, when it is triggered by an SWI (software interrupt instruction)
[Signal] in FLISR

DEVICE DRIVER:
A device driver has a set of routines (functions) used by a high-level language
programmer, which does the interaction with the device hardware, sends control
commands to the device, communicates data to the device and runs the codes for
reading device data
Each device in a system needs device driver routine with number of device
functions.
An ISR relates to a device driver command (device-function). The device driver
uses SWI to call the related ISR (device-function routine)
The device driver also responds to device hardware interrupts.
A programmer uses generic commands for device driver for using a device. The
operating system provides these generic commands.
Each command relates to an ISR. The device driver command uses an SWI to call
the related ISR device-function routine)
Generic functions used for the commands to the device are device create ( ), open ( ),
connect ( ), bind ( ), read ( ), write ( ), ioctl () [for IO control], delete ( ) and close ( ).
Device driver code is different in different operating system.
Same device may have different code for the driver when system is using different
operating system
Does the interrupt service for any event related to the device and use the system and
IO buses required for the device service.
Device driver can be considered software layer between an application program and
the device
An Interrupt service routine (ISR) accesses a device for service (configuring,
initializing, activating, opening, attaching, reading, writing, resetting, deactivating or
closing).
Interrupt service routines thus implements the device functions of the device driver

INTERRUPT SOURCES:
HARDWARE SOURCES OF INTERRUPTS:
Hardware sources can be internal or external for interrupt of ongoing routine.
The internal sources from devices differ in different processor or
microcontroller families
External sources and ports also differ in different processors or
microcontrollers

Internal Hardware Device Sources

1. Parallel Port
2. UART Serial Receiver Port - [Noise, Overrun, Frame-Error, IDLE, RDRF in 68HC11]
3. Synchronous Receiver byte Completion
4. UART Serial Transmit Port-Transmission Complete [e.g. TDRE (transmitter data
register Empty]
5. Synchronous Transmission of byte completed
6. ADC Start of Conversion
7. ADC End of Conversion
8. Pulse-Accumulator overflow
9. Real Time Clock time-outs
10. Watchdog Timer Reset
11. Timer Overflow on time-out
12. Timer comparison with Output compare Registers
13. Timer capture on inputs

Hardware interrupt pins in different processors

1. INTR in 8086 (Maskable interrupt)


2. INT0 and INT 1 in 8051(Maskable interrupt)
3. IRQ in 68HC11(Maskable interrupt)
4. NMI (Non - Maskable interrupt)

Software error Related Sources

1. Division by zero detection (or trap) by hardware


2. Over-flow detection by hardware
3. Under-flow detection by hardware
4. Illegal opcode detection by hardware

SOFTWARE INTERRUPTS:
Software interrupt is interrupt-generated
For example,
software instruction Int n in 80x86 processor
software instruction SWI m in ARM7 processor , where m is 24 bits

Steps on interrupt of type n or on Software Instruction INT n in 80x86


1. INT n means executes interrupt of type n
2. n can be between 0 and 255.
3. INT n causes the processor vectoring to address 0x00004 n for finding IP and
CS registers values for diversion to the ISR

Eg. If an interrupt instruction is given in 8086 processor as INT 04 , then the


interrupt vector address is calculated as 0x0004 x 4 (since n = 4).
Therefore the interrupt vector is 0x00010 (equal to 16 in hexadecimal).This address
will be saved in Instruction pointer(IP) register and Code Segment register (CS)

INTERRUPT VECTOR MECHANISM:


An interrupt vector is an important part of interrupt service mechanism, which
associates a processor.
Processor first saves program counter and/or other registers of CPU on
interrupt and then loads a vector address into the program counter.
Vector address provides either the ISR or ISR address to the processor for the
interrupt source or group of sources or given interrupt type.

Interrupt Vector
System software designer puts the bytes at a ISR_VECTADDR address.
The bytes are for either
o The ISR short code or jump instruction to ISR instruction or
o ISR short code with call to the full code of the ISR at an ISR address or
o Bytes points to an ISR address
A memory address to which processor vectors (transfers into program counter
or IP and CS registers in case of 80x86) a new address on an interrupt for
servicing that interrupt.
The memory addresses for vectoring by the processor are processor or
microcontroller specific.
Vectoring is as per interrupt handling mechanism, which the processor
provides

S-ar putea să vă placă și