linux usb学习笔记

USB 设备基础知识

usb端点

usb端点用一个结构体来描述
  USB 端点在内核中使用结构 struct usb_host_endpoint 来描述. 这个结构包含真实的端点信息在另一个结构中, 称为 struct usb_endpoint_descriptor. 后者包含所有的 USB-特定 数据, 以设备自身特定的准确格式. 驱动关心的这个结构的成员是:
  bEndpointAddress
这是这个特定端点的 USB 地址. 还包含在这个 8-位 值的是端点的方向. 位掩码USB_DIR_OUT 和USB_DIR_IN 可用来和这个成员比对, 来决定给这个端点的数据是到设备还是到主机.
  bmAttributes
这是端点的类型. 位掩码 USB_ENDPOINT_XFERTYPE_MASK 应当用来和这个值比对,来决定这个端点是否是 USB_ENDPOINT_XFER_ISOC, USB_ENDPOINT_XFER_BULK, 或者是类型 USB_ENDPOINT_XFER_INT. 这些宏定义了同步, 块, 和中断端点, 相应地.LINUX DEVICE DRIVERS,3RD EDITION
  wMaxPacketSize
这是以字节计的这个端点可一次处理的最大大小. 注意驱动可能发送大量的比这个值大的数据到端点, 但是数据会被分为 wMaxPakcetSize 的块, 当真正传送到设备时. 对于高速设备, 这个成员可用来支持端点的一个高带宽模式, 通过使用几个额外位在这个值的高位部分. 关于如何完成的细节见 USB 规范.
  bInterval
如果这个端点是中断类型的, 这个值是为这个端点设置的间隔, 即在请求端点的中断之间的时间. 这个值以毫秒表示.这个结构的成员没有一个”传统” Linux 内核的命名机制. 这是因为这些成员直接对应于USB 规范中的名子. USB 内核程序员认为使用规定的名子更重要, 以便在阅读规范时减少混乱, 不必使这些名子对Linux 程序员看起来熟悉

在usb.h这个文件里面

/*** struct usb_host_endpoint - host-side endpoint descriptor and queue* @desc: descriptor for this endpoint, wMaxPacketSize in native byteorder* @ss_ep_comp: SuperSpeed companion descriptor for this endpoint* @urb_list: urbs queued to this endpoint; maintained by usbcore* @hcpriv: for use by HCD; typically holds hardware dma queue head (QH)*  with one or more transfer descriptors (TDs) per urb* @ep_dev: ep_device for sysfs info* @extra: descriptors following this endpoint in the configuration* @extralen: how many bytes of "extra" are valid* @enabled: URBs may be submitted to this endpoint** USB requests are always queued to a given endpoint, identified by a* descriptor within an active interface in a given USB configuration.*/
struct usb_host_endpoint {struct usb_endpoint_descriptor      desc;struct usb_ss_ep_comp_descriptor    ss_ep_comp;struct list_head        urb_list;void                *hcpriv;struct ep_device        *ep_dev;    /* For sysfs info */unsigned char *extra;   /* Extra descriptors */int extralen;int enabled;
};

usb接口

  USB 端点被绑在接口中. USB 接口只处理一类 USB 逻辑连接, 例如一个鼠标, 一个键盘,或者一个音频流. 一些 USB 设备有多个接口, 例如一个 USB 扬声器可能有 2 个接口:一个 USB 键盘给按钮和一个 USB 音频流. 因为一个 USB 接口表示基本的功能, 每个USB 驱动控制一个接口; 因此, 对扬声器的例子, Linux 需要 2 个不同的驱动给一个硬件设备。
  还是在usb.h文件里面
  

