USB 3G卡热插拔那些事1------原理框架
2013-02-21 11:31
267 查看
USB 3G卡热插拔那些事1------原理框架 2012-03-31
23:20:15
分类: 嵌入式
这里我们先讲讲USB热插拔事件的处理工作。---Khubd守护进程。
-Khubd守护进程它是一个守护进程,来检查usb port的事件通知HCD和usb core,然后做相应的处理。
驱动目录drivers/usb/*
usb/serial usb 串行设备驱动 (例如usb 3G卡、蓝牙等)
usb/storage usb 大储量磁盘驱动(u盘)
usb/host usb host usb主机控制器驱动(嵌入式otg:dwc_otg)
usb/core usb 核心一些处理代码,所有的驱动相关处理都在这里,也都注册到它里面。
usb/usb-skeleton.c 经典的usb客户驱动框架,可以参考。
当然还有其他这里不再说明。
下面贴出USB的整体驱动框架:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202010/10/6013ad3b12fd201dce9e5c36016f9cae.jpg)
这里我们主要分析khub的工作原理: 硬件层次是hub的工作,如何和host及其设备间通信及相应事件
看usb/core/hub.c
int usb_hub_init(void)
{
if (usb_register(&hub_driver) < 0) {
printk(KERN_ERR "%s: can't register hub driver\n",
usbcore_name);
return -1;
}
khubd_task = kthread_run(hub_thread, NULL, "khubd");
if (!IS_ERR(khubd_task))
return 0;
/* Fall through if kernel_thread failed */
usb_deregister(&hub_driver);
printk(KERN_ERR "%s: can't start khubd\n", usbcore_name);
return -1;
}
这里我们只关心kthread_run(hub_thread, NULL, "khubd"); 然后我们看hub_thread函数
static int hub_thread(void *__unused)
{
do {
hub_events();
wait_event_interruptible(khubd_wait,
!list_empty(&hub_event_list) ||
kthread_should_stop());
try_to_freeze();
} while (!kthread_should_stop() || !list_empty(&hub_event_list));
pr_debug("%s: khubd exiting\n", usbcore_name);
return 0;
}
这里我们看到了hub_events()函数。然后设置运行状态,如果有事件就加入hub_event_list。
自此khubd运行起来了。
这里我们同样贴出它的函数调用流程图(这里懒得自己画了,就剪切了个^^)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202010/10/065db1b8968ed3d796c7759e0d57d8e5.jpg)
通过流程图我们可以清晰的明白,当usb设备插入usb接口后,khubd运行,它检测到port状态的变化
调用hub_port_connect_change(),如果是新设备那么usb_allco_dev,然后调用usb_new_device来进行配置使usb设备可以正常工作。详细流程请看源码。
23:20:15
分类: 嵌入式
这里我们先讲讲USB热插拔事件的处理工作。---Khubd守护进程。
-Khubd守护进程它是一个守护进程,来检查usb port的事件通知HCD和usb core,然后做相应的处理。
驱动目录drivers/usb/*
usb/serial usb 串行设备驱动 (例如usb 3G卡、蓝牙等)
usb/storage usb 大储量磁盘驱动(u盘)
usb/host usb host usb主机控制器驱动(嵌入式otg:dwc_otg)
usb/core usb 核心一些处理代码,所有的驱动相关处理都在这里,也都注册到它里面。
usb/usb-skeleton.c 经典的usb客户驱动框架,可以参考。
当然还有其他这里不再说明。
下面贴出USB的整体驱动框架:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202010/10/6013ad3b12fd201dce9e5c36016f9cae.jpg)
这里我们主要分析khub的工作原理: 硬件层次是hub的工作,如何和host及其设备间通信及相应事件
看usb/core/hub.c
int usb_hub_init(void)
{
if (usb_register(&hub_driver) < 0) {
printk(KERN_ERR "%s: can't register hub driver\n",
usbcore_name);
return -1;
}
khubd_task = kthread_run(hub_thread, NULL, "khubd");
if (!IS_ERR(khubd_task))
return 0;
/* Fall through if kernel_thread failed */
usb_deregister(&hub_driver);
printk(KERN_ERR "%s: can't start khubd\n", usbcore_name);
return -1;
}
这里我们只关心kthread_run(hub_thread, NULL, "khubd"); 然后我们看hub_thread函数
static int hub_thread(void *__unused)
{
do {
hub_events();
wait_event_interruptible(khubd_wait,
!list_empty(&hub_event_list) ||
kthread_should_stop());
try_to_freeze();
} while (!kthread_should_stop() || !list_empty(&hub_event_list));
pr_debug("%s: khubd exiting\n", usbcore_name);
return 0;
}
这里我们看到了hub_events()函数。然后设置运行状态,如果有事件就加入hub_event_list。
自此khubd运行起来了。
这里我们同样贴出它的函数调用流程图(这里懒得自己画了,就剪切了个^^)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202010/10/065db1b8968ed3d796c7759e0d57d8e5.jpg)
通过流程图我们可以清晰的明白,当usb设备插入usb接口后,khubd运行,它检测到port状态的变化
调用hub_port_connect_change(),如果是新设备那么usb_allco_dev,然后调用usb_new_device来进行配置使usb设备可以正常工作。详细流程请看源码。
相关文章推荐
- USB 3G卡热插拔那些事1------原理框架
- USB 3G卡热插拔那些事2
- USB 3G卡热插拔那些事3------usb serial驱动
- USB 3G卡热插拔那些事4------pppd
- USB 3G卡热插拔那些事5------PPP协议
- 深入分析 iBATIS 框架之系统架构与映射原理
- USB 3G网卡驱动流程
- AndFix Bug热修复框架原理及源码解析
- Spring核心框架 - AOP的原理及源码解析
- ofbiz框架以及核心原理介绍
- AutoMonkey框架原理与应用(三)
- Java微框架Spring Boot 运行原理深入解读
- Apache Cordova-Android框架原理研究笔记 II
- 关于热插拔usb hotplug /proc/sys/kernel mdev udev busybox
- 框架开发原理/类加载器加载配置文件
- struts2中validation校验框架的原理和使用
- alibaba远程调用框架dubbo原理
- 关于热插拔usb hotplug /proc/sys/kernel mdev udev busybox
- 分布式服务框架原理(一)设计和实现
- How to use USB 3G dongle/stick Huawei E169/E620/E800 ( Chip used Qualcomm e1750) in Linux (China and world)