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

📄 usbsetup.c

📁 S3C2410 USB Mass storage 源码.
💻 C
📖 第 1 页 / 共 2 页
字号:
			case SET_FEATURE: // HID class command 0x03, Get Protocol
//				CLR_EP0_OUT_PKT_RDY();
				switch(descSetup.bmRequestType){
					case 0:
						DeviceStatus=0x01;
						break;
					case 0x01:
						InterfaceStatus=0x01;
						break;
					case 0x02:
						switch(descSetup.bIndexL){
							case 0x01:
								EndPoint0Status=0x01;
								break;
							case 0x03:
								EndPoint3Status=0x01;
								break;
							}
						break;
					case 0xA1:
					case 0xA2:
						rEP0_FIFO = DeviceProtocolStatus;
						SET_EP0_IN_PKT_RDY();
						break;
					default:
						break;
					}
				break;
			case SET_ADDRESS:
				rFUNC_ADDR_REG=0x80|descSetup.bValueL;
				CLR_EP0_OUTPKTRDY_DATAEND();
				ep0State = EP0_STATE_INIT;
				break;
			case GET_DESCRIPTOR:
//				CLR_EP0_OUT_PKT_RDY();
				switch(descSetup.bValueH){
					case DEVICE_TYPE:
						ep0State=EP0_STATE_GD_DEV_0;
						break;
					case CONFIGURATION_TYPE:
						if((descSetup.bLengthL+(descSetup.bLengthH<<8))>0x09)
							ep0State = EP0_STATE_GD_CFG_0; //for WIN98,WIN2K
						else	    	    
							ep0State = EP0_STATE_GD_CFG_ONLY_0; //for WIN2K
						break;
					case STRING_TYPE:
						switch(descSetup.bValueL)//SW3
						{
							case 0:
								ep0State = EP0_STATE_GD_STR_I0;
								break;
							case 1:
								ep0State = EP0_STATE_GD_STR_I1;
								break;
							case 2:	
								ep0State = EP0_STATE_GD_STR_I2;
								break;
							default:
								break;
						}
						ep0SubState=0;
						break;
					case INTERFACE_TYPE:
						ep0State=EP0_STATE_GD_IF_ONLY_0;
						break;
					case ENDPOINT_TYPE:
						switch(descSetup.bValueL&0xf)//SW4
						{
							case 0:
								ep0State=EP0_STATE_GD_EP0_ONLY_0;
								break;
							case 1:
								ep0State=EP0_STATE_GD_EP1_ONLY_0;
								break;
							default:
								break;
						}
						break;
					default:
						ep0State=EP0_STATE_INIT;
						break;
					}
				break;
			case SET_DESCRIPTOR:
//				DbgPrintf("Ep0_4\n");
//				CLR_EP0_OUT_PKT_RDY();
				break;
			case GET_CONFIGURATION:
//				DbgPrintf("Ep0_5\n");
//				CLR_EP0_OUT_PKT_RDY();
				rEP0_FIFO = isUsbdSetConfiguration;
				SET_EP0_IN_PKT_RDY();  
				ep0State=EP0_STATE_INIT;    
				break;
			case SET_CONFIGURATION: // HID class command 0x09, Set Report
//				DbgPrintf("Ep0_6\n");
				isUsbdSetConfiguration=descSetup.bValueL;
				CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
				ep0State=EP0_STATE_INIT;

				break;
			case GET_INTERFACE: // HID class command 0x0A, Set Idle
//				DbgPrintf("Ep0_7\n");
//				CLR_EP0_OUT_PKT_RDY();
				if(descSetup.bmRequestType == 0x81){
					rEP0_FIFO = InterfaceRegister;
					//Write 8 bytes data (0-7) of USB_DEVICE_DESCRIPTOR into EP0_FIFO
					SET_EP0_IN_PKT_RDY();  
					}
				else	{
					// HID Command Request : SET IDLE
					CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
					DeviceIdleStatus = descSetup.bValueL;         			
					}
				ep0State=EP0_STATE_INIT;    
				break;
			case SET_INTERFACE: // HID class command 0x0B, Set Protocol
//				DbgPrintf("Ep0_8\n");
				if(descSetup.bmRequestType == 0x01){
					CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
					InterfaceRegister = descSetup.bValueL;
					}
				else{
					// HID Command Request : SET PROTOCOL
					CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
					DeviceIdleStatus = descSetup.bValueL; 
					}           		
				ep0State=EP0_STATE_INIT;
				break;
			case SYNCH_FRAME:
//				DbgPrintf("Ep0_9\n");
//				CLR_EP0_OUT_PKT_RDY();
				break;
			default:
