Beruflich Dokumente
Kultur Dokumente
Drivers
Introduction
Device driver consists of a lot of "bit-bashing and registertwiddling" to convince some ornery unit of hardware to
submit to the control of driver software.
You've got to get every one of a myriad of details right the
bits, the sequences, the timing -- or else that chunk of
hardware will just refuse to do its thing.
A device driver can be organized as a collection of "chunks"
of concurrent software.
The RTOS is involved in both scheduling the "chunks" and
allowing them to communicate cleanly with one another.
In different operating systems, the concurrent "chunks" of
software might be given different names like 'threads' or
'tasks'.
For example, in the pSOSystem RTOS they are called 'tasks'
and 'Interrupt Service Routines' (ISRs).
Introduction
A device driver itself is a collection of functions that are
programmed to make a hardware device perform some
input/output-related ("I/O") activities.
A driver might contain an "initialization" function, a "read"
function, a "write" function, etc.
Device drivers that work with hardware devices that deliver
interrupts
also
include
the
ISRs
for
those
interrupts as an additional component of the device driver.
The functions of a device driver can be called by
application software tasks that would like to get some
hardware I/O-related activities to happen.
ECU
Application Software
RTOS
Device
Driver
Device Hardware
Tasks, Processes,
Threads
RTOS Interface
(Optional)
Device-Independent
Services
Example:
Synchronization to
Application
Hardware
Abstraction Layer
Application Software
RTOS
Device
Driver
Device Hardware
Components of a Driver
Collection of Functions
That Make Useful Things Happen to an Input/Output (I/O) Device
Callable from Application Code, Tasks
Each Function may be structured as 1 or 2 Layers
Provide Mechanism to Operate I/O Device, Not Policy
Interrupt Service Routine(s)
To Handle Interrupt(s) from the I/O Device
Device Interrupt
Service
Device
Init.
Device
Start.
Device
Open
Device
Close
Device
Read
Device
Hardware
Device
Device Device Device Device
Device
Simulate
Get
Get
Set
Abort
Write
Interrupt Info
Config Config. Read
Device
Abort
Write
User
Application
User Mode
Print
Im TSK1
Print
Im TSK2
Im TSK1 Im TSK2
Beware: Libraries
Asynchronous Driver
Requesting Task continues to execute, while Driver I/O
operation is underway
Issue: Whats it going to do at that time?
Example: Input device: Task can not yet process the Input it
Requested
Categories of I/O
Passive I/O
On-Demand or Polled
Interrupt-Driven I/O
Input: Interrupt -> New input
ready to be processed
Output: Interrupt -> Finished
with previous output
Ready for next output data
Device
DevRead()
Device
Interrupt
Service
Device
Hardware
Device
Hardware
DMA
Device
Interrupt
Service
Device
Hardware
Driver
DevInit()
Application Task
dv_read()
Driver
DevRead()
Application Task
dv_write()
RTOS
Driver
DevWrite()
Device
Hardware
Application Task
dv_read()
RTOS
Driver
DevRead()
Semaphore
Device
Interrupt
Service
Device
Hard
ware
RTOS
Driver
DevRead()
Device_Interrupt Service
DEVICE_ISR:
BEGIN
Handle Hardware Data/Status;
semaphore_release (DONE);
/* Signal Completion */
END
Semaphore
Device
Interrupt
Service
Device
Hard
ware
Application Task
dv_read()
RTOS
Driver
DevRead()
Mail Box
Device
Interrupt
Service
Device
Hard
ware
Device_Interrupt Service
ASYNC_OP:
BEGIN
rc= mailbox_pend( D_IN, Q_NOWAIT);
if (rc!= 0) .../* Error */
Start next Input Operation at H/W;
Process D_IN Status/Data;
END
Application Task
dv_read()
RTOS
Driver
DevRead()
DEVICE_ISR:
BEGIN
Transfer Data/Status from H/W;
mailbox_post (D_IN);
/* Send new data */
END
Mail Box
Device
Interrupt
Service
Device
Hard
ware
RTOS
Driver
DevRead()
QUEUE
Interrupt
Service
Device
Hard
ware
Device_Interrupt Service
ASYNC_OP:
BEGIN
rc= queue_receive ( D_IN, Q_WAIT);
if (rc!= 0) .../* Error */
Process D_IN Status/Data;
END
Application Task
dv_read()
RTOS
Driver
DevRead()
DEVICE_ISR:
BEGIN
Transfer Data/Status from H/W;
queue_send (D_IN); /*New data*/
END
QUEUE
Device
Interrupt
Service
Device
Hard
ware
Design Model 5 :
Latest Input Only
Application Task
dv_read()
RTOS
Driver
DevRead()
Semaphore
Shared
Data Area
Device
Interrupt
Service
Device
Hard
ware
Application Task
dv_read()
RTOS
Driver
DevRead()
Shared
Data
Area
Device
Interrupt
Service
Device
Hard
ware
RTOS
Driver
DevRead()
Shared
Data
Area
Device
Interrupt
Service
Device
Hard
ware
Application Task
dv_read()
RTOS
Driver
DevRead()
Shared
Data
Area
Device
Interrupt
Service
Device
Hard
ware
Design Model 7 :
Latest Input But No RTOS (Way #2)
Application Task
dv_read()
RTOS
Driver
DevRead()
Shared
Data
Area
Device
Interrupt
Service
Device
Hard
ware
Application Task
dv_read()
RTOS
Driver
DevRead()
Update
Count
Shared
Data
Area
Device
Interrupt
Service
Device
Hard
ware
Design Model 8 :
Latest Input But No RTOS (Way #3)
Update
Bit
Application Task
dv_read()
RTOS
Driver
DevRead()
Shared
Data
Area
Device
Interrupt
Service
Device
Hard
ware
Application Task
dv_read()
RTOS
Driver
DevRead()
Update
Bit
Shared
Data
Area
Device
Interrupt
Service
Device
Hard
ware
Design Model 9 :
Simple Asynchronous Output Driver
Application
Task
dv_write()
RTOS
Driver
DevWrite()
Task
Message
Waiting
Queue
Queue
Device
Interrupt
Service
Device
Hard
ware
ASYNC_OP:
BEGIN
queue_receive ( STAT, Wait);
Wait for H/W done/status */
IF( STAT is O.K. )
Start next Output Operation;
ELSE ...
END
Application Task
dv_write()
RTOS
Driver
DevWrite()
DEVICE_ISR:
BEGIN
Fetch Status from H/W;/*
queue_send (STAT);
/* Send new status */
END
Task
Message
Waiting
Queue
Queue
Device
Interrupt
Service
Device
Hard
ware
Further Reading