c – USB的简单内核模块
发布时间:2020-12-16 06:56:18 所属栏目:百科 来源:网络整理
导读:我正在尝试熟悉 Linux内核模块.所以我写了这个最简单的模块,可以在usb上运行.我不确定我错过了什么.正在加载模块.同样在dmesg我可以看到: [27245.911387] usbcore: registered new interface driver testusb [27245.911392] testusb: driver registered suc
我正在尝试熟悉
Linux内核模块.所以我写了这个最简单的模块,可以在usb上运行.我不确定我错过了什么.正在加载模块.同样在dmesg我可以看到:
[27245.911387] usbcore: registered new interface driver testusb [27245.911392] testusb: driver registered successfully 但是当我插入一个usb棒时,我的testusb_probe函数没有被调用.知道我哪里出错了. #include <linux/kernel.h> #include <linux/module.h> #include <linux/usb.h> static int testusb_probe(struct usb_interface *interface,const struct usb_device_id *id) { printk("testusb: probe modulen"); return 0; } static void testusb_disconnect(struct usb_interface *interface) { printk("testusb: disconnect modulen"); } static struct usb_driver testusb_driver = { name: "testusb",probe: testusb_probe,disconnect: testusb_disconnect,}; static int __init testusb_init(void) { int result; result = usb_register(&testusb_driver); if (result) { printk("testusb: registering driver failed"); } else { printk("testusb: driver registered successfully"); } return result; } static void __exit testusb_exit(void) { usb_deregister(&testusb_driver); printk("testusb: module deregistered"); } module_init(testusb_init); module_exit(testusb_exit); MODULE_AUTHOR("Dal Chand"); MODULE_LICENSE("GPL"); 解决方法
您的测试驱动程序未启用USB热插拔.
http://www.linuxjournal.com/node/4786/print /* Define these values to match your devices */ #define USB_VENDOR_ID 0xfff0 #define USB_PRODUCT_ID 0xfff0 /* table of devices that work with this driver */ static struct usb_device_id test_table [] = { { USB_DEVICE(USB_VENDOR_ID,USB_PRODUCT_ID) },{ } /* Terminating entry */ }; MODULE_DEVICE_TABLE (usb,test_table); USB_VENDOR_ID和USB_PRODUCT_ID是您的USB棒的ID.如果您不知道ID,请在插入操作杆时检查dmesg消息. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |