USB驱动程序源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
项目报告7
USB驱动程序源代码作者:罗仕波
一.头文件go7007sb.h
/*
*go7007sb.h - this file includes all relative header files that
*will be used in go7007sb vedio usb interface driver, and it
*also defines all relative driver private data structures and
*it's io control commands.
*/
#ifndef _GO7007SB_H
#define _GO7007SB_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#define DEBUG
#define DRIVER_VERSION "1.0.0"
#define DRIVER_DESC "USB GO7007SB Driver"
#include
MODULE_AUTHOR("Luo Shibo");
MODULE_DESCRIPTION(DRIVER_DESC" "DRIVER_VERSION);
MODULE_LICENSE("GPL");
/*
*io control commands definition,these commands will be
*used to control the device in function iocntl_go7007sb
*/
#define GO7007SB_IOC_MAGIC 'U' //command magic number
#define GO7007SB_IOC_RESET _IO(GO7007SB_IOC_MAGIC,0) //software reset the device
#define GO7007SB_IOC_SHUTDOWN _IO(GO7007SB_IOC_MAGIC,1) //shutdown the device
#define GO7007SB_IOC_PAUSE _IO(GO7007SB_IOC_MAGIC,2) //pause compression
#define GO7007SB_IOC_RESUME _IO(GO7007SB_IOC_MAGIC,3) //resume from pause status
#define GO7007SB_IOC_GETSTATE _IOR(GO7007SB_IOC_MAGIC,4,unsigned int)//get state of dev
/*
*go7007sb device file number,the major of all USB devices have been defined as 180,
*we just need to define minors here,currently,we accept only 4 devices
*their minors start from 64,so minors:64,65,66,67 should be ok.
*/
#ifdef __KERNEL__ /*__KERNEL__*/
#define GO7007SB_MAX_MNR 4
#define GO7007SB_BASE_MNR 64
#define USB_GO7007SB_MINOR(inode) MINOR((inode)->i_rdev)-GO7007SB_BASE_MNR
/*
*go7007sb video interface number
*/
#define GO7007SB_VIDEO_IFNUM 0
/*
*endpoints definition
*/
#define GO7007SB_MAX_EP_NUM 4 //maximum endpoint number
#define GO7007SB_EP_BULK_IN 1 //in endpoint for stream
#define GO7007SB_EP_CTRL 2 //out endpoint for control
#define GO7007SB_EP_BULK_OUT 3 //out endpoint for initialization
#define GO7007SB_EP_INTR 4 //in endpoint for interrupt
#define IS_EP_BULK(ep) ((ep).bmAttributes==USB_ENDPOINT_XFER_BULK ? 1 : 0)
#define IS_EP_BULK_IN(ep) (IS_EP_BULK(ep)&& \
((ep).bEndpointAddress & USB_ENDPOINT_DIR_MASK)==USB_DIR_IN)
#define IS_EP_BULK_OUT(ep) (IS_EP_BULK(ep)&& \
((ep).bEndpointAddress & USB_ENDPOINT_DIR_MASK)==USB_DIR_OUT)
#define IS_EP_INTR(ep) ((ep).bmAttributes==USB_ENDPOINT_XFER_INT ? 1 : 0)
#define IS_EP_CTRL(ep) ((ep).bmAttributes==USB_ENDPOINT_XFER_CONTROL ? 1 : 0)
#define USB_ENDPOINT_NUM(ep) ((ep).bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
#define USB_EP_DIR_IN 0
#define USB_EP_DIR_OUT 1