You are on page 1of 7

INTRODUCTION TO DEVICE DRIVERS AND

EMBEDDED SOFTWARE
Device driver definition:
A device driver is software or opening, connecting or binding, reading,
writing and closing or controlling action of a device. It is software written in high
level language. It controls functions for device open (configure), connect, bind,
listen, read or write or close. The device driver executes after the programming of
the control register (or word) of a peripheral or virtual device. The driver reads
the status register, gets the inputs and writes the outputs.
A driver controls three functions
1) Initialling which is activated by placing appropriate bit at the control register
2) Calling an ISR on interrupt or on setting a status flag in the status register and
running the ISR (Interrupt Handler Routine)
3) Resetting the status flag after an interrupt service.
NEED FOR DEVICE DRIVERS:
For designing embedded software, two types of devices are considered: physical
and virtual. Physical devices eg : keyboard, printer or display unit virtual devices
Eg: A file or pipe or socket or RAM disk Each device in a system needs device
driver routines. An ISR relates to a device driver function. The examples of
generic functions used for the commands to the device are device create (), open
(), connect (), Bind (), Read (), write (). IOctl (), delete () and close(). Device
driver can be considered as a function in software layer of an application
program and the device. Ex the application sends the commands to write on a
display screen of a mobile. The contact names from the contact database.

DEVICE DRIVER PROGRAMMING:


Each device function requires a driver. Examples of multiple functions in a
device are as follows:
1. A timer device performs timing as well as counting functions. It also performs
the delay function and periodic system calls.
2. Voice data facts modem device has transmitting as well as receiving functions for
voice, facts as well as data.

A common driver or separate drivers for each device function are required.
Device drivers and their corresponding ISRs are the important routines in most
systems.
The driver has the following features.
1. The driver provides a software layer (interface) between the application and
actual device:
2. The driver facilitates the use of a device by executing an ISR: The driver
function is usually written in such a manner that it can be used like a black
box by an application developer.
Writing physical device driving ISRs in a system
For writing the software for driver in assembly, the following points must be
clear.
1.information about how the device communicates.
2information about the three sets of device registers data registers or buffers,
control registers and status registers
3.Information of other registers and common address to a device register.
4.Control register bits control all actions of the device.
5.Status register bits reflect the flags for status of the device at an instant and
changes after performing actions as per the device driver.
6.Ether setting of an enable bit(interrupt control flag ) is used by the system to
initiate a call for executing an ISR related to the device drive function.
Virtual device drivers
Virtual device drivers emulate the hardware
Eg: hard disk and generate software interrupts similar to physical device drivers.
T he file and pipe are two two examples of virtual device drivers.
Consider the analogies of a files device with a physical device.
Eg: just as a file needs to be opened to enable read and write operations , a
device may need to sent an interrupt call for initializing and configuring
it(opening, registering or attaching it. Setting control bits appropriately does
this).The concept of virtual(software) device drivers is very important in
programming. Eg: A memory block can have data buffers in analogy to buffers
in analogy to buffers at an IO device and can be accessed from a char driver or a
block driver. The device is called the device or the block device when it can
access a character or a block of character, respectively.
parallel port drivers in a system
device driver read() function can be implemented by calling an ISR is
Port_ISR_Input, which handle the port input. The below figure1 shows control

and status bits used in the ISRs in the device drivers and port pins interface with
the at a bus

figure 2 shows step A for port initialization, step B for calling the driver
and steps 0 to 5 for driver Port_ISR_input.

Serial port drivers in a system


status register(s)there is IEEE called POSIX (portable operating system interface)
standard. Portability of the UART drivers in different systems in essential.
Device driver for internal programmable timing devices there is at least one
hardware timer T as an internal device in any systems needing function related to
timers. Timer device driver function call an ISR. The ISR programming needs an
understanding of the programming of each bit of timer control register(s) ans

Differences between Embedded Software and


