You are on page 1of 18

EMBEDDED SYSTEMS

MODULE 4
DEVICE DRIVERS
DEVICE DRIVER - INTRO
A piece of software
Acts as a bridge b/w OS & H/W
Operates or controls a particular type of
device that is attached to a computer.
Provides asoftware interfaceto hardware
devices, enabling OS and other computer
programs to access H/W functions without
needing to know precise details of the
hardware being used.
TOPOLOGY OF USER APPS
AND H/W INTERACTION IN
RTOS

USER LEVEL APPLICATION


APP /TASKS
APP APP
1 2 3

OPERATING SYSTEM SERVICES

DEVICE DRIVERS

HARDWARE
WHY DEVICE DRIVERS?
OS KERNEL ARCH . Do not allow
direct device access from user appln.
All device related access should flow
through OS kernel
OS based PROD. ARCH user applns
talk to OS kernel for all info exch.
with H/W peripherals.
The OS kernel is responsible for
routing the user applns to concerned
H/W peripheral.
RESPONSIBILITIES OF DD
Initiating commn. with H/W
Managing
Establishing connectivity with H/W
Initialising the H/W setting up
registers
Transfering data
Drivers are hardware-dependent andoperating-system-specific.
NOTE:1

Each class of H/W requires a unique


driver ::::
A driver is implemented with the
initialisation of the H/W and the protocols
required for communicating with the device
( these vary from device to device)
A single driver hence cannot be used for all
hardware
NOTE:2
Implementation of driver is OS
dependent::::
HOW driver communicates with OS
kernel ----- depends on OS structure
& implementation.
Hence different OS follow different
implementations
DETA-DATA
Device drivers simplify programming by acting as translator
between a hardware device and the applications or
operating systemsthat use it.
Programmers can write the higher-level application code
independently of whatever specific hardware the end-user is using.
For example, a high-level application for interacting with a
serial portmay simply have two functions for "send data" and
"receive data". At a lower level, a device driver implementing these
functions would communicate to the particular serial port controller
installed on a user's computer. The commands needed to control a
16550 UARTare much different from the commands needed to
control anFTDIserial port converter, but each hardware-specific
device driverabstractsthese details into the same (or similar)
software interface. THE DEVICE DRIVER ABSTRACTS THE
HARDWARE FROM USER APPLICATIONS
CLASSIFICATION-1
BUILT-IN-DRIVERS (on board drivers)
Drivers that come as a part of the OS KERNEL
-for H/W devices that are part of the
platform
-for devices supporting standard protocol and
device class
Eg:
1. NAND FLASH driver :for NAND FLASH memory
2. USB Drivers for USB mass storage devices
3. Mouse /Keypad drivers - HID Device drivers
INSTALLABLE DRIVERS
Drivers to be installed separately when the
device is to be accessed
Loading by the OS on a need basis at the
time of booting the devices and kept in RAM
When device is connected to the S/M OS
loads the driver to memory
When device is removed . Driver unloaded
from memory
Eg: A medical device with custom USB class
implementation is connected to the USB
port of the s/m.
Note: OS maintains a record of the drivers
corresponding to each hardware.
CLASSIFICATION-2
KERNEL MODE DRIVERS
Runs in kernel space
Not safe- an error or exception can
cause kernel crash
EG: Microsoft Windowsplatforms, can
run inkernel-mode(
Ring 0 on x86 CPUs)
USER MODE DRIVERS
Runs in user space
Safe as an exception or error in user space
doesnot affect kernel
Improved stability, since a poorly written user
mode device driver cannot crash the system
by overwriting kernel memory.
user/kernel-mode transitions usually impose a
considerable performance overhead, thereby
prohibiting user-mode drivers for low latency
and high throughput requirements.
EG: Microsoft Windowscan run inuser-mode
(Ring3 on x86 CPUs).
HOW?
OS provides interfaces in the form of API for accessing the
H/W. API APPLICATION PROGRAMMING INTERFACES
A driver typically communicates with thedevicethrough
thecomputer busor communications subsystem to which
the hardware connects.
When a calling program invokes aroutinein the driver, the
driver issues commands to the device.
Once the device sends data back to the driver, the driver
may invoke routines in the original calling program.
They usually provide theinterrupthandling required for
any necessary asynchronous time-dependent hardware
interface.
Cont..
A device driver implements the
following:
1. (a) Device (H/W) initialis.
(b) Interrupt config.
2. Interupt handling and processing
3.Client Interfacing ( interfacing with
user applications)
HARDWARE INITIALISATION
Config. different registers of target
H/W
-
INTERRUPT CONFIG.
Configuring the interrupts needed to be associated with
the H/W
This includes
Setting the interrupt type
-edge triggered <rising / falling >
-Level triggered < LOW / HIGH >
Enable the interrupts
Set the interrupt priority
Bind the interrupt with an Interrupt Request (IRQ)-
processor identifies the interrupt using IRQ generated by
interrupt controller so as to get the interrupt identified
Register ISR with IRQ ISR handler of Interrupt
INTERRUPT HANDLING AND
PROCESSING
Interrupt processing routine or thread
to inform the user applications (using
Client Interfacing )that
---an interrupt has occurred and
---data is available for further
processing
CLIENT INTERFACING
Uses the Inter Process
communication mechanisms
supported by OS for communicating
and synchronising with user
applications and drivers

You might also like