//				DbgPrintf("Ep0_A\n");
//				CLR_EP0_OUT_PKT_RDY();
				break;
		}//End of SW1
	}//
    
	switch(ep0State)
	{	
		case EP0_STATE_INIT:
//			DbgPrintf("EP0_STATE_INIT\n");
			break; 

		//=== GET_DESCRIPTOR:DEVICE ===
		// Send USB device descriptor to USB host, total 18 bytes.
		case EP0_STATE_GD_DEV_0:
			//Uart_Printf("[GDD0]\n");
			WrPktEp0((U8 *)&descDev, 16);
			//Write 8 bytes data (0-7) of USB_DEVICE_DESCRIPTOR into EP0_FIFO
			SET_EP0_IN_PKT_RDY();
			ep0State=EP0_STATE_GD_DEV_1;
			break;

		case EP0_STATE_GD_DEV_1:
			//Uart_Printf("[GDD1]\n");
			WrPktEp0((U8 *)&descDev+16, 2);
			ep0State=EP0_STATE_INIT;
			SET_EP0_INPKTRDY_DATAEND();
			//Write 8 bytes data (8-15) of USB_DEVICE_DESCRIPTOR into EP0_FIFO
//			SET_EP0_IN_PKT_RDY();
//			ep0State=EP0_STATE_GD_DEV_2;
			break;

		case EP0_STATE_GD_CFG_ONLY_0:
			WrPktEp0((U8 *)&descConf, 9);
			ep0State=EP0_STATE_INIT;
			SET_EP0_INPKTRDY_DATAEND();
			break;

//=== GET_DESCRIPTOR:INTERFACE ONLY===
// Send USB interface descriptor to USB host, total 9 bytes.
		case EP0_STATE_GD_IF_ONLY_0:
			WrPktEp0((U8 *)&descIf, 9);
			ep0State=EP0_STATE_INIT;
			SET_EP0_INPKTRDY_DATAEND();
			break;

		case EP0_STATE_GD_EP0_ONLY_0:
			WrPktEp0((U8 *)&descEndpt[0], 7);
			ep0State=EP0_STATE_INIT;
			SET_EP0_INPKTRDY_DATAEND();
			break;
			
		case EP0_STATE_GD_EP1_ONLY_0:
			WrPktEp0((U8 *)&descEndpt[1], 7);
			ep0State=EP0_STATE_INIT;
			SET_EP0_INPKTRDY_DATAEND();
			break;
	
		//=== GET_DESCRIPTOR:CONFIGURATION+INTERFACE+ENDPOINT0+ENDPOINT1 ===
		//Windows98 gets these 4 descriptors all together by issuing only a request.
		//Windows2000 gets each descriptor seperately.
		case EP0_STATE_GD_CFG_0:
			//Uart_Printf("[GDC0]\n");
			WrPktEp0((U8 *)&descConf, 9); //EP0_PKT_SIZE
			WrPktEp0((U8 *)&descIf, 7); 
			ep0State=EP0_STATE_GD_CFG_1;
			SET_EP0_IN_PKT_RDY();
//			SET_EP0_IN_PKT_RDY();
//			ep0State=EP0_STATE_GD_CFG_1;
			break;

		case EP0_STATE_GD_CFG_1:
			//Uart_Printf("[GDC1]\n");
			WrPktEp0((U8 *)&descIf+7, 2); 
			WrPktEp0((U8 *)descEndpt, 14);
			SET_EP0_IN_PKT_RDY();
			ep0State=EP0_STATE_GD_CFG_2;

			//ep0State=EP0_STATE_INIT;
			//SET_EP0_INPKTRDY_DATAEND();
			break;

		case EP0_STATE_GD_CFG_2:
			//Uart_Printf("[GDC2]\n");
			//zero length data packit 
			SET_EP0_INPKTRDY_DATAEND();
			ep0State=EP0_STATE_INIT;			
			break;


		//=== GET_DESCRIPTOR:STRING ===
		case EP0_STATE_GD_STR_I0:

			if(descSetup.bLengthL==2)
			{
				WrPktEp0((U8 *)LANGUAGE_ID, 2);  
				SET_EP0_INPKTRDY_DATAEND();
				ep0State=EP0_STATE_INIT;  
				ep0SubState=0;
			}
			else
			{
				WrPktEp0((U8 *)LANGUAGE_ID, 4);  
				SET_EP0_INPKTRDY_DATAEND();
				ep0State=EP0_STATE_INIT;     
				ep0SubState=0;
			}
			break;

		case EP0_STATE_GD_STR_I1:
			if(descSetup.bLengthL==2)
			{
				WrPktEp0((U8 *)device_serial_number,2); 
				SET_EP0_IN_PKT_RDY();
				ep0State=EP0_STATE_INIT;
			}
			else
			{
				if((ep0SubState*16+16) < sizeof(descStr1))
				{
					WrPktEp0((U8 *)descStr1+(ep0SubState*16), 16); 
					SET_EP0_IN_PKT_RDY();
					ep0State=EP0_STATE_GD_STR_I1;
					ep0SubState++;
				}
				else
				{
					WrPktEp0((U8 *)descStr1+(ep0SubState*16),
					sizeof(descStr1)-(ep0SubState*16)); 
					SET_EP0_INPKTRDY_DATAEND();
					ep0State=EP0_STATE_INIT;     
					ep0SubState=0;
				}
			}
			break;

		case EP0_STATE_GD_STR_I2:
			if(descSetup.bLengthL==2)
			{
				WrPktEp0((U8 *)device_serial_number,2); 
				SET_EP0_IN_PKT_RDY();
				ep0State=EP0_STATE_INIT;
			}
			else
			{
				if( (ep0SubState*16+16) < sizeof(device_serial_number) )
				{
					WrPktEp0((U8 *)device_serial_number+(ep0SubState*16),16); 
					SET_EP0_IN_PKT_RDY();
					ep0State=EP0_STATE_GD_STR_I2;
					ep0SubState++;
				}
				else
				{
					WrPktEp0((U8 *)device_serial_number+(ep0SubState*16),
					sizeof(device_serial_number)-(ep0SubState*16));
					SET_EP0_INPKTRDY_DATAEND();
					ep0State=EP0_STATE_INIT;
					ep0SubState=0;
				}
			}
			break;
		default:
//			DbgPrintf("UE:G?D");
			break;
	}//End of switch(ep0State)
}//End of Ep0Handler()

⌨️ 快捷键说明

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