Chap04Lesson13Emsysdevicedriversfunctions

Embed Size (px)

Citation preview

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    1/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    1

    DEVICE DRIVERS AND TERRUPTS SERVICE

    MECHANISM

    LessonLesson--13:13: Multiple device functionsMultiple device functions

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    2/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    2

    Multiple functions in a Timer deviceMultiple functions in a Timer device A timerdevice control registers needs to be

    programmed by a device function. A timer

    device performs does timing functions as

    well as counting functions. It also performs

    does the delay function and periodic systemcalls.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    3/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    3

    Multiple functions in a Transceiver deviceMultiple functions in a Transceiver device A transceiverdevice control registers needs to be

    programmed by a device function

    A transceiverdevice does transmitting as well asreceiving functions.

    It may not be just a repeater. It may also do the

    jabber control andcollision control. Jabber control means prevention of that it prevent

    continuous streams of unnecessary bytes in case of

    some system fault. Collision control means that it must first sense the

    network bus availability then only transmit.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    4/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    4

    Multiple functions in a deviceMultiple functions in a device

    Voice-data-fax modem device hastransmitting as well as receiving functions

    for voice, fax as well as data.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    5/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    5

    DEVICE DRIVERDEVICE DRIVER

    A program that controls the

    functioning of a device.

    Every device, whether it be a

    peripheral such as printer, LCD displayunit, keypad or an internal device such

    as timer, must have a driver.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    6/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    6

    Common driver or the separate driversCommon driver or the separate drivers

    A common driver or the separate drivers for

    each device function are required.

    Device-drivers are the important routines in

    a system Routines generic functions, such as create

    ( ), open ( ), connect ( ), listen ( ), accept ( ),

    read ( ), write ( ), close ( ), delete ( ) for useby high level programmers

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    7/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    7

    Device Driver

    System has number of physical devices.A device may have multiple functions.

    Each device function is controlled by thedriver

    The driver provides a software layer

    (interface) between application and the

    actual device.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    8/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    8

    The driver facilitates the use of device by

    using the generic commands sent byapplication program-steps.

    Once a driver is available, application

    programmer does not need to know any

    thing about the mechanism, addresses,

    registers, bits and flags used by the device.

    Device Application programmer usingDevice Application programmer using

    the generic commandsthe generic commands

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    9/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    9

    Device Driver FunctionDevice Driver Function

    The driver function is to translate a

    generic command in an application(user software) into specific set of

    commands that the device understands.

    Generic command means a command

    used for the number of devices or

    device groups.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    10/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    10

    DEVICE DRIVERDEVICE DRIVER

    Many times, the drivers, such as the

    keypad driver, LCD display unit driver,modem driver, are available to an

    application program from the operating

    system.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    11/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    11

    DEVICE DRIVERDEVICE DRIVER

    Several times, drivers, such as LCD display

    unit driver for the multilingual display, notavailable at the OS have to written by the

    application programmer or sourced from

    other programmer for an embedded system

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    12/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    12

    Driver routine as a black boxDriver routine as a black box

    Simple commands from a task or function

    can then drive the device. Once a driver is available, application

    developer does not have to know the any

    thing about the mechanism, addresses,registers, bits and flags used by the device.

    For example, consider a case when system

    clock is to be set to tick every 10000 s(100 times each second).

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    13/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    13

    Driver routineDriver routine OS_TicksOS_Ticks (100) as a black box(100) as a black box

    The user of OS for the application simply makes a

    call to function like OS_Ticks (100)

    It is not necessary for the user this function to

    know which timer device will do that.

    What are the addresses, which, will be used by the

    driver? Which will be the device register where

    value 100 for the ticks registers?

    What are the control bits that will be set or reset?

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    14/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    14

    Driver routineDriver routine OS_TicksOS_Ticks (100)(100) When runs, simply interrupts the system and

    executes the software interrupt (SWI) instruction

    which calls the signaled routine (driver) for the

    system ticking device.

    Then the driver, which executes will takes 100 as

    inputand will configures the real time clock to let

    the system clock tick each 10000 s and generate

    continuously the system clock interrupts

    continuously every 10000 s to get 100 ticks each

    second

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    15/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    15

    Accesses the device through interrupt (s),

    and drives a peripheral device or internal

    device through generic commands.

    User dont have to write codes when OS

    provides the drivers. A devices file descriptor is shared by the

    commands and interrupt service routines,

    which execute those commands.

    Device driver accesses to the deviceDevice driver accesses to the device

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    16/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    16

    Application Program Access to a DeviceApplication Program Access to a Device

    Access to a device is by using genericcommands of the driver.

    When a command executes in applicationprogram, device driver generates an

    interrupt (using an SWI instruction, such asINT n or SWI m) to the device occurs.

    An interrupt service routine corresponding

    to that command is then executed.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    17/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    17

    DEVICE DRIVERDEVICE DRIVER

    Several times, drivers, such as LCD display

    unit driver for the multilingual display, notavailable at the OS have to written by the

    application programmer or sourced from

    other programmer for an embedded system

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    18/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    18

    A Device Driver CommandA Device Driver Command A device may be configured

    (commanded), for example, configuredto read or write or read and write both

    through the port address (es).

    Device may be set to function in

    different modes. For example, mode 0

    for one data transfer rate, 1 for another.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    19/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    19

    File descriptorFile descriptor

    A general term File descriptor refers to

    device descriptor data structure

    A data structure accessed by theprogrammer using an integer number, fd

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    20/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    20

    Driver Generic commands examplesDriver Generic commands examples

    fd = open (device1, O_RDWR, 0) in

    an application. Means configure the device at address

    device1 for the read as well as write

    operations and set the device for mode

    0 functions. fd1 is device1 descriptor

    pointer, which open function returns.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    21/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    21

    DescriptorDescriptor

    Device Status, Mode, Present config.Read buffer start and end addresses

    Device port address(es)

    Write buffer start and end addressesCurrent cursor position address(es)

    for read or write or read-write.

    Routine addresses for the open,

    write, read, close and other functions

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    22/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc.

    22

    CursorCursor

    Current cursor address is an addressfrom address at the buffer from where

    the read (operation) will be done onnext read command or to where thewrite (operation) will be done in next

    write operation. For example, cursor inan LCD display means the address(position) for the write (then display)

    from which line number (row) whichcharacter number (column).

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    23/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 23

    Driver Generic commands exampleDriver Generic commands example 22

    write (fd1, device1, 1024) in the

    application means write into the device

    buffer 1024 Bytes from current cursor

    position. Device if set in mode 0 thentransmit from the buffer at the rate

    defined for its mode 0 operation.

    Device descriptor is at fd1.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    24/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 24

    Driver Generic commands example 3Driver Generic commands example 3

    msg1 = read (fd1, device1, 32) in theapplication means (a) device is device

    at address (b) descriptor is at fd1 (c)

    read and save at msg1 from the device

    buffer the 32 Bytes from current cursor

    position.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    25/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 25

    Driver Generic commands example 4Driver Generic commands example 4

    fd1 = close (device1) in an applicationmeans close the device1 and save the device

    current status after close operation. The

    device can now be reused only after firstexecuting open function.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    26/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 26

    For each type of device, there is a set

    of the generic commands. For example, for char device one set

    of commands and for block devicethere can be another set.

    Device TypesDevice Types

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    27/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 27

    SummarySummary

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    28/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 28

    We learnt

    (i) The driver accepts generic commandsfrom an application or OS program andthen translates each command into a

    set of specialized commands for thedevice.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    29/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 29

    We learnt

    (ii) The driver provides a software

    layer (interface) betweenapplication and the actual device.

    (iii) A device is configured andinitialized by the function open of

    the driver.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    30/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 30

    We learnt (v) A device is deactivated by the

    function close at the driver.

  • 7/30/2019 Chap04Lesson13Emsysdevicedriversfunctions

    31/31

    2008 Chapter-4 L13: "Embedded Systems - Architecture, Programming andDesign" , Raj Kamal, Publs.: McGraw-Hill, Inc. 31

    End of Lesson 13 of Chapter 4End of Lesson 13 of Chapter 4