SlideShare a Scribd company logo
1 of 62
Download to read offline
DEVICE DRIVERS AND INTERRUPTS SERVICE
MECHANISM
Programmed I/O (busy and wait) method for ports
and devices, and the need for interrupt driven IOs
1
An embedded system uses its input/output devices to interact
with the external world. Input devices allow the computer to
gather information, and output devices can display
information. Output devices also allow the computer to
manipulate its environment. The tight-coupling between the
computer and external world distinguishes an embedded
system from a regular computer system. The challenge is under
most situations the software executes much faster than the
hardware. E.g., it might take the software only 1 us to ask the
hardware to clear the LCD, but the hardware might take 1 ms
to complete the command. During this time, the software could
execute tens of thousands of instructions. Therefore, the
synchronization between the executing software and its
external environment is critical for the success of an embedded
system.
Interrupt Concepts
An interrupt is the automatic transfer of software
execution in response to a hardware event that is
asynchronous with the current software execution. This
hardware event is called a trigger. The hardware event
can either be a busy to ready transition in an external I/O
device (like the UART input/output) or an internal event
(like bus fault, memory fault, or a periodic timer). When
the hardware needs service, signified by a busy to ready
state transition, it will request an interrupt by setting its
trigger flag.
A thread is defined as the path of action of software as it
executes. The execution of the interrupt service routine is
called a background thread. This thread is created by the
hardware interrupt request and is killed when the interrupt
service routine returns from interrupt (e.g., by executing a BX
LR). A new thread is created for each interrupt request. It is
important to consider each individual request as a separate
thread because local variables and registers used in the
interrupt service routine are unique and separate from one
interrupt event to the next interrupt.
In a multi-threaded system, we consider the threads as
cooperating to perform an overall task. Consequently, we
will develop ways for the threads to communicate (e.g.,
FIFO) and to synchronize with each other. Most embedded
systems have a single common overall goal. On the other
hand, general-purpose computers can have multiple
unrelated functions to perform.
A process is also defined as the action of software
as it executes. Processes do not necessarily
cooperate towards a common shared goal. Threads
share access to I/O devices, system resources, and
global variables, while processes have separate
global variables and system resources. Processes do
not share I/O devices.
Programmed IOs approach from ports and devices
• Processor is continuously busy in
executing the program related to input
or output from the port and waits for
the input ready or output completion
• Processor is continuously busy in
executing the program related to device
functions and waits for the device status
ready or function completions
8
Example─ A 64-kbps UART Input
•When a UART transmits in format of 11-bit per character
format, the network transmits at most 64 kbps  11 = 5818
characters per second, which means every 171.9 s a
character is expected.
•Before 171.9 s, the receiver port must be checked to find
and read another character assuming that all the received
characters are in succession without any in-between time-
gap
9
Format of bits at UART protocol
10
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 re-transmits the character to Port
B output.
11
In_A_Out_B routine
12
• 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
In_A_Out_B routine
•Call function i
•Call function ii
•Call function iii
•Call function iv
•Call function v
•Loop back to step 1
13
Steps a, b and c
14
• Step a: Function i─ Check for a character at port A, if
not available, then wait
• Step b: Function ii─ Read Port A byte (character for
message) and return to step a instruction, which will
call function iii
• Step c: Function iii─ Decrypt the Message and return
to step a instruction, which will call function iv
Steps d and e
15
• Step d: Function iv─ Encode the Message and return to
step a instruction, which will call function v.
• Step e: Function v ─ Transmit the encoded message to
Port B and return to step a last instruction, which will
start step a from beginning
Step a
17
• Does Polling─ Polling a port means to find the status
of the port─ whether ready with a character (byte) at
input or not.
• Polling must start before 171.9 s because characters
are expected at 64 kbps/11 bit format.
Condition in which no character misses
18
• If the program instructions in four steps b, c, d and e
(functions ii to v) take total running time of
less than 171.9 s then the above programmed IO
method works.
Problems with Programmed IOs approach from ports
and devices
1. (a) The program must switch to execute the
In_A_Out_B cycle of steps a to e within a
period less than 171.9 s. (b) Programmer
must ensure that steps of In_A_Out_B and any
other device program steps never exceed this
time.
19
Problems with Programmed IOs approach from port as
and devices
2. When the characters are not received at Port A
in regular succession, the waiting period during
step a for polling the port can be very
significant.
3. Wastage of processor times for the waiting
periods is the most significant disadvantage
of the present approach
20
Problem with Programmed IOs approach from ports and
devices
21
4. When the other ports and devices are also present, then
programming problem is to poll each port and device, and
ensure that program switches to execute the In_A_Out_B step
a as well as switches to poll each port or device on time and
then execute each service routines related to the functions of
other ports and devices within specific time intervals such that
each one is polled on time.
Problems with Programmed IOs approach from ports and
devices
5. The program and functions are processor and
device specific in the above busy-wait approach,
and all system functions must execute in
synchronization and timings are completely
dependent on periods of software execution
22
IO based on an interrupt from Port A
23
• Instead of continuously checking for characters at the port A by
executing function (i) we can first call step a when a modem
receives an input character, sets a status bit in its status register and
interrupts Port A. The interrupt should be generated by port
hardware.
• In response to the interrupt, an interrupt service routine ISR_ PortA
_Character executes─ an efficient solution in place the wait at step a
(poll for input character)
Application of programmed IOs
24
• In case of single purpose processor and dedicated IOs or
device functions with continuous device status polling
Interrupt and Interrupt Service Routine
Concept
25
• Interrupt means event, which invites attention of the
processor on occurrence of some action at hardware or
software interruptinstruction event.
26
Interrupt Concept
Action on Interrupt
27
• In response to the interrupt, the routine or program,
which is running presently interrupts and an interrupt
service routine (ISR) executes.
Interrupt Service Routine
28
• 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
29
Hardware interrupt
30
• Examples─ When a device or port is ready, a device or
port generates an interrupt, or when it completes the
assigned action or when a timer overflows or when a
time at the timer equals a preset time in a compare
register or on setting a status flag (for example, on timer
overflow or compare or capture of time) or on click of
mice in a computer
• Hardware interrupt generates call to an ISR
Software Interrupt
31
Examples
•When software run-time exception condition (for examples,
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 .
Software Interrupt
32
• 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.
Interrupt
33
• 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.]
Interrupt Driven Actions
On Interrupt Interrupt Service
Routine (ISR)
Running
Program Return
No continuous checks of device status
34
How does call to ISR differ from a function
(routine) call?
35
Routine (function) and ISR call features
36
• 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
Routine (function) call and ISR call features
37
• 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
38
• 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
Using the Interrupt(s) and ISR(s) for each device
function (for example, read, write)
- Use of ISRs (Interrupt Service Routine) by SWIs
is the main mechanism used for the device accesses
and actions
39
Interrupt driven IO and device accesses feature
1. 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
device- functions, and each of which
executes on a device interrupt.
40
Example─ A 64-kbps UART Input
•When a UART transmits in format of 11-bit per
character format, the network transmits at most 64
kbps  11 = 5818 characters per second, which
means every 171.9 s a character is expected.
•Before 171.9 s, the receiver port is not checked.
Only on interrupt from the port the character is read
•There is no in-between time-gap for polling
41
Ports A and B with interrupt generation and interrupt
service (handling) mechanism
• Port A be at in a PC, and port B be its modem input
which puts the characters on the telephone line.
• Let ISR_ PortA_Character be a routine that receives an
input character from Port A on interrupt and Out_B
routine re-transmits an output character to Port B.
42
ISR_ PortA _Character
43
• Step f function (vi): Read Port A character. Reset the
status bit so that modem is ready for next character input
(generally resetting of status bit is automatic without need
of specific instruction for it). Put it in memory buffer.
Memory buffer is a set of memory addresses where the
bytes (characters) are queued for processing later.
• Return from the interrupt service routine.
2008
Chapter-4 L02: "Embedded Systems - " , Raj Kamal,
Publs.: McGraw-Hill Education
20
ISR_ PortA _Character
On interrupt call ISR_ PortA _Character
Save PC, status word and registers (current
program context) on stack
Step f
Execute function vi codes (read character,
reset port status bit, character save in
memory buffer)
Return (retrieve the saved context)
Current program
Out_B routine
45
• Step g: Call function (vii) to decrypt the message
characters at the memory buffer and return for next
instruction step h.
• Step h: Call function (viii) to encode the message
character and return for next instruction step k
• Step k: Call function (ix) to transmit the encoded
character to Port B
• Return from the function.
Out_B Routine
Out_B Routine
Step g
Step h
Step k
Each step has three parts, save context, execute
codes, and retrieve the context for return 46
Application of Interrupt based IOs and device functions
• In case of multiple processes and
device functions with no device
status polling or wait
47
Use of ISR in the mobile phone reset key interrupt
example
Mobile
Keypad
events
input
processor
at mobile
Event: Reset
Key pressed
to reset the
mobile
ISR_ResetKey Read
key state at Port bits
P0-P7 Reset key state
status bit
Sent message for
tasks
Signal timer start for
enabling display off
after 15 s (preset
time)
P0-P7
Reset event
1 2
Call
4
Signal timer Tasks
4
Data bus
5
R
et
ur
n
Interrupt
3
Sent
messag
e for
Tasks
48
Software Interrupts and Interrupt
Service routines
4
9
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
5
0
Detection of exceptional run-time condition
•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.
5
1
SWI
•Executes on detecting the exceptional run- time 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.
5
2
Example: SWI a1 and SWI a2
5
3
• The SWI (software interrupt) instructions,
SWI a1 and SWI a2 will be inserted for
trapping (A- B) as –ve number and trapping
y > 100 or less than 0
Software instruction SWI a1
5
4
• 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
5
5
• Causes processor interrupt.
• In response, the software ISR function
‘catch (Exception_2 a2) { }’ executes
on throwing of the exception a1 during
try block execution.
• SWI a2 is used after catching the exception
a2 whenever it is thrown
2008 Chapter-4 L03: "Embedded Systems - " , Raj
8
Use of SWI software interrupt-instruction for calling an ISR
in the software on throwing and catching the exceptional run-
time conditions a1 and a2 encountered during computations
Exceptional handler
Find exception source a1
Run codes for actions to
be taken on event a1 in
catch (Exception_1 a1) {
}
Find exception source a2
Run codes for actions to
be taken on event a2 in
catch (Exception_1 a2{ }
Call function to execute at
end
Call function to
execute
end
on detecting
an
exception
condition or
error
condition in
try block
End of
Function
Run Codes at
finally { …}
codes, which
should
execute when
the
exceptions or
try
bl
ock
instructions
finished
Status Flags for the Exception sources in the memory
throw
event a1
Software
interrupt
throw
event a2
Software
interrupt
on detecting
another
exception
condition or
error condition
in try block
1
2
SWI a3
57
• Software ISR function ‘finally { }’
executes either at the end of the try or at the
end of catch function codes.
• SWI a3 is used after the try and catch
functions finish, then finally function will
perform final task, for example, exit from
the program or call another function
Signal from a thread for Signal handler Interrupt Service
Routine
• ISR is also called signal handler in case of a
routine or program thread, or task sends a signal
using an SWI
• Signals are used to notify error conditions or
notifying end of an action to enable signal
handler thread or task to initiate action on that.
58
Action on Signal generated by SWI and signal handling
A program or task or
routine 1
Run Codes
Signal (event e1) for run
routine 2
Status Flags for the Signal sources
in the memory
interrupt
A program or task or
routine 2
Run Codes
Signal (event e2) for
run routine 3
Software
interrupt 1
Software
2
Signal handler Find signal
a1
Run codes for actions to be
taken on signal a1 from
program
Find signal a2
Run codes for actions to be
taken on signal a2 from program to
execute at end
59
Device driver
60
• 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
Interrupt service routines
61
• 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
First level ISR and second level IST approach to
handle the device hardware interrupts followed by
software interrupt
Command
c1
Device driver
command 1 Run
short code Signal
ISR 1
Device driver
command 2 Run
short code Signal
ISR 2
Command
c2
Interrupt
Interrupt (signal)
Interrupt (signal)
ISR 1
Run codes of
device function 1
ISR 2
Run codes of
device function 2
device
event e3
Interrupt
Interrupt
62

More Related Content

Similar to DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf

Computer architecture presentation
Computer architecture presentationComputer architecture presentation
Computer architecture presentationMuhammad Hamza
 
Input-Output Modules
Input-Output ModulesInput-Output Modules
Input-Output ModulesMukesh Tekwani
 
Unit 5 I/O organization
Unit 5   I/O organizationUnit 5   I/O organization
Unit 5 I/O organizationchidabdu
 
8086 Interrupts & With DOS and BIOS by vijay
8086 Interrupts &  With DOS and BIOS  by vijay8086 Interrupts &  With DOS and BIOS  by vijay
8086 Interrupts & With DOS and BIOS by vijayVijay Kumar
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in indiaEdhole.com
 
COMPUTER ORGANIZATION NOTES Unit 3 4
COMPUTER ORGANIZATION NOTES  Unit 3 4COMPUTER ORGANIZATION NOTES  Unit 3 4
COMPUTER ORGANIZATION NOTES Unit 3 4Dr.MAYA NAYAK
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kVijay Kumar
 
I/O Organization
I/O OrganizationI/O Organization
I/O OrganizationDhaval Bagal
 
Bca examination 2015 csa
Bca examination 2015 csaBca examination 2015 csa
Bca examination 2015 csaAnjaan Gajendra
 
CO--MODULE-1 (b) - Input-Output-Organization.pptx
CO--MODULE-1 (b) - Input-Output-Organization.pptxCO--MODULE-1 (b) - Input-Output-Organization.pptx
CO--MODULE-1 (b) - Input-Output-Organization.pptxahmedsalik057
 
Lecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfLecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfTaufeeq8
 
Compuer organizaion processing unit
Compuer organizaion processing unitCompuer organizaion processing unit
Compuer organizaion processing unitDeepak John
 
Iosystemspre final-160922112930
Iosystemspre final-160922112930Iosystemspre final-160922112930
Iosystemspre final-160922112930marangburu42
 
Io systems final
Io systems finalIo systems final
Io systems finalmarangburu42
 
unit-5 ppt.ppt
unit-5 ppt.pptunit-5 ppt.ppt
unit-5 ppt.pptSheebaKelvin2
 
Control unit design
Control unit designControl unit design
Control unit designDhaval Bagal
 

Similar to DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf (20)

Computer architecture presentation
Computer architecture presentationComputer architecture presentation
Computer architecture presentation
 
Input-Output Modules
Input-Output ModulesInput-Output Modules
Input-Output Modules
 
IO organization.ppt
IO organization.pptIO organization.ppt
IO organization.ppt
 
Unit 5 I/O organization
Unit 5   I/O organizationUnit 5   I/O organization
Unit 5 I/O organization
 
8086 Interrupts & With DOS and BIOS by vijay
8086 Interrupts &  With DOS and BIOS  by vijay8086 Interrupts &  With DOS and BIOS  by vijay
8086 Interrupts & With DOS and BIOS by vijay
 
Ca 2 note mano
Ca 2 note manoCa 2 note mano
Ca 2 note mano
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
Os lectures
Os lecturesOs lectures
Os lectures
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in india
 
COMPUTER ORGANIZATION NOTES Unit 3 4
COMPUTER ORGANIZATION NOTES  Unit 3 4COMPUTER ORGANIZATION NOTES  Unit 3 4
COMPUTER ORGANIZATION NOTES Unit 3 4
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
 
I/O Organization
I/O OrganizationI/O Organization
I/O Organization
 
Bca examination 2015 csa
Bca examination 2015 csaBca examination 2015 csa
Bca examination 2015 csa
 
CO--MODULE-1 (b) - Input-Output-Organization.pptx
CO--MODULE-1 (b) - Input-Output-Organization.pptxCO--MODULE-1 (b) - Input-Output-Organization.pptx
CO--MODULE-1 (b) - Input-Output-Organization.pptx
 
Lecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfLecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdf
 
Compuer organizaion processing unit
Compuer organizaion processing unitCompuer organizaion processing unit
Compuer organizaion processing unit
 
Iosystemspre final-160922112930
Iosystemspre final-160922112930Iosystemspre final-160922112930
Iosystemspre final-160922112930
 
Io systems final
Io systems finalIo systems final
Io systems final
 
unit-5 ppt.ppt
unit-5 ppt.pptunit-5 ppt.ppt
unit-5 ppt.ppt
 
Control unit design
Control unit designControl unit design
Control unit design
 

Recently uploaded

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoĂŁo Esperancinha
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerAnamika Sarkar
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 

Recently uploaded (20)

young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 

DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf

  • 1. DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM Programmed I/O (busy and wait) method for ports and devices, and the need for interrupt driven IOs 1
  • 2. An embedded system uses its input/output devices to interact with the external world. Input devices allow the computer to gather information, and output devices can display information. Output devices also allow the computer to manipulate its environment. The tight-coupling between the computer and external world distinguishes an embedded system from a regular computer system. The challenge is under most situations the software executes much faster than the hardware. E.g., it might take the software only 1 us to ask the hardware to clear the LCD, but the hardware might take 1 ms to complete the command. During this time, the software could execute tens of thousands of instructions. Therefore, the synchronization between the executing software and its external environment is critical for the success of an embedded system.
  • 3.
  • 4. Interrupt Concepts An interrupt is the automatic transfer of software execution in response to a hardware event that is asynchronous with the current software execution. This hardware event is called a trigger. The hardware event can either be a busy to ready transition in an external I/O device (like the UART input/output) or an internal event (like bus fault, memory fault, or a periodic timer). When the hardware needs service, signified by a busy to ready state transition, it will request an interrupt by setting its trigger flag.
  • 5. A thread is defined as the path of action of software as it executes. The execution of the interrupt service routine is called a background thread. This thread is created by the hardware interrupt request and is killed when the interrupt service routine returns from interrupt (e.g., by executing a BX LR). A new thread is created for each interrupt request. It is important to consider each individual request as a separate thread because local variables and registers used in the interrupt service routine are unique and separate from one interrupt event to the next interrupt.
  • 6. In a multi-threaded system, we consider the threads as cooperating to perform an overall task. Consequently, we will develop ways for the threads to communicate (e.g., FIFO) and to synchronize with each other. Most embedded systems have a single common overall goal. On the other hand, general-purpose computers can have multiple unrelated functions to perform.
  • 7. A process is also defined as the action of software as it executes. Processes do not necessarily cooperate towards a common shared goal. Threads share access to I/O devices, system resources, and global variables, while processes have separate global variables and system resources. Processes do not share I/O devices.
  • 8. Programmed IOs approach from ports and devices • Processor is continuously busy in executing the program related to input or output from the port and waits for the input ready or output completion • Processor is continuously busy in executing the program related to device functions and waits for the device status ready or function completions 8
  • 9. Example─ A 64-kbps UART Input •When a UART transmits in format of 11-bit per character format, the network transmits at most 64 kbps  11 = 5818 characters per second, which means every 171.9 s a character is expected. •Before 171.9 s, the receiver port must be checked to find and read another character assuming that all the received characters are in succession without any in-between time- gap 9
  • 10. Format of bits at UART protocol 10
  • 11. 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 re-transmits the character to Port B output. 11
  • 12. In_A_Out_B routine 12 • 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
  • 13. In_A_Out_B routine •Call function i •Call function ii •Call function iii •Call function iv •Call function v •Loop back to step 1 13
  • 14. Steps a, b and c 14 • Step a: Function i─ Check for a character at port A, if not available, then wait • Step b: Function ii─ Read Port A byte (character for message) and return to step a instruction, which will call function iii • Step c: Function iii─ Decrypt the Message and return to step a instruction, which will call function iv
  • 15. Steps d and e 15 • Step d: Function iv─ Encode the Message and return to step a instruction, which will call function v. • Step e: Function v ─ Transmit the encoded message to Port B and return to step a last instruction, which will start step a from beginning
  • 16.
  • 17. Step a 17 • Does Polling─ Polling a port means to find the status of the port─ whether ready with a character (byte) at input or not. • Polling must start before 171.9 s because characters are expected at 64 kbps/11 bit format.
  • 18. Condition in which no character misses 18 • If the program instructions in four steps b, c, d and e (functions ii to v) take total running time of less than 171.9 s then the above programmed IO method works.
  • 19. Problems with Programmed IOs approach from ports and devices 1. (a) The program must switch to execute the In_A_Out_B cycle of steps a to e within a period less than 171.9 s. (b) Programmer must ensure that steps of In_A_Out_B and any other device program steps never exceed this time. 19
  • 20. Problems with Programmed IOs approach from port as and devices 2. When the characters are not received at Port A in regular succession, the waiting period during step a for polling the port can be very significant. 3. Wastage of processor times for the waiting periods is the most significant disadvantage of the present approach 20
  • 21. Problem with Programmed IOs approach from ports and devices 21 4. When the other ports and devices are also present, then programming problem is to poll each port and device, and ensure that program switches to execute the In_A_Out_B step a as well as switches to poll each port or device on time and then execute each service routines related to the functions of other ports and devices within specific time intervals such that each one is polled on time.
  • 22. Problems with Programmed IOs approach from ports and devices 5. The program and functions are processor and device specific in the above busy-wait approach, and all system functions must execute in synchronization and timings are completely dependent on periods of software execution 22
  • 23. IO based on an interrupt from Port A 23 • Instead of continuously checking for characters at the port A by executing function (i) we can first call step a when a modem receives an input character, sets a status bit in its status register and interrupts Port A. The interrupt should be generated by port hardware. • In response to the interrupt, an interrupt service routine ISR_ PortA _Character executes─ an efficient solution in place the wait at step a (poll for input character)
  • 24. Application of programmed IOs 24 • In case of single purpose processor and dedicated IOs or device functions with continuous device status polling
  • 25. Interrupt and Interrupt Service Routine Concept 25
  • 26. • Interrupt means event, which invites attention of the processor on occurrence of some action at hardware or software interruptinstruction event. 26 Interrupt Concept
  • 27. Action on Interrupt 27 • In response to the interrupt, the routine or program, which is running presently interrupts and an interrupt service routine (ISR) executes.
  • 28. Interrupt Service Routine 28 • ISR is also called device driver in case of the devices and called exception or signal or trap handler in case of software interrupts
  • 29. 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 29
  • 30. Hardware interrupt 30 • Examples─ When a device or port is ready, a device or port generates an interrupt, or when it completes the assigned action or when a timer overflows or when a time at the timer equals a preset time in a compare register or on setting a status flag (for example, on timer overflow or compare or capture of time) or on click of mice in a computer • Hardware interrupt generates call to an ISR
  • 31. Software Interrupt 31 Examples •When software run-time exception condition (for examples, 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 .
  • 32. Software Interrupt 32 • 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.
  • 33. Interrupt 33 • 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.]
  • 34. Interrupt Driven Actions On Interrupt Interrupt Service Routine (ISR) Running Program Return No continuous checks of device status 34
  • 35. How does call to ISR differ from a function (routine) call? 35
  • 36. Routine (function) and ISR call features 36 • 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
  • 37. Routine (function) call and ISR call features 37 • 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
  • 38. Nesting of function calls and ISRs 38 • 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
  • 39. Using the Interrupt(s) and ISR(s) for each device function (for example, read, write) - Use of ISRs (Interrupt Service Routine) by SWIs is the main mechanism used for the device accesses and actions 39
  • 40. Interrupt driven IO and device accesses feature 1. 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 device- functions, and each of which executes on a device interrupt. 40
  • 41. Example─ A 64-kbps UART Input •When a UART transmits in format of 11-bit per character format, the network transmits at most 64 kbps  11 = 5818 characters per second, which means every 171.9 s a character is expected. •Before 171.9 s, the receiver port is not checked. Only on interrupt from the port the character is read •There is no in-between time-gap for polling 41
  • 42. Ports A and B with interrupt generation and interrupt service (handling) mechanism • Port A be at in a PC, and port B be its modem input which puts the characters on the telephone line. • Let ISR_ PortA_Character be a routine that receives an input character from Port A on interrupt and Out_B routine re-transmits an output character to Port B. 42
  • 43. ISR_ PortA _Character 43 • Step f function (vi): Read Port A character. Reset the status bit so that modem is ready for next character input (generally resetting of status bit is automatic without need of specific instruction for it). Put it in memory buffer. Memory buffer is a set of memory addresses where the bytes (characters) are queued for processing later. • Return from the interrupt service routine.
  • 44. 2008 Chapter-4 L02: "Embedded Systems - " , Raj Kamal, Publs.: McGraw-Hill Education 20 ISR_ PortA _Character On interrupt call ISR_ PortA _Character Save PC, status word and registers (current program context) on stack Step f Execute function vi codes (read character, reset port status bit, character save in memory buffer) Return (retrieve the saved context) Current program
  • 45. Out_B routine 45 • Step g: Call function (vii) to decrypt the message characters at the memory buffer and return for next instruction step h. • Step h: Call function (viii) to encode the message character and return for next instruction step k • Step k: Call function (ix) to transmit the encoded character to Port B • Return from the function.
  • 46. Out_B Routine Out_B Routine Step g Step h Step k Each step has three parts, save context, execute codes, and retrieve the context for return 46
  • 47. Application of Interrupt based IOs and device functions • In case of multiple processes and device functions with no device status polling or wait 47
  • 48. Use of ISR in the mobile phone reset key interrupt example Mobile Keypad events input processor at mobile Event: Reset Key pressed to reset the mobile ISR_ResetKey Read key state at Port bits P0-P7 Reset key state status bit Sent message for tasks Signal timer start for enabling display off after 15 s (preset time) P0-P7 Reset event 1 2 Call 4 Signal timer Tasks 4 Data bus 5 R et ur n Interrupt 3 Sent messag e for Tasks 48
  • 49. Software Interrupts and Interrupt Service routines 4 9
  • 50. 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 5 0
  • 51. Detection of exceptional run-time condition •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. 5 1
  • 52. SWI •Executes on detecting the exceptional run- time 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. 5 2
  • 53. Example: SWI a1 and SWI a2 5 3 • The SWI (software interrupt) instructions, SWI a1 and SWI a2 will be inserted for trapping (A- B) as –ve number and trapping y > 100 or less than 0
  • 54. Software instruction SWI a1 5 4 • 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
  • 55. Software instruction SWI a2 5 5 • Causes processor interrupt. • In response, the software ISR function ‘catch (Exception_2 a2) { }’ executes on throwing of the exception a1 during try block execution. • SWI a2 is used after catching the exception a2 whenever it is thrown
  • 56. 2008 Chapter-4 L03: "Embedded Systems - " , Raj 8 Use of SWI software interrupt-instruction for calling an ISR in the software on throwing and catching the exceptional run- time conditions a1 and a2 encountered during computations Exceptional handler Find exception source a1 Run codes for actions to be taken on event a1 in catch (Exception_1 a1) { } Find exception source a2 Run codes for actions to be taken on event a2 in catch (Exception_1 a2{ } Call function to execute at end Call function to execute end on detecting an exception condition or error condition in try block End of Function Run Codes at finally { …} codes, which should execute when the exceptions or try bl ock instructions finished Status Flags for the Exception sources in the memory throw event a1 Software interrupt throw event a2 Software interrupt on detecting another exception condition or error condition in try block 1 2
  • 57. SWI a3 57 • Software ISR function ‘finally { }’ executes either at the end of the try or at the end of catch function codes. • SWI a3 is used after the try and catch functions finish, then finally function will perform final task, for example, exit from the program or call another function
  • 58. Signal from a thread for Signal handler Interrupt Service Routine • ISR is also called signal handler in case of a routine or program thread, or task sends a signal using an SWI • Signals are used to notify error conditions or notifying end of an action to enable signal handler thread or task to initiate action on that. 58
  • 59. Action on Signal generated by SWI and signal handling A program or task or routine 1 Run Codes Signal (event e1) for run routine 2 Status Flags for the Signal sources in the memory interrupt A program or task or routine 2 Run Codes Signal (event e2) for run routine 3 Software interrupt 1 Software 2 Signal handler Find signal a1 Run codes for actions to be taken on signal a1 from program Find signal a2 Run codes for actions to be taken on signal a2 from program to execute at end 59
  • 60. Device driver 60 • 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
  • 61. Interrupt service routines 61 • 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
  • 62. First level ISR and second level IST approach to handle the device hardware interrupts followed by software interrupt Command c1 Device driver command 1 Run short code Signal ISR 1 Device driver command 2 Run short code Signal ISR 2 Command c2 Interrupt Interrupt (signal) Interrupt (signal) ISR 1 Run codes of device function 1 ISR 2 Run codes of device function 2 device event e3 Interrupt Interrupt 62