/*** struct usb_interface - what usb device drivers talk to* @altsetting: array of interface structures, one for each alternate*  setting that may be selected.  Each one includes a set of*  endpoint configurations.  They will be in no particular order.* @cur_altsetting: the current altsetting.* @num_altsetting: number of altsettings defined.* @intf_assoc: interface association descriptor* @minor: the minor number assigned to this interface, if this*  interface is bound to a driver that uses the USB major number.*  If this interface does not use the USB major, this field should*  be unused.  The driver should set this value in the probe()*  function of the driver, after it has been assigned a minor*  number from the USB core by calling usb_register_dev().* @condition: binding state of the interface: not bound, binding*  (in probe()), bound to a driver, or unbinding (in disconnect())* @sysfs_files_created: sysfs attributes exist* @ep_devs_created: endpoint child pseudo-devices exist* @unregistering: flag set when the interface is being unregistered* @needs_remote_wakeup: flag set when the driver requires remote-wakeup*  capability during autosuspend.* @needs_altsetting0: flag set when a set-interface request for altsetting 0*  has been deferred.* @needs_binding: flag set when the driver should be re-probed or unbound*  following a reset or suspend operation it doesn't support.* @dev: driver model's view of this device* @usb_dev: if an interface is bound to the USB major, this will point*  to the sysfs representation for that device.* @pm_usage_cnt: PM usage counter for this interface* @reset_ws: Used for scheduling resets from atomic context.* @reset_running: set to 1 if the interface is currently running a*      queued reset so that usb_cancel_queued_reset() doesn't try to*      remove from the workqueue when running inside the worker*      thread. See __usb_queue_reset_device().* @resetting_device: USB core reset the device, so use alt setting 0 as*  current; needs bandwidth alloc after reset.** USB device drivers attach to interfaces on a physical device.  Each* interface encapsulates a single high level function, such as feeding* an audio stream to a speaker or reporting a change in a volume control.* Many USB devices only have one interface.  The protocol used to talk to* an interface's endpoints can be defined in a usb "class" specification,* or by a product's vendor.  The (default) control endpoint is part of* every interface, but is never listed among the interface's descriptors.** The driver that is bound to the interface can use standard driver model* calls such as dev_get_drvdata() on the dev member of this structure.** Each interface may have alternate settings.  The initial configuration* of a device sets altsetting 0, but the device driver can change* that setting using usb_set_interface().  Alternate settings are often* used to control the use of periodic endpoints, such as by having* different endpoints use different amounts of reserved USB bandwidth.* All standards-conformant USB devices that use isochronous endpoints* will use them in non-default settings.** The USB specification says that alternate setting numbers must run from* 0 to one less than the total number of alternate settings.  But some* devices manage to mess this up, and the structures aren't necessarily* stored in numerical order anyhow.  Use usb_altnum_to_altsetting() to* look up an alternate setting in the altsetting array based on its number.*/
struct usb_interface {/* array of alternate settings for this interface,* stored in no particular order */struct usb_host_interface *altsetting;struct usb_host_interface *cur_altsetting;  /* the currently* active alternate setting */unsigned num_altsetting;    /* number of alternate settings *//* If there is an interface association descriptor then it will list* the associated interfaces */struct usb_interface_assoc_descriptor *intf_assoc;int minor;          /* minor number this interface is* bound to */enum usb_interface_condition condition;     /* state of binding */unsigned sysfs_files_created:1; /* the sysfs attributes exist */unsigned ep_devs_created:1; /* endpoint "devices" exist */unsigned unregistering:1;   /* unregistration is in progress */unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */unsigned needs_altsetting0:1;   /* switch to altsetting 0 is pending */unsigned needs_binding:1;   /* needs delayed unbind/rebind */unsigned reset_running:1;unsigned resetting_device:1;    /* true: bandwidth alloc after reset */struct device dev;      /* interface specific device info */struct device *usb_dev;atomic_t pm_usage_cnt;      /* usage counter for autosuspend */struct work_struct reset_ws;    /* for resets in atomic context */
};

usb配置

  linux 描述 USB 配置使用结构 struct usb_host_config 和整个 USB 设备使用结构struct usb_device. USB 设备驱动通常不会需要读写这些结构的任何值, 因此它们在这里没有详细定义. 好奇的读者可在内核源码树的文件 include/linux/usb.h 中找到对它们的描述
  

