网络安全参考 | UNIX参考 | GPS参考 | 无线参考 | 在线手册 | OSBUG.ORG | SUNNY-NETWORK.COM
天线制作 GPS 地标
网站地图 RSS订阅
高级搜索 收藏本站
Home | 业界动态 | Open source | GNU | Linux | BSD | Solaris | AIX | HP-UX | IRIX | Mac OS X | Minix | Tru64 | SCO UNIX | Network | Security | X-Window | Database | 应用服务 | Programming | 经典著作 | 永远的纪念 | 杂项
 当前位置: Home > Linux > 设备驱动 > 文章  
Linux设备驱动编程之复杂设备驱动
文章来源: 天极开发 文章作者: 宋宝华 发布时间: 2006-11-01   字体: [ ]  
 

static void *sample_probe(struct usb_device *udev, unsigned int ifnum,
const struct usb_device_id *id)
{
 /*
 * The probe procedure is pretty standard. Device matching has already
 * been performed based on the id_table structure (defined later)
 */
 struct usb_interface *iface;
 struct usb_interface_descriptor *interface;
 struct usb_endpoint_descriptor *endpoint;
 struct sample_device *sample;

 printk(KERN_INFO "usbsample: probe called for %s device\n",(char *)id->driver_info /* "mouse" or "keyboard" */ );

 iface = &udev->actconfig->interface[ifnum];
 interface = &iface->altsetting[iface->act_altsetting];

 if (interface->bNumEndpoints != 1) return NULL;

 endpoint = interface->endpoint + 0;
 if (!(endpoint->bEndpointAddress & 0x80)) return NULL;
 if ((endpoint->bmAttributes & 3) != 3) return NULL;

 usb_set_protocol(udev, interface->bInterfaceNumber, 0);
 usb_set_idle(udev, interface->bInterfaceNumber, 0, 0);

 /* allocate and zero a new data structure for the new device */
 sample = kmalloc(sizeof(struct sample_device), GFP_KERNEL);
 if (!sample) return NULL; /* failure */
 memset(sample, 0, sizeof(*sample));
 sample->name = (char *)id->driver_info;

 /* fill the URB data structure using the FILL_INT_URB macro */
 {
  int pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
  int maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));

  if (maxp > 8) maxp = 8; sample->maxp = maxp; /* remember for later */
  FILL_INT_URB(&sample->urb, udev, pipe, sample->data, maxp,
  sample_irq, sample, endpoint->bInterval);
 }

 /* register the URB within the USB subsystem */
 if (usb_submit_urb(&sample->urb)) {
  kfree(sample);
  return NULL;
 }
 /* announce yourself */
 printk(KERN_INFO "usbsample: probe successful for %s (maxp is %i)\n",sample->name, sample->maxp);

 /*
 * here you might MOD_INC_USE_COUNT; if you do, you'll need to unplug
 * the device or the devices before being able to unload the module
 */

 /* and return the new structure */
 return sample;
}

  在网络设备驱动的编写中,我们特别关心的就是数据的收、发及中断。网络设备驱动程序的层次如下:

 
推荐文章
·让arm-linux支持普通USB摄像头
·Linux设备驱动编程之结构化设备
·深入浅出Linux设备驱动之并发控
·深入浅出Linux设备驱动之字符设
·深入浅出Linux设备驱动编程之内
·深入浅出Linux设备驱动编程之引
·Linux设备驱动编程之定时器
·Linux设备驱动编程之中断处理
·Linux设备驱动编程之异步通知
·Linux设备驱动编程之阻塞与非阻
·Linux设备驱动编程之内存与I/O操
·摄像头(WebCam)在Linux操作系
·中星微芯片(301,302)USB 摄像头
·Linux的I2C驱动架构
 

 
↑返回顶部   打印本页   关闭窗口↓  

Google
 
Web oldhand.org unixreference.net meshmea.org
相关分类
热点文章
·摄像头(WebCam)在Linu
·在Linux中使用中星微301
·中星微芯片(301,302)USB
·Linux设备驱动编程之内
·深入浅出Linux设备驱动
·Linux培训园地:Linux下
·Linux的I2C驱动架构
·让arm-linux支持普通USB
相关文章
·Linux设备驱动编程之结
·Qt/Embedded在嵌入式Lin
·如何编写Linux操作系统
·深入浅出Linux设备驱动
·深入浅出分析Linux设备
·Linux培训园地:Linux下
·深入浅出Linux设备驱动
·Linux培训园地:Linux下
更多...
 
 

Copyright(c) 2001-2009 OLDHAND ORGANIZATION, All Rights reserved.
Power by DedeCms 织梦内容管理系统