⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbsetup.c

📁 S3C2410学习的基础资料 大部分实验源码及工程
💻 C
📖 第 1 页 / 共 2 页
字号:
   	case EP0_STATE_GD_DEV_0://GET_DESCRIPTOR:DEVICE-->发送设备描述符
//		DbgOut("[GDD0]");
		WrPktEp0((U8 *)&descDev+0,8); //写数据包,设备描述符的前8个字节
		SET_EP0_IN_PKT_RDY();//置数据准备好标志,IN_PKT_RDY=1
		ep0State=EP0_STATE_GD_DEV_1;//进入下一个状态阶段
		break;
            
	case EP0_STATE_GD_DEV_1:
//		DbgOut("[GDD1]");
		WrPktEp0((U8 *)&descDev+0x8,8);//设备描述符的第二个8字节 
		SET_EP0_IN_PKT_RDY();            
		ep0State=EP0_STATE_GD_DEV_2;
		break;

	case EP0_STATE_GD_DEV_2:
//		DbgOut("[GDD2]");
		WrPktEp0((U8 *)&descDev+0x10,2);   //8+8+2=0x12
		SET_EP0_INPKTRDY_DATAEND();//IN数据包发送结束,DATA_END位置1
		ep0State=EP0_STATE_INIT;
		break;   

        //=== GET_DESCRIPTOR:CONFIGURATION+INTERFACE+ENDPOINT0+ENDPOINT1 ===
        //Windows98 发送一次请求得到所有的4个描述符.
        //Windows2000 每次请求得1个描述符
	case EP0_STATE_GD_CFG_0:
//		DbgOut("[GDC0]");
		WrPktEp0((U8 *)&descConf+0,8); //EP0_PKT_SIZE=8,配置描述符的前8个字节
		SET_EP0_IN_PKT_RDY();	//IN包数据准备好发送
		ep0State=EP0_STATE_GD_CFG_1;
		break;
    
	case EP0_STATE_GD_CFG_1:
//		DbgOut("[GDC1]");
		WrPktEp0((U8 *)&descConf+8,1); //配置描述符的第9个字节
		WrPktEp0((U8 *)&descIf+0,7); //接口描述符的前7个字节
		SET_EP0_IN_PKT_RDY();
        ep0State=EP0_STATE_GD_CFG_2;
        break;

  	case EP0_STATE_GD_CFG_2:
//		DbgOut("[GDC2]");
        WrPktEp0((U8 *)&descIf+7,2); //接口描述符的后2个字节
        WrPktEp0((U8 *)&descEndpt0+0,6);//端点0描述符的前6个字节 
        SET_EP0_IN_PKT_RDY();
        ep0State=EP0_STATE_GD_CFG_3;
        break;

   	case EP0_STATE_GD_CFG_3:
//		DbgOut("[GDC3]");
        WrPktEp0((U8 *)&descEndpt0+6,1); //端点0描述符的最后1个字节
        WrPktEp0((U8 *)&descEndpt1+0,7); //端点1描述符的全部7个字节
        SET_EP0_IN_PKT_RDY();
        ep0State=EP0_STATE_GD_CFG_4;            
        break;

   	case EP0_STATE_GD_CFG_4:
//		DbgOut("[GDC4]");
		//zero length data packit 
		SET_EP0_INPKTRDY_DATAEND();//发送0长度数据包,指示数据发送完毕
		ep0State=EP0_STATE_INIT;            
        break;

    //=== GET_DESCRIPTOR:仅针对配置描述符===
   	case EP0_STATE_GD_CFG_ONLY_0://第一次发送
//		DbgOut("[GDCO0]");
        WrPktEp0((U8 *)&descConf+0,8); //发送配置描述符的前8个字节
        SET_EP0_IN_PKT_RDY();
        ep0State=EP0_STATE_GD_CFG_ONLY_1;
        break;
    
	case EP0_STATE_GD_CFG_ONLY_1:	//第二次发送
//		DbgOut("[GDCO1]");
        WrPktEp0((U8 *)&descConf+8,1);//发送配置描述符的第9个字节 
        SET_EP0_INPKTRDY_DATAEND();//发送0长度数据包,指示数据发送完毕
        ep0State=EP0_STATE_INIT;            
        break;

    //=== GET_DESCRIPTOR:仅针对接口描述符===
   	case EP0_STATE_GD_IF_ONLY_0:
