Device Drivers - University at Buffalo

Device Drivers - University at Buffalo

Device Drivers 1 B. RAMAMURTHY 01/16/20 Introduction 2 A device driver is computer program that allows a system to interface with hardware devices. Example driver: printer driver, bluetooth driver, pipe driver Example devices: your USB stick, sensors:

accelerometer It is a translator between the operating system and applications the use the devices and the devices. A typical operating system has many device drivers built into it. A device driver converts general IO instructions into device specific operations. Device drivers operate in a privileged mode requires careful design 01/16/20 Why Device Driver? 3 A typical computing system (lap top, computer,

cell phone, PDA, Point of sale system) deals with a variety of devices. Making a hardware device work as expected is a cumbersome task. Instead adding this code every application, operating system provides a single point interface for all devices by hosting the device drivers. Adding it under the operating systems provides the protection and security needed for the device drivers from malicious use. The device drivers are essentially shared dynamically linked libraries. 01/16/20 File abstraCtion 4 What do you with a device? {read, write}, {read only}, {write only}

Lets look at some examples: USB device, CDROM, LED Display, What do you do with a file? open, close, read, write, .. File is an excellent abstraction for devices. 01/16/20 /dev partial listing 5

total 380 lrwxrwxrwx 1 root 30 Mar 7 2004 allkmem -> ../devices/pseudo/[email protected]: allkmem lrwxrwxrwx 1 root 27 Aug 15 2001 arp -> ../devices/pseudo/[email protected]:arp lrwxrwxrwx 1 root 7 Aug 15 2001 audio -> sound/0 lrwxrwxrwx 1 root 10 Aug 15 2001 audioctl -> sound/0ctl

lrwxrwxrwx 1 root 11 Oct 4 03:06 -> /dev/term/b drwxr-xr-x 2 root 512 Aug 17 2001 cfg lrwxrwxrwx 1 root 31 Aug 15 2001 conslog -> ../devices/pseudo/[email protected] :conslog lrwxrwxrwx 1 root 30 Aug 15 2001 console -> ../devices/pseudo/[email protected]: console drwxr-xr-x 2 root 512 Aug 15 2001 cua drwxr-xr-x 2 root 2048 Aug 31 2002 dsk lrwxrwxrwx 1 root 29 Aug 15 2001 dump -> ../devices/pseudo/[email protected]:d ump lrwxrwxrwx 1 root 50 Aug 15 2001 ecpp0 -> ../devices/[email protected],4000/eb [email protected]/[email protected],3043bc:ecpp0 lrwxrwxrwx 1 root

8 Aug 15 2001 fb0 -> fbs/ffb0 drwxr-xr-x 2 root 512 Aug 15 2001 fbs dr-xr-xr-x 2 root 528 Nov 9 11:51 fd lrwxrwxrwx 1 root 30 Apr 7 2002 fssnapctl -> ../devices/pseudo/ 01/16/20 Device SPACE 6 Typically there are multiple devices of the same type. All the devices controlled by the same device driver is given the same major number A minor number distinguishes among the devices of the same type. Example: printers have a major number since

purpose is same, minor# is denote a specific printer 01/16/20 Examples from XINU 7 Take a look at files in the include directory: device.h tty.h uart.h Also in the system directory devtable.c, initialize.c Bottom line is this, for a device xyz: 1. Include a file in include directory: xyz.h -- define the operations/functions for the device 2. Add a directory xyz -- implement all functions each in its own file 3. Add an entry in the devtable.c for the device (note that

this has the minor device number along with other things) 01/16/20 Lets Analyze the XINU UART Driver 8 Starting point: uart.h in include directory uart directory functions system directory devtable.c, initialize.c Usage of the devices is through device table: Ex: pdev = &devtab[i]; (pdevinit)(pdev); 01/16/20 UART Driver in EXINU 9

1. General device driver related files: device.h, devtable.c 2. Uart files: uart.h defining the physical features of the uart 3. All the files in the uart directory that implement the operations related to the uart. uartControl.c uartInit.c uartIntr.c uartPutChar.c uartWrite.c uartGetChar.c uartRead.c 01/16/20 Device Drivers 10 On board devices are called internal

peripherals and one outside are called external peripherals UART Chip (internal) TTY (external) UART transceiverRS232D-9 connector laptop serial socket WRT54GL board and modifications 01/16/20 Device drivers (contd.) 11 Embedded processor interacts with a

peripheral device through a set of control and status registers. Registers are part of the peripheral device. Registers within a serial controller are different from those in a timer. These devices are located in the memory space of the processor or I/O space of the processor-- two types: memory-mapped or I/ O mapped respectively. 01/16/20 Device driver (contd.) 1. 1 2 The keyword volatile should be used when declaring pointers to device drivers. Bit patterns for testing, setting, clearing, toggling, shifting bits, bitmasks, and bitfields.