/*** struct usb_host_config - representation of a device's configuration* @desc: the device's configuration descriptor.* @string: pointer to the cached version of the iConfiguration string, if*  present for this configuration.* @intf_assoc: list of any interface association descriptors in this config* @interface: array of pointers to usb_interface structures, one for each*  interface in the configuration.  The number of interfaces is stored*  in desc.bNumInterfaces.  These pointers are valid only while the*  the configuration is active.* @intf_cache: array of pointers to usb_interface_cache structures, one*  for each interface in the configuration.  These structures exist*  for the entire life of the device.* @extra: pointer to buffer containing all extra descriptors associated*  with this configuration (those preceding the first interface*  descriptor).* @extralen: length of the extra descriptors buffer.** USB devices may have multiple configurations, but only one can be active* at any time.  Each encapsulates a different operational environment;* for example, a dual-speed device would have separate configurations for* full-speed and high-speed operation.  The number of configurations* available is stored in the device descriptor as bNumConfigurations.** A configuration can contain multiple interfaces.  Each corresponds to* a different function of the USB device, and all are available whenever* the configuration is active.  The USB standard says that interfaces* are supposed to be numbered from 0 to desc.bNumInterfaces-1, but a lot* of devices get this wrong.  In addition, the interface array is not* guaranteed to be sorted in numerical order.  Use usb_ifnum_to_if() to* look up an interface entry based on its number.** Device drivers should not attempt to activate configurations.  The choice* of which configuration to install is a policy decision based on such* considerations as available power, functionality provided, and the user's* desires (expressed through userspace tools).  However, drivers can call* usb_reset_configuration() to reinitialize the current configuration and* all its interfaces.*/
struct usb_host_config {struct usb_config_descriptor    desc;char *string;       /* iConfiguration string, if present *//* List of any Interface Association Descriptors in this* configuration. */struct usb_interface_assoc_descriptor *intf_assoc[USB_MAXIADS];/* the interfaces associated with this configuration,* stored in no particular order */struct usb_interface *interface[USB_MAXINTERFACES];/* Interface information available even when this is not the* active configuration */struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];unsigned char *extra;   /* Extra descriptors */int extralen;
};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/469216.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

cv2.error: OpenCV(4.5.2) : -1 : error: (-5:Bad argument) in function ‘rectangle‘

在使用opencv画矩形框的时候下面的这行出现了错误: cv2.rectangle(img, (22.0, 3.0),(33.0, 45.0), translate_color(classes[k]), 3, 1) cv2.error: OpenCV(4.5.2) : -1 : error: (-5:Bad argument) in function ‘rectangle’ Overload resolution failed: Can’t…

电脑如何测网速_物联网卡的网速到底怎么样呢

最近不少朋友发私信问我,物联网卡网速到底怎么样,和手机卡的网速有没有什么区别?其实关于网速这个问题,我已经重复解释了很多遍。只要是走公网的流量卡,在不限速的情况下,基本是和你手机卡网速是一致的&…

捡起JavaScript(1)

JS原型介绍 原型的作用是什么? 大家知道的JS不是面向对象的语言,就没有面向对象的继承的概念。那么原型就是用来弥补JS继承功能的。 下面有三个思想需要明确 在JavaScript世界中一切都是对象。一切对象都是由方法new出来的。所有的JavaScript的变量最终都…

git入门学习笔记

安装和配置 安装 #sudo apt-get install git #sudo apt-get install git-doc git-svn git-email git-gui gitk 如果是第一次使用git,需要进行如下设置: #git config--global user.name "weiqifa" #git config--global user.email "ww…

Expected more than 1 value per channel when training, got input size torch.Size

Expected more than 1 value per channel when training, got input size torch.Size 训练的时候,batch size必须大于1,但是预测的时候,batch size可以等于1 原因: 因为模型中用了batchnomolization,训练中用batch训…

dll可以在linux下使用吗_Linux下安装和使用杀毒软件AntiVir

小白玩转智能数据湖,20分钟开发实时豆瓣评分Top20电影的脚本!>>> 提起计算机病毒来,可谓人人皆知,有些吃过病毒苦头的人更是有点谈虎色变的感觉。其实无论对于企业还是个人,病毒的危害都是不可避免的&#xf…

[转]微信小程序登录逻辑梳理

本文转自:http://www.jianshu.com/p/d9996cafdb31 官方文档 文档相关地址: 用户登录 获取用户数据 用户数据的签名验证和加解密 登录时序图.png微信两个api所拿到的信息:login和getUserInfo 返回的信息.png注册/登录 小程序端: 通过上面wx.login和wx.getUserInfo两个…

应用matplotlib的imshow函数显示彩色图像(RGB data)报错的解决方法