//		DbgOut("[GDI0]");
        WrPktEp0((U8 *)&descIf+0,8); //发送配置描述符的前8个字节
        SET_EP0_IN_PKT_RDY();
        ep0State=EP0_STATE_GD_IF_ONLY_1;
        break;
        
   	case EP0_STATE_GD_IF_ONLY_1:
//		DbgOut("[GDI1]");
        WrPktEp0((U8 *)&descIf+8,1);//发送配置描述符的第9个字节 
        SET_EP0_INPKTRDY_DATAEND();
        ep0State=EP0_STATE_INIT;            
        break;

    //=== GET_DESCRIPTOR:仅针对端点0描述符===
   	case EP0_STATE_GD_EP0_ONLY_0:
//		DbgOut("[GDE00]");
        WrPktEp0((U8 *)&descEndpt0+0,7); 
        SET_EP0_INPKTRDY_DATAEND();
        ep0State=EP0_STATE_INIT;            
        break;
            
    //===GET_DESCRIPTOR:仅针对端点1描述符===
   	case EP0_STATE_GD_EP1_ONLY_0:
//		DbgOut("[GDE10]");
        WrPktEp0((U8 *)&descEndpt1+0,7); 
        SET_EP0_INPKTRDY_DATAEND();
        ep0State=EP0_STATE_INIT;            
        break;
 
    //===GET_DESCRIPTOR:发送字符串描述符 ===
   	case EP0_STATE_GD_STR_I0://发送第一个字符串描述符,4字节,包含设备序列号
//		DbgOut("[GDS0_0]");
	    WrPktEp0((U8 *)descStr0, 4 );  
	    SET_EP0_INPKTRDY_DATAEND();
	    ep0State=EP0_STATE_INIT;     
	    ep0SubState=0;
	    break;

	case EP0_STATE_GD_STR_I1://发送第二个字符串描述符,包含厂商标识
//		DbgOut("[GDS1_%d]",ep0SubState);
		if( (ep0SubState*EP0_PKT_SIZE+EP0_PKT_SIZE)<sizeof(descStr1) )
		{
			WrPktEp0((U8 *)descStr1+(ep0SubState*EP0_PKT_SIZE),EP0_PKT_SIZE); 
            SET_EP0_IN_PKT_RDY();
            ep0State=EP0_STATE_GD_STR_I1;
            ep0SubState++;
		}
	    else
	    {
	    	WrPktEp0((U8 *)descStr1+(ep0SubState*EP0_PKT_SIZE),//字符串发送最后一个包
	    		 sizeof(descStr1)-(ep0SubState*EP0_PKT_SIZE)); 
			SET_EP0_INPKTRDY_DATAEND();
			ep0State=EP0_STATE_INIT;     
			ep0SubState=0;
	    }
	    break;

	case EP0_STATE_GD_STR_I2://发送第三个字符串描述符,包含产品标识
//		DbgOut("[GDS2_%d]",ep0SubState);
        if( (ep0SubState*EP0_PKT_SIZE+EP0_PKT_SIZE)<sizeof(descStr2) )
        {
        	WrPktEp0((U8 *)descStr2+(ep0SubState*EP0_PKT_SIZE),EP0_PKT_SIZE); 
            SET_EP0_IN_PKT_RDY();
            ep0State=EP0_STATE_GD_STR_I2;
            ep0SubState++;
		}
	    else
	    {
//			DbgOut("[E]");
	    	WrPktEp0((U8 *)descStr2+(ep0SubState*EP0_PKT_SIZE),
	    		 sizeof(descStr2)-(ep0SubState*EP0_PKT_SIZE)); 
			SET_EP0_INPKTRDY_DATAEND();
			ep0State=EP0_STATE_INIT;     
			ep0SubState=0;
	    }
		break;
		
	default:
//		DbgOut("UE:G?D");
    	break;
    }
}//Ep0中断处理结束

U32 UsbFunction;

