23162880 Ppt 1 Device Drivers Dp Brds

download 23162880 Ppt 1 Device Drivers Dp Brds

of 52

Transcript of 23162880 Ppt 1 Device Drivers Dp Brds

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    1/52

    INTRODUCTION TO DEVICE DRIVERS

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    2/52

    INDEX

    Device drivers basics Types of drivers

    Driver Implementation Concepts

    Introduction to DP Boards & Drivers

    Details of DP-MM-1105

    Details of DP-cPCI-3096

    Details of DP-IP-4221

    Details of DP-cPCI-4509

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    3/52

    Device driver basics

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    4/52

    Basics of device driver

    What is a device driver ?

    Why we need device driver ?

    Where device drivers are located ?

    What are the types of device drivers ?

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    5/52

    Basics of device driver

    Specialized device specific software that controls thedevice and exports usable interface for other programs to

    interact with the device.

    OS cannot be expected to know about the details of each

    device so, to control the device, device specific software

    (device driver) is necessary.

    Device drivers are modules that can be plugged into the

    Linux kernel dynamically.

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    6/52

    Device driver in kernel

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    7/52

    Types of device drivers

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    8/52

    Types of device drivers

    Character drivers

    Block drivers

    Network drivers

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    9/52

    CHARACTER DRIVERS

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    10/52

    Character driver concepts

    Char devices are accessed using files called device files(or) node files (or) special files.

    Char device files are located at the location /dev/

    Identified by c in first column of output of ls -lcommand.

    Major & Minor Number : The major number identifies the driver associated with the

    device. The minor number is used by the kernel to determine

    exactly which device is being referred to.

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    11/52

    Character driver concepts

    Internal representation of device number

    The dev_t type (defined in ) is usedto hold device numbersboth the major and minorparts.

    To obtain the major or minor parts of a dev_t, use:

    MAJOR(dev_t dev);

    MINOR(dev_t dev);

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    12/52

    Character driver concepts

    Data Structures:

    1. struct file_operations

    Connects driver operations to device numbers

    Defined in

    Its a collection of function pointers

    Each member points to the specific function in the driver

    Fields of the file_operations structure

    ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);

    ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    13/52

    Character driver concepts

    int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned

    long); int (*open) (struct inode *, struct file *);

    int (*release) (struct inode *, struct file *);

    struct file_operations dpxxxx_fops ={

    .read = dpxxxx_read,

    .write = dpxxxx_write,

    .ioctl = dpxxxx_ioctl,

    .open = dpxxxx_open,

    .release = dpxxxx_release

    };

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    14/52

    Character driver concepts

    2. struct file

    Defined in .

    Different from file pointer of user space program.

    Every open file in the system has an associated struct file in

    kernel space. Driver doesnt create but only use this structure.

    Field of struct file mode_t f_mode;

    loff_t f_pos;

    unsigned int f_flags; struct file_operations *f_op;

    void *private_data;

    struct dentry *f_dentry;

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    15/52

    Character driver concepts

    3. struct inode

    The inode structure is used by the kernel internallyto represent files.

    There can be numerous file structures representingmultiple open descriptors on a single file, but theyall point to a single inode structure.

    Following two fields of this structure are of interestfor writing driver code:

    dev_t i_rdev struct cdev *i_cdev

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    16/52

    Character driver concepts

    Char Device Registration & Release:

    Function to register a char device driver:

    int register_chrdev(unsigned int major, const char *name,

    struct file_operations *fops);

    Function to release a char device driver:

    int unregister_chrdev(unsigned int major, const char *name);

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    17/52

    BLOCK DRIVERS

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    18/52

    Block driver concepts

    Provides access to devices that transferrandomly accessible data in fixed-size blocksdisk drives.

    Block : A blockis a fixed-size chunk of data,the size being determined by the kernel.(normal size 4096 bytes).

    Sector : A sectoris a small block whose size isusually determined by the underlyinghardware. The kernel expects to be dealingwith devices that implement 512-byte sectors.

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    19/52

    Block driver concepts

    Block Driver Registration:

    int register_blkdev(unsigned int major, const char*name);

    To register block driver in the kernel.

    Declared in

    int unregister_blkdev(unsigned int major, const char*name);

    For canceling a block driver registration.

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    20/52

    Block driver concepts

    Data Structures:

    1. struct block_device_operations

    Used to make driver operations available to the system

    Declared in

    Structure fields int (*open)(struct inode *inode, struct file *filp);

    int (*release)(struct inode *inode, struct file *filp);

    int (*ioctl)(struct inode *inode, struct file *filp, unsigned int cmd,

    unsigned long arg); int (*media_changed) (struct gendisk *gd);

    int (*revalidate_disk) (struct gendisk *gd);

    struct module *owner;

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    21/52

    Block driver concepts

    2. struct gendisk

    Kernels representation of an individual diskdevice.

    Declared in Structure fields

    int major;

    int first_minor;

    int minors; char disk_name[32];

    struct block_device_operations *fops;

    struct request_queue *queue;

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    22/52

    Block driver concepts

    int flags; sector_t capacity;

    void *private_data;

    Kernel Functions to work with gendisk structure struct gendisk *alloc_disk(int minors);

    void del_gendisk(struct gendisk *gd);

    void add_disk(struct gendisk *gd);

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    23/52

    Block driver concepts

    Request Function :

    Core function of every block driver.

    Prototype:

    void request(request_queue_t *queue);

    Associated with request queue.

    Runs atomically.

    Asynchronous to user space process.

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    24/52

    Block driver concepts

    Request Queue :

    A queue of block I/O requests

    Keep track of outstanding block I/O requests.

    Stores parameters that describes kinds of requeststhe device is able to service: Maximum size.

    Maximum no. of segments may go into a request.

    Hardware sector size.

    Alignment requirements.

    Implements a plug-in interface to allow the use ofmultiple I/O schedulers (orelevators).

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    25/52

    NETWORK DRIVERS

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    26/52

    Network driver concepts

    Features

    Necessary for data communication.

    No special files.

    Block drivers operate only in response to requests from the kernel,whereas network drivers receive packets asynchronously from the outside.

    Should support administrative tasks.

    Set addresses.

    Modify transmission parameters. Maintain traffic and error statistics.

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    27/52

    Driver Implementation Concepts

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    28/52

    Two ways of implementing drivers

    Traditional built-in drivers compiled into the kernel

    loaded when the kernel boots

    always loaded, can not be removed

    programming interface somewhat limited

    Loadable kernel module drivers

    can be loaded and unloaded on demand

    a more general programming interface

    Can be designed, written and installed long after kernel has

    been compiled and OS installed

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    29/52

    Kernel space - User space interaction methods

    Real Time FIFO Device File

    IOCTL Layer

    copy_from_user

    copy_to_user

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    30/52

    Control Flow diagram

    application

    IOCTL Layer

    User Space

    Kernel Space

    KernelDriver Module

    Hardware Device

    FIFO FIFO

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    31/52

    Introduction to DP Boards & Drivers

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    32/52

    DP Boards

    DP Boards are categorized as follows:

    1. Data Acquisition Boards (DP-MM-1105)

    2. Input/Output Boards (DP-cPCI-3096)

    3. Communication Boards (DP-IP-4221)4. Relay Boards (DP-cPCI-4509)

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    33/52

    DP Drivers

    DP Drivers are Character drivers General driver API Calls

    DPxxxx_FindNoOfBoards

    DPxxxx_Open (DPxxxx_RTOpen)

    DPxxxx_Close (DPxxxx_RTClose) DPxxxx_GetErrorMessage

    DPxxxx_GetDriverVersion

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    34/52

    DP-MM-1105

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    35/52

    DP-MM-1105 Features

    Fast analog input M-Module 16 bit, Analog to Digital Conversion

    8 differential voltage inputs or 16 single ended voltage inputs

    Programmable gain 1, 10,100 or 1000

    512 Entry Scan RAM for Scan Sequencing

    1 K Sample FIFO for converted data

    Numerically controlled Oscillator for flexible scan frequency

    Digitally isolated channel to system for high linearity

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    36/52

    DP-MM-1105 API Calls

    DP1105_DetectMModules() DP1105_Open() (or) DP1105_RTOpen()

    DP1105_Close() (or) DP1105_RTClose()

    DP1105_ConfigureADC()

    DP1105_UpdateScanList()

    DP1105_StartAcquisition()

    DP1105_Trigger()

    DP1105_StopAcquisition()

    DP1105_GetRecentSample()

    DP1105_BulkRead()

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    37/52

    DP-MM-1105 API Calls

    DP1105_ReadBuffer () DP1105_CheckStatus()

    DP1105_ReadCalibrationTable()

    DP1105_WriteCalibrationTable()

    DP1105_Calibrate ()

    DP1105_GetErrorMessage()

    DP1105_CalibrateSingleEnded()

    DP1105_EnableInterrupt()

    DP1105_GetDrvVer()

    DP1105_GetFifo()

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    38/52

    DP-MM-1105 Configuration

    DP1105_CONFIGURATION Structure.

    Input type (1 Single ended, 0 Differential).

    Pacer Source (0 Internal, 1 External, 2 Software Pacer).

    Pace Frequency If Internal Pacer source is selected (in Hz).

    Trigger type (0 Internal Trigger (through software), 1 External Trigger).

    Continuous Trigger type (No Continuous Trigger 0, Timer Trigger Enable 1,

    Continuous Internal Trigger Enable 2).

    External Trigger Signal type (0 Positive Edge sensitive, 1 Negative Edge

    sensitive).

    Time Period Time period between two successive triggers if Timer Trigger is enabl

    (In multiples of 100 microseconds).

    Buffer size The internal buffer size (in number of samples). Source Type The Parameter specifies the Voltage and Current type. Possible valu

    are 1 and 2.

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    39/52

    Input / Output Modules General Features

    Self Test Facility

    Interrupt types Input Interrupt

    State Change Interrupt

    Board Strobe Interrupt

    Group Strobe Interrupt

    Ability to Read Back

    Actual Data

    Interrupt Interrupt data

    State Change Input data

    Strobed Input data

    Primary Latch & Secondary Latch for Output Channels

    Programmable Debounce Time Feature

    Some of the DP I/O Modules are (3096 3069, 3015)

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    40/52

    DP-cPCI-3096

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    41/52

    DP-cPCI-3096 Features

    48 Channel Isolated Digital Input / Interrupt 48 Channel Isolated Digital Open Collector Output with

    200mA Sink Current

    Isolation in group of 16 channels

    Jumper selectable input levels of 5, 12, 24 & 48V DC

    Time programmable debounce for input

    Programmable interrupt (Maskable, Edge selectable).

    Build-in self test for each group.

    Additional 48 Input and 48 Output channel through rear I/O

    Relay coil flyback protection for output channels Hot swap compliant

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    42/52

    DP-cPCI-3096 API Calls

    DPcPCI3096_FindDevices DPcPCI3096_Open (or) DPcPCI3096_RTOpen

    DPcPCI3096_Close (or) DPcPCI3096_RTClose

    DPcPCI3096_ConfigMode

    DPcPCI3096_SetDebounceTime DPcPCI3096_SelfTest

    DPcPCI3096_GroupStatus

    DPcPCI3096_MaskGroup

    DPCPCI3096_MaskChannel DPcPCI3096_GroupEdgeSelect

    DPcPCI3096_ChannelEdgeSelect

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    43/52

    DP-cPCI-3096 API Calls

    DPcPCI3096_StrobeGroup DPcPCI3096_BoardStrobe

    DPcPCI3096_ClearInterrupt

    DPcPCI3096_ClearAllInterrupts

    DPcPCI3096_WriteGroupData DPcPCI3096_EnableOutput

    DPcPCI3096_ReadbackInput

    DPcPCI3096_ReadInterruptStatus

    DPcPCI3096_ReadbackOutput DPcPCI3096_Reset

    DPCPCI3096_GetErrorMsg

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    44/52

    DP-IP-4221

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    45/52

    DP-IP-4221 Features

    Provides eight asynchronous serial communicationports from a single IP carrier slot.

    Provides programmable Baud rates, character-sizes,

    stop bits, and parity.

    Each serial port is equipped with 128-byte FIFObuffers each on transmit and receive lines, minimizing

    CPU interaction for improved system performance.

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    46/52

    DP-IP-4221 API Calls

    DPIP4221_FindDevices

    DPIP4221_Open

    DPIP4221_Close

    DPIP4221_SetBaudRate

    DPIP4221_SetWordLength DPIP4221_SetStopBit

    DPIP4221_SetParity

    DPIP4221_SetMode

    DPIP4221_SetModemControl

    DPIP4221_GetRxFIFOCount

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    47/52

    DP-IP-4221 API Calls

    DPIP4221_GetTxFIFOCount

    DPIP4221_LoopBackMode

    DPIP4221_TransmitData

    DPIP4221_ReceiveData

    DPIP4221_FlushFIFO

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    48/52

    DP-cPCI-4509

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    49/52

    DP-cPCI-4509 Features

    High voltage switching of up to 220V AC/ DC

    Relays can be operated individually, or in groups of

    16 relays each

    Relay status provided through read back

    Rugged connectors for field terminations

    Hot swap feature

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    50/52

    DP-cPCI-4509 API Calls

    DPcPCI4509_FindDevices DPCPCI4509_Open

    DPCPCI4509_Close

    DPcPCI4509_SetRelay

    DPcPCI4509_SetGroup DPcPCI4509_SetTrigger

    DPcPCI4509_ReadSetValue

    DPcPCI4509_ReadRelay

    DPcPCI4509_ReadGroup

    DPcPCI4509_GetErrorMsg

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    51/52

    Question(?) Time

  • 7/27/2019 23162880 Ppt 1 Device Drivers Dp Brds

    52/52

    THANK YOU