怎么做诚信通网站的店招,临沂市建设局网站公示,苏州家政保洁公司哪家好,wordpress列表页怎么写在嵌入式项目里面#xff0c;会扩展很多usb端口#xff0c;由于主芯片本身的局限性还会增加2.0#xff0c;3.0 的usb hub。有时还需要切换usb 触摸的链路#xff0c;这样还需要添加switch 开关。
小板和子卡上面的usb hub 会与主板连接后#xff0c;由于时序等其他兼容性问…在嵌入式项目里面会扩展很多usb端口由于主芯片本身的局限性还会增加2.03.0 的usb hub。有时还需要切换usb 触摸的链路这样还需要添加switch 开关。
小板和子卡上面的usb hub 会与主板连接后由于时序等其他兼容性问题尝尝会导致hub 初始化失败或者挂死这个时候就需要重置恢复正常工作。这里我们只分享一下hub 的软复位。
linux下一切设备皆文件现在我们就找到连接在主板上面的hub文件。查找设备
查看所有usb 设备vidpid
Mstar:/ # lsusb
Bus 003 Device 001: ID 1d6b:0002
Bus 002 Device 004: ID 29bd:4101
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 005: ID 090c:1000
Bus 001 Device 003: ID 2109:2817
Bus 001 Device 002: ID 1a40:0101
Bus 004 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0002
Bus 001 Device 004: ID 0a12:0001上面一组vidpid 唯一确定一个usb设备。
查找hub 设备
Mstar:/ # find / -type d -iname hub
/sys/bus/usb/drivers/hub
Mstar:/ # cd /sys/bus/usb/drivers/hub 在hub 文件夹下有6个usb 设备1-0:1.01-1.1:1.01-1:1.02-0:1.03-0:1.04-0:1.06个usb 设备对应的文件在
/sys/devices/Mstar-ehci-2/usb1/1-0:1.0
/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1/1-1.1:1.0
/sys/devices/Mstar-ehci-2/usb1/1-1/1-1:1.0
/sys/devices/Mstar-ehci-1/usb2/2-0:1.0
/sys/devices/Mstar-ehci-3/usb3/3-0:1.0
/sys/devices/Mstar-ehci-4/usb4/4-0:1.0如下图 其中有两个比较重要的节点bindunbind 使用方法可以参考 https://www.ibm.com/developerworks/cn/linux/l-cn-sysfs/
设备属性
以其中的/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 为例
Mstar:/ # cd /sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1/
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # ls
1-1.1:1.0 bMaxPower dev manufacturer speed
authorized bNumConfigurations devnum maxchild subsystem
avoid_reset_quirk bNumInterfaces devpath port uevent
bConfigurationValue bcdDevice driver power urbnum
bDeviceClass bmAttributes ep_00 product version
bDeviceProtocol busnum idProduct quirks
bDeviceSubClass configuration idVendor removable
bMaxPacketSize0 descriptors ltm_capable remove
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat product
USB2.0 Hub
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat idProduct
2817
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat idVendor
2109
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat quirks
0x0
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat speed
480
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat bMaxPower
0mA
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat bDeviceProtocol
02
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat bDeviceSubClass
00
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # cat bDeviceClass
09通过这些属性结合usb的协议我们基本可以了解这个usb 设备的信息。这里我们主要需要的idProductidVendor以及product信息来唯一确定我们需要操作。
重置操作
Mstar:/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1 # echo 1 remove
[ 8396.820996] hub_port_disable: 0 hub-err: 0
[ 8396.826702] usb 1-1.1: USB disconnect, device number 7通过remove 节点来完成软重置。
#define VENDORPATH (/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1/idVendor)
#define PRODUCTPATH (/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1/idProduct)
static MAPI_BOOL resetFrontBoardBhub()
{if(access(VENDORPATH, F_OK|R_OK) ! 0){printf([%s][%d] cant find the file [%s] .\n, __FUNCTION__, __LINE__, VENDORPATH);return MAPI_TRUE;}if(access(PRODUCTPATH, F_OK|R_OK) ! 0){printf([%s][%d] cant find the file [%s] .\n, __FUNCTION__, __LINE__, PRODUCTPATH);return MAPI_TRUE;}char u8VBuffer [8] {0x00};char u8PBuffer [8] {0x00};int uVendorId 0;int uProductId 0;int unVendorFd open(VENDORPATH, O_RDONLY);if(unVendorFd 0){if(read(unVendorFd, u8VBuffer, 8) 0){uVendorId atoi(u8VBuffer);close(unVendorFd);}else{close(unVendorFd);printf([%s][%d] cant get the vendor id .\n, __FUNCTION__, __LINE__);return MAPI_FALSE;}}int unProductFd open(PRODUCTPATH, O_RDONLY);if(unProductFd 0){if(read(unProductFd, u8PBuffer, 8) 0){uProductId atoi(u8PBuffer);close(unProductFd);}else{printf([%s][%d] cant get the product id .\n, __FUNCTION__, __LINE__);close(unProductFd);return MAPI_FALSE;}}printf([%s][%d] the front board hub vid: 0x%4d, pid: 0x%4d\n,__FUNCTION__,__LINE__,uVendorId,uProductId);if(2109 uVendorId 2817 uProductId){char rst_cmd[256];memset(rst_cmd, 0x00, sizeof(rst_cmd));snprintf(rst_cmd, 256, echo 1 %s,/sys/devices/Mstar-ehci-2/usb1/1-1/1-1.1/remove);system((char * const)rst_cmd);}return MAPI_TRUE;
}一般来说hub 的状态出现异常通过软重置可以恢复正常这个是在hub 没有reset pin power pin 给主板控制的情况下的备选方案。
扩展
模拟usb 热拔插操作mstar平台usb 设备根节点
/sys/devices/Mstar-ehci-1/usb2/
/sys/devices/Mstar-ehci-2/usb1/
/sys/devices/Mstar-ehci-3/usb3/
/sys/devices/Mstar-ehci-4/usb4/usb storage 设备属性的delete 节点操作卸载操作 echo 1 /sys/bus/scsi/drivers/sd/0:0:0:0/delete echo offline /sys/bus/scsi/drivers/sd/0:0:0:0/state