void InitDescriptorTable(U8 fun)
{	
	UsbFunction = fun-1;
    
    //设备描述符
    //Standard device descriptor
    descDev.bLength=0x12;	//Size of this descriptor in bytes    
    descDev.bDescriptorType=DEVICE_TYPE; //DEVICE Descriptor Type        
    descDev.bcdUSBL=0x10;//USB Specification Release Number
    descDev.bcdUSBH=0x01; 	//Ver 1.10
    descDev.bDeviceClass=0xFF; //Class code, the device class is vendor-specific         
    descDev.bDeviceSubClass=0x0;//Subclass code          
    descDev.bDeviceProtocol=0x0;//Protocol code          
    descDev.bMaxPacketSize0=0x8;//Maximum packet size for endpoint zero         
    descDev.idVendorL=0x45;//Vendor ID 5345H
    descDev.idVendorH=0x53;
    if(fun==1)    
    	descDev.idProductL=0x34;//Product ID 1234H or 1233H
    else
    	descDev.idProductL=0x33;	
    descDev.idProductH=0x12;
    descDev.bcdDeviceL=0x00; //Device release number 100
    descDev.bcdDeviceH=0x01;
    descDev.iManufacturer=0x1;  //Index of string descriptor describing manufacturer
    descDev.iProduct=0x2;	//Index of string descriptor describing product 
    descDev.iSerialNumber=0x0;//Index of string descriptor describing the device’s serial number
    descDev.bNumConfigurations=0x1;//Number of possible configurations
    
    //配置描述符
    //Standard configuration descriptor
    descConf.bLength=0x9;  //Size of this descriptor in bytes   
    descConf.bDescriptorType=CONFIGURATION_TYPE; //CONFIGURATION Descriptor Type        
    descConf.wTotalLengthL=0x20; //Total length of data returned for this configuration.<cfg desc>+<if desc>+<endp0 desc>+<endp1 desc>
    descConf.wTotalLengthH=0; 
    descConf.bNumInterfaces=1;//Number of interfaces supported by this configuration
    descConf.bConfigurationValue=1; //Value to use as an argument to the SetConfiguration() request to select this configuration 
    descConf.iConfiguration=0;//Index of string descriptor describing this configuration
    descConf.bmAttributes=CONF_ATTR_DEFAULT;  //bus powered only.
    descConf.maxPower=25; //draws 50mA current from the USB bus. Maximum power consumption of the USB device from the bus         

    //接口描述符
    //Standard interface descriptor
    descIf.bLength=0x9;//Size of this descriptor in bytes   
    descIf.bDescriptorType=INTERFACE_TYPE; //INTERFACE Descriptor Type        
    descIf.bInterfaceNumber=0x0;//Number of interface
    descIf.bAlternateSetting=0x0; //Value used to select alternate setting for the interface identified in the prior field
    descIf.bNumEndpoints=2;	//# of endpoints except EP0
    descIf.bInterfaceClass=0xff; //Class code
    descIf.bInterfaceSubClass=0x0; //Subclass code 
    descIf.bInterfaceProtocol=0x0; //Protocol code
    descIf.iInterface=0x0;//Index of string descriptor describing this interface

    //Standard endpoint0 descriptor
    descEndpt0.bLength=0x7; //Size of this descriptor in bytes   
    descEndpt0.bDescriptorType=ENDPOINT_TYPE; //ENDPOINT Descriptor Type        
    descEndpt0.bEndpointAddress=1|EP_ADDR_IN;   // 2400Xendpoint 1 is IN endpoint.
                                                //The address of the endpoint on the USB device described by this descriptor.
    descEndpt0.bmAttributes=EP_ATTR_BULK; //This field describes the endpoint’s attributes
    descEndpt0.wMaxPacketSizeL=EP1_PKT_SIZE; //64 Maximum packet
    descEndpt0.wMaxPacketSizeH=0x0;
    descEndpt0.bInterval=0x0; //not usedInterval for polling endpoint for data transfers.

    //Standard endpoint1 descriptor
    descEndpt1.bLength=0x7;    
    descEndpt1.bDescriptorType=ENDPOINT_TYPE;         
    descEndpt1.bEndpointAddress=3|EP_ADDR_OUT;   // 2400X endpoint 3 is OUT endpoint.
    descEndpt1.bmAttributes=EP_ATTR_BULK;
    descEndpt1.wMaxPacketSizeL=EP3_PKT_SIZE; //64
    descEndpt1.wMaxPacketSizeH=0x0;
    descEndpt1.bInterval=0x0; //not used 
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -