日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux usb学习笔记

發布時間:2023/12/20 linux 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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; };

總結

以上是生活随笔為你收集整理的linux usb学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。