zoukankan      html  css  js  c++  java
  • usb驱动---linux ACM驱动详解ACA【转】

    转自:http://blog.chinaunix.net/uid-9185047-id-3404684.html

    DTE提供或接收数据,连接到网络中的用户端机器,主要是计算机和终端设备。与此相对地,在网络端的连接设备称为 DCE ( Date Circuit - terminating Equipment )。DTE与进行信令处理的DCE相连。 它是用户—网络接口的用户端设备,可作为数据源、目的地或两者兼而有之。

       

    数据终端设备

    DTE通过DCE设备(例如,调制解调器)连接到数据网络,且一般使用DCE产生的时钟信号。DTE包括像计算机、协议转换器多路复用器这样的设备。

    Module_init中会注册tty_driver,tty_device会在acm usb_driver的probe中注册。

    每个ACM设备都由2个Interface组成,第一个interface有一个interrupt endpoint主要负责控制,第二个interface主要负责数据传输,有2个endpoint,有可能是两个int,也有可能是2个bulk。他们都是成对出现的。

    比如:

    这个是第一个interface,其中CDC Union中,bMasterInterface就是设备的第0号interface,它就是ACM中的第一个interface,作为主interface,它所对应的从interface的号是1,也就是负责数据传输的那个interface。他们两个是成对出现的。

        Interface Descriptor:

          bLength                 9

          bDescriptorType         4

          bInterfaceNumber        0

          bAlternateSetting       0

          bNumEndpoints           1

          bInterfaceClass         2 Communications

          bInterfaceSubClass      2 Abstract (modem)

          bInterfaceProtocol      1 AT-commands (v.25ter)

          iInterface              4 CDC Communication Interface

          CDC Header:

            bcdCDC               1.10

          CDC Union:

            bMasterInterface        0

            bSlaveInterface         1

          CDC Call Management:

            bmCapabilities       0x00

            bDataInterface          1

          CDC ACM:

            bmCapabilities       0x07

              sends break

              line coding and serial state

              get/set/clear comm features

          Endpoint Descriptor:

            bLength                 7

            bDescriptorType         5

            bEndpointAddress     0x81  EP 1 IN

            bmAttributes            3

              Transfer Type            Interrupt

              Synch Type               None

              Usage Type               Data

            wMaxPacketSize     0x0040  1x 64 bytes

            bInterval               4

    第二个

        Interface Descriptor:

          bLength                 9

          bDescriptorType         4

          bInterfaceNumber        1

          bAlternateSetting       0

          bNumEndpoints           2

          bInterfaceClass        10 CDC Data

          bInterfaceSubClass      0 Unused

          bInterfaceProtocol      0

          iInterface              5 CDC Data Interface

          Endpoint Descriptor:

            bLength                 7

            bDescriptorType         5

            bEndpointAddress     0x82  EP 2 IN

            bmAttributes            2

              Transfer Type            Bulk

              Synch Type               None

              Usage Type               Data

            wMaxPacketSize     0x0200  1x 512 bytes

            bInterval               0

          Endpoint Descriptor:

            bLength                 7

            bDescriptorType         5

            bEndpointAddress     0x02  EP 2 OUT

            bmAttributes            2

              Transfer Type            Bulk

              Synch Type               None

              Usage Type               Data

            wMaxPacketSize     0x0200  1x 512 bytes

            bInterval               0

        Interface Association:

          bLength                 8

          bDescriptorType        11

          bFirstInterface         2

          bInterfaceCount         2

          bFunctionClass          2 Communications

          bFunctionSubClass       2 Abstract (modem)

          bFunctionProtocol       1 AT-commands (v.25ter)

          iFunction               0

    在第一个interaface被匹配后,它对应的probe函数中,会找到它所对应的slave interface,并用

    usb_driver_claim_interface(&acm_driver, data_interface, acm);来对其声明,让这两个interface device匹配同一个usb_driver。

    虽然在module_init中注册了tty_driver,但是此时它是不工作的,在probe的结尾会调用

    tty_register_device(acm_tty_driver, minor, &control_interface->dev); 

    这句话是注册tty_driver所对应的tty_device,此时他们俩会匹配,并创建相应的字符设备。这个时候user space才可以对其进行访问!

    其中在probe中,会有三个ep

    Epcontrol

    Epread

    Epwrite

    其中control是interrupt ep,在tty_open的时候会注册到系统中,监听control event.

    Epread对应一个urb,也是在tty_open时被submit,每次接收到数据后,urb的callback了都会调用tty_flip_buffer_push将数据提交给tty子系统的flip buffer中。

    Epwrite则是在tty_write中调用。

    acm_tty_throttle会在最后一次read urb处理的callback中进行判断是否继续提交,因为tty子系统的flip buffer已经满了,直到acm_tty_unthrottle中会再次提交read urb。

    acm_tty_break_ctl是用来发送break信号的,RS232规定,收到break信号后,要output一段时间的logic zero。

    acm_tty_tiocmset和acm_tty_tiocmget主要是来设置和查询当前的CS232的硬件信号的支持。比如RTS信号

    而acm_tty_set_termios主要就是设置什么奇偶校验,波特率等串口传输特性。

  • 相关阅读:
    Docker入门之docker-compose [转]
    防火墙和iptables
    MariaDB/MySQL备份和恢复(三):xtrabackup用法和原理详述
    Veritas NetBackup™ for VMware 介绍 (NBU版本 8.2)
    RMAN备份恢复所需要了解的Oracle术语
    mac 下使用命令行打开项目
    ORACLE 11g RAC-RAC DG Duplicate 搭建(生产操作文档)
    15-vuex
    14-Promise
    13-vue-router2
  • 原文地址:https://www.cnblogs.com/sky-heaven/p/5594113.html
Copyright © 2011-2022 走看看