何时出现错误提示 :”Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers)”?在Python中,使用 matplotlib 的函数:plt.imshow(ndarray) 将输入数组显示为彩色 ( RGB ) 图像时。 …

转一篇写的比较好的camera文档[Camera 图像处理原理分析]

色彩篇(一) 1 前言 做为拍照手机的核心模块之一,camera sensor效果的调整,涉及到众多的参数,如果对基本的光学原理及sensor软/硬件对图像处理的原理能有深入的理解和把握的话,对我们的工作将会起…

python导出项目所依赖的所有的库文件以及安装

python项目包的导入和导出 1、导出 pip freeze > filename.txt # filename.txt 可随意命名 # 同时filename.txt 文件中可自定义编辑,也是能够进行包的批量安装。 2、导入(包的批量安装) pip install -r filename.txt

201521123061 《Java程序设计》第三周学习总结

1. 本章学习总结 2. 书面作业 **Q1.代码阅读 public class Test1 { private int i 1;//这行不能修改 private static int j 2; public static void main(String[] args) {geti();Test1getj(); }public static void geti() {System.out.println(i); }public static void getj(…

自带flash的浏览器_解决Flash插件已被屏蔽的问题(谷歌、火狐、IE、Edge)

病症,浏览器界面中显示 adobe flash player 已被屏蔽:作为产品运营,作为经常必须可能要接触到Flash/Html5视频应用的人来员;作为曾开发过flash产品的我来说,这题,我会。并且,提供三种解决方式。…

android系统开发(六)-HAL层开发基础

Android HAL层,即硬件抽象层,是Google响应厂家“希望不公开源码”的要求推出的新概念 1,源代码和目标位置 源代码: /hardware/libhardware目录,该目录的目录结构如下: /hardware/libhardware/hardware.c编译成libha…

numpy数组中冒号[:,:,0]与[...,0]的区别

先随机产生一个[3,4,5]的numpy数组。则该x维度是3,shape是(3,4,5),总共包含60个元素。 x[:,:,0] 意思是对数组x切片,可以想象成一个正方体数据,每次切下一个面的数据。第二维取0则得出来[3,4]大小的数组&am…

苹果忘记开机密码_苹果电脑忘记开机密码快速恢复的方法!

很多用户不经常使用电脑,或者粗心大意忘记自己设置的电脑开机密码!!!这可怎么办呢?今天小编就来和大家分享【Mac电脑忘记开机密码快速恢复的方法教程!】有需要的的用户不要错过哦!步骤一&#x…

Web框架 Bottle 、Flask 、Tornado

Bottle Flask Tornado Python的WEB框架 Bottle Bottle是一个快速、简洁、轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Python的标准库外,其不依赖任何其他模块。 pip install bottle easy_install bottle apt-get install py…

【Pytorch神经网络理论篇】 36 NLP中常见的任务+BERT模型+发展阶段+数据集

同学你好!本文章于2021年末编写,获得广泛的好评! 故在2022年末对本系列进行填充与更新,欢迎大家订阅最新的专栏,获取基于Pytorch1.10版本的理论代码(2023版)实现, Pytorch深度学习理论篇(2023版)目录地址…

10个你可能没用过的linux命令

如果你是一个硬件系统管理员或者Linux工程师,你可能会记得大多数Linux命令行技巧。下面的这些Linux命令行技巧通常不被Linux用户所使用。 1.使用pgrep快速查找一个PID pgrep遍历目前正在运行的进程然后列出符合查找规则的进程ID(PID)。 pg…

win7关机快捷键_1个U盘+1款软件,电脑小白也能在家轻松重装win7系统

U盘重装系统,顾名思义就是将U盘插入笔记本后,对电脑进行重装系统。但是我们得清楚一个事情,所谓的U盘并不是普通的U盘,是一个装有PE镜像文件的启动盘。也许很多人还不懂,今天我就来给大家介绍一下如何用1个U盘1款软件&…

cmd导入mysql文件

之所以要使用CMD(命令行)导入Mysql文件(.sql文件形式)也许是你还没遇到过 Mysql图形管理工具都无法正常导入sql文件。在网上找了很多的网友提供的资料来看几乎都是显示 所用工具限制,这里我就不多说了。 如下&#xff…