Struct overlays: In embedded systems featuring memory mapped IO devices, it is common to overlay a C struct on to each peripherals control and status registers. This will provide the offsets for the various registers from the base address of the device. 01/16/20 Device Driver Philosophy 13 Hide the hardware completely: hardware abstraction If the device generates any interrupts include interrupt controllers. Device driver presents a generic interface for applications at higher level to access the devices: device.h Device drivers in embedded systems are different from general purpose operating systems: See diagram in

slide #14 Applications in general purpose systems accesses OS (Operating Systems) which in turn accesses device drivers. Applications in embedded systems can directly access device drivers. 01/16/20 General Purpose OS vs. Embedded System Applicatio n process Applicatio n process Operating System: dev/xyz

Device driver Device driver Physical Device hardware Physical Device hardware 14 01/16/20 Device Driver development steps 15

1. 2. 3. 4. 5. An interface to the control and status registers. Variables to track the current state of the physical and logical devices -- Major and minor device number, device name A routine to initialize the hardware to known state An API for users of the device driver -- Read, write, seek Interrupts service routines 01/16/20 Example: A serial device driver 16

Read the text for explanation and general example of a timer Now lets look at the UARTdriver of the embedded xinu and WRT54GL. Study the tty driver that is a logical device that is layered on top of the UART driver. In our Lab 2 you will write a device driver for a framebuffer. 01/16/20 Shift Operators 17 << left shift >> right shift Usage: unsigned int x = 70707;

//x = 00000000 00000001 00010100 00110011 unsigned int y, z; y = x << 2; // y = 00000000 00000100 01010000 11001100 z = x >> 2; //z = 00000000 00000000 01000101 00001100 01/16/20 Logic Operators 18 Bitwise & (AND) Bitwise inclusive | (OR) Bitwise exclusive ^ (XOR) Bitwise negation ~ Usage: unsigned exp1 = 1; unsigned exp2 = 4; printf ( %d\n, exp1 | exp2);

printf ( %d\n, exp1 & exp2); printf ( %d\n, exp1 ^ exp2); printf ( %d\n, ~exp1); 01/16/20 Relevance of shift and logic operators 19 Bitwise operations are necessary for much low-level programming, such as writing to device drivers, low-level graphics, communications protocol packet assembly and decoding. Device drivers use these operators to test the presence or absence of a bit in a serial port or a device input, for example. (checking for on or off) 01/16/20

Summary 20 We studied the design and development of device drivers. We analyzed the code for a sample UART driver. 01/16/20

Recently Viewed Presentations

  • Exploring the Americas

    Exploring the Americas

    Their primary purpose was t preach repentance and aid the poor. Franciscans engaged in early missionary work in the Middle East ... The larger French army followed no battle plan and attacked in a disorderly fashion. The . English archers...
  • Announcements  All participants must register for the Monthly

    Announcements All participants must register for the Monthly

    If the CIR was created via a MER, Index Case Information will be pre-populated from the corresponding fields within the MER for the patient. To update this information, return to the MER, make necessary corrections, and re-submit. ... Reporting Unit....
  • Ethics - FAMU-FSU Eng College

    Ethics - FAMU-FSU Eng College

    Learning Objectives Enhance the ability to deal with difficult ethical decisions Strengthen moral autonomy (self-determination) - the habit of thinking rationally about ethical issues following appropriate moral principles improve practical skills such as Recognize and understanding ethical situations Critical thinking...
  • DHS PowerPoint template - all slides - save a copy and edit it

    DHS PowerPoint template - all slides - save a copy and edit it

    Copies of time reporting policies and procedures from the following counties are being provided to you: Crow Wing, Meeker, Nobles, Pope, St. Louis, Sherburne, Wabasha and Wright. Review these and take the words/phrases that would work in creating the policy...
  • Presentazione di PowerPoint

    Presentazione di PowerPoint

    VANGELO (Luca 2,16-21) Questo vangelo è Parola di Dio. Quindi è Gesù che ci parla e ci dice: "Quando sono nato, i pastori vennero a Betlemme e trovarono proprio quello che aveva detto l'angelo: Maria, Giuseppe ed Io - il...
  • 8A1 Food -

    8A1 Food -

    8A1 Food Are these meals good for you? Dish of the Day Fried bacon Fried sausage Fried egg Fried bread Fried mushrooms Ice cream Today's Specials Fresh pasta with boiled rice and curry sauce Bread and butter pudding Chef's Choice...
  • SEEKING THINGS ABOVE Colossians 3:1 The Church at

    SEEKING THINGS ABOVE Colossians 3:1 The Church at

    Colossians 3: Text. 12* Therefore, as the elect of God, holy and beloved, put on tender mercies, kindness, humility, meekness, longsuffering; 13* bearing with one another, and forgiving one another, if anyone has a complaint against another; even as Christ...
  • Adolescents&#x27; Families - Simmons College

    Adolescents' Families - Simmons College

    Families Adolescents' Families Historically Today Impact Conflict Parenting Style Attachment Siblings Divorce Historical Change Patterns over Two Centuries Three changes over the past two centuries have influenced family life Lower birth rate In 1800, women in the U.S. had an...