Software Developer
There are the 5 Differences between general software and embedded
software.
1. Knowledge of Hardware
An embedded software developer should know the hardware he should
use the hardware in the best possible way. He would have to interact with the
hardware more closely though he may not speak the 1s and 0s directly. A
software developer works on applications that is totally shielded from the
hardware it runs on and the software developer does not have to know much or in
fact anything about the hardware his program would execute on. The team that
worked on developing firefox or MS Word may not have to know the hardware
completely to develop their software.
2. Lines of code vs Making things work
A software developer generally writes more lines of code almost always.
The reason is that a software developers builds a product just with his lines of
code, out of thin air. An embedded guy makes a physical hardware device work
with his software
3. Algorithm & Data Processing Vs System Control
A software program generally revolves around 2 aspects, ALGORITHM
and DATA. Take any program, it would either be computing something
(numerically or logically), which is what I we refer as Algorithm or it would be
working on data. It could be storing data, moving data, processing data or simply
presenting or deleting data. Any software right from banking, insurance, retail,
logistics to simple PC based software like Word, PowerPoint, etc., all of them
work on the aforementioned principles. An embedded software is more focused
towards controlling and managing the system (or hardware). It is developed to
exploit the full potential of the hardware and manage it for the benefit of the user.

Though there would be data and algorithm in embedded software, it would be


there only to control and manage the hardware in a better fashion.

4. PC vs PCB
Though embedded developers work on PC they are not writing software
for PCs. They use the PC to build their software which eventually runs on
another platform (a Printed Circuit Board with a Micro controller). Embedded
software engineers develop software for these BOARDS and move the
executable binary from the PC to the board using debugging tools or specific
connectivity options. Software developers develop software that run on PCs or
PC equivalents (like servers). Whether the software runs in a bank, shipyard, our
fedex store, Airport or Grocery store it runs on a computer. May be nowadays
they run on Mobile phones and tablets too. From an embedded perspective
today's tablets and mobiles don't differ much from PCs as they are all are more
General Purpose.
5. Oscilloscopes vs Breakpoints

Debugging embedded software is different from debugging application


software just like development. Embedded developers use Oscilloscopes,
Logic Analyzers and multimeter while debugging a HANG!! than using
break points. Software Developers more often use the debugging break
points and debug options that their IDE provides to debug the code, profile
the code, etc. Today, there has been a great amount of work being done to
simplify embedded software development and make it easy and more
comparable to normal application software development. The many
community boards like Raspberry, PI, Arduino, etc. are targeting this area.
Even with limited hardware knowledge you should be able to make a
device - that's where its moving - More on that another time.

Embedded C
It is a set of language extensions for the C Programming language by the C
Standards committee to address commonality issues that exist between C
extensions

for

different embedded

systems.

Historically,

embedded

programming requires nonstandard extensions to the C language in order to


support exotic features such as fixed-point arithmetic, multiple distinct memory
banks, and basic I/O operations.

Use of C in embedded systems is driven by following advantages

It is small and reasonably simpler to learn, understand, program and debug.

C Compilers are available for almost all embedded devices in usetoday,and


there is a large pool of experienced C programmers.

Unlike assembly, C has advantage of processor-independence and is not specific


to any particular microprocessor/ microcontroller or any system. This makes it
convenient for a user to develop programs that can run on most of the systems.

As C combines functionality of assembly language and features of high level


languages, C is treated as a middle-level computer language or high level
assembly language

It is fairly efficient

It supports access to I/O and provides ease of management of large embedded


projects.
Dfference between c and embedded c
Though C and embedded C appear different and are used in different contexts,
they have more similarities than the differences. Most of the constructs are same;
the difference lies in their applications. C is used for desktop computers,
while embedded C is for microcontroller based applications. Accordingly, C has
the luxury to use resources of a desktop PC like memory, OS, etc. While
programming on desktop systems, we need not bother about memory. However,
embedded C has to use with the limited resources (RAM, ROM, I/Os) on an
embedded processor. Thus, program code must fit into the available program
memory. If code exceeds the limit, the system is likely to crash.

Compilers

for

(ANSI

C)

typically

generate

OS

dependant

executables. Embedded C requires compilers to create files to be downloaded to


the microcontrollers/microprocessors where it needs to run. Embedded compilers
give access to all resources which is not provided in compilers for desktop
computer applications. Embedded systems often have the real-time constraints,
which is usually not there with desktop computer applications. Embedded
systems often do not have a console, which is available in case of desktop
applications. So, what basically is different while programming with embedded
C is the mindset; for embedded applications, we need to optimally use the
resources, make the program code efficient, and satisfy real time constraints, if
any. All this is done using the basic constructs, syntaxes, and function libraries of
C.

You might also like