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

📄 usb.c

📁 用于WinCE的eboot的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:

	for(i=0;i<num;i++)
	{
		buf[i]=(U8)(pUSBCtrlAddr->EP3F.fifo_data);
    }
}

void PrepareEp1Fifo(void) 
{
    int i;
    pUSBCtrlAddr->INDEX.index=1;
    
    for(i=0;i<EP1_PKT_SIZE;i++)ep1Buf[i]=(U8)(transferIndex+i);
    WrPktEp1(ep1Buf,EP1_PKT_SIZE);
	pUSBCtrlAddr->EP0ICSR1.opr_ipr = 1;
	pUSBCtrlAddr->EP0ICSR1.sts_ = 0;
	pUSBCtrlAddr->EP0ICSR1.de_ff = 0;
}

void Ep1Handler(void)
{
    pUSBCtrlAddr->INDEX.index=1;
    
    if(pUSBCtrlAddr->EP0ICSR1.sds_sts)
    {   
		pUSBCtrlAddr->EP0ICSR1.opr_ipr = 0;
		pUSBCtrlAddr->EP0ICSR1.sts_ = 0;
		pUSBCtrlAddr->EP0ICSR1.de_ff = 0;
		pUSBCtrlAddr->EP0ICSR1.sds_sts = 0;
   		return;
    }	

    transferIndex++;

    PrepareEp1Fifo(); 

    return;
}

void Ep0Handler(void)
{
	static int ep0SubState;

	pUSBCtrlAddr->INDEX.index=0;

	//DATAEND interrupt(ep0_csr==0x0) will be ignored 
	//because ep0State==EP0_STATE_INIT when the DATAEND interrupt is issued.

//	EdbgOutputDebugString("INFO : Ep0Handler\r\n");

	if(pUSBCtrlAddr->EP0ICSR1.se_sds)
	{   
		// Host may end GET_DESCRIPTOR operation without completing the IN data stage.
		// If host does that, SETUP_END bit will be set.
		// OUT_PKT_RDY has to be also cleared because status stage sets OUT_PKT_RDY to 1.
		CLR_EP0_SETUP_END();
		if(pUSBCtrlAddr->EP0ICSR1.opr_ipr) 
		{
			FLUSH_EP0_FIFO(); //(???)
			//I think this isn't needed because EP0 flush is done automatically.   
			CLR_EP0_OUT_PKT_RDY();
		}

		ep0State=EP0_STATE_INIT;
		return;
	}	

	//I think that EP0_SENT_STALL will not be set to 1.
	if(pUSBCtrlAddr->EP0ICSR1.sts_)
	{   
		EdbgOutputDebugString("[STALL]\r\n");
		CLR_EP0_SENT_STALL();
		if(pUSBCtrlAddr->EP0ICSR1.opr_ipr)
		{
			CLR_EP0_OUT_PKT_RDY();
		}

		ep0State=EP0_STATE_INIT;
		return;
	}	

	if((pUSBCtrlAddr->EP0ICSR1.opr_ipr) && (ep0State==EP0_STATE_INIT))
	{
		RdPktEp0((U8 *)&descSetup,EP0_PKT_SIZE);

		switch(descSetup.bRequest)
		{
		case GET_DESCRIPTOR:
			switch(descSetup.bValueH)        
			{
            case USB_DEVICE_TYPE:
				CLR_EP0_OUT_PKT_RDY();
				ep0State=EP0_STATE_GD_DEV_0;	        
				break;	
			case CONFIGURATION_TYPE:
				CLR_EP0_OUT_PKT_RDY();
				if((descSetup.bLengthL+(descSetup.bLengthH<<8))>0x9)
					//bLengthH should be used for bLength=0x209 at WIN2K.    	
					ep0State=EP0_STATE_GD_CFG_0; //for WIN98,WIN2K
				else	    	    
					ep0State=EP0_STATE_GD_CFG_ONLY_0; //for WIN2K
				break;
			case STRING_TYPE:
				CLR_EP0_OUT_PKT_RDY();
				switch(descSetup.bValueL)
				{
				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:
					EdbgOutputDebugString("[UE:STRI?]\r\n");
					break;
				}
				ep0SubState=0;
				break;
			case INTERFACE_TYPE:
				EdbgOutputDebugString("[GDI]\r\n");
				CLR_EP0_OUT_PKT_RDY();
				ep0State=EP0_STATE_GD_IF_ONLY_0; //for WIN98
				break;
			case ENDPOINT_TYPE:	    	
				EdbgOutputDebugString("[GDE]\r\n");
				CLR_EP0_OUT_PKT_RDY();
				switch(descSetup.bValueL&0xf)
				{
				case 0:
					ep0State=EP0_STATE_GD_EP0_ONLY_0;
					break;
				case 1:
					ep0State=EP0_STATE_GD_EP1_ONLY_0;
					break;
				default:
					EdbgOutputDebugString("[UE:GDE?]\r\n");
					break;
				}
				break;
			default:
				EdbgOutputDebugString("[UE:GD?]\r\n");
				break;
			}
			break;

		case SET_ADDRESS:
			pUSBCtrlAddr->udcFAR.func_addr = descSetup.bValueL;
			pUSBCtrlAddr->udcFAR.addr_up = 1;
			CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
			ep0State=EP0_STATE_INIT;
			break;
    	
		case SET_CONFIGURATION:
			ConfigSet.ConfigurationValue=descSetup.bValueL;
			CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
			ep0State=EP0_STATE_INIT;

			break;

			//////////////////////// For chapter 9 test ////////////////////

		case CLEAR_FEATURE:
			switch (descSetup.bmRequestType)
			{
			case DEVICE_RECIPIENT:
				if (descSetup.bValueL == 1)
					Rwuen = FALSE;
				break;

			case ENDPOINT_RECIPIENT:
				if (descSetup.bValueL == 0)
				{
					if((descSetup.bIndexL & 0x7f) == 0x00){
						StatusGet.Endpoint0= 0;    
					}
					if((descSetup.bIndexL & 0x8f) == 0x81){           // IN  Endpoint 1
						StatusGet.Endpoint1= 0;           
					}
					if((descSetup.bIndexL & 0x8f) == 0x03){          // OUT Endpoint 3
						StatusGet.Endpoint3= 0;      
					}
				}
				break;

			default:
				break;
			}
			CLR_EP0_OUTPKTRDY_DATAEND();
			ep0State=EP0_STATE_INIT;
			break;

		case GET_CONFIGURATION:
			CLR_EP0_OUT_PKT_RDY();
			ep0State=EP0_CONFIG_SET;
			break;

		case GET_INTERFACE:
			CLR_EP0_OUT_PKT_RDY();
			ep0State=EP0_INTERFACE_GET;
			break;

		case GET_STATUS:
			switch(descSetup.bmRequestType)
			{
			case  (0x80):
				CLR_EP0_OUT_PKT_RDY();
				StatusGet.Device=((U8)Rwuen<<1)|(U8)Selfpwr;
				ep0State=EP0_GET_STATUS0;
				break;

			case  (0x81):
				CLR_EP0_OUT_PKT_RDY();
				StatusGet.Interface=0;
				ep0State=EP0_GET_STATUS1;
				break;

			case  (0x82):
				CLR_EP0_OUT_PKT_RDY();
				if((descSetup.bIndexL & 0x7f) == 0x00){
					ep0State=EP0_GET_STATUS2;
				}
				if((descSetup.bIndexL & 0x8f) == 0x81){
					ep0State=EP0_GET_STATUS3;
				}
				if((descSetup.bIndexL & 0x8f) == 0x03){
					ep0State=EP0_GET_STATUS4;
				}
				break;

			default:
				break;
    	  	}
    	  	break;

		case SET_DESCRIPTOR:
			CLR_EP0_OUTPKTRDY_DATAEND();
			ep0State=EP0_STATE_INIT;
			break;

		case SET_FEATURE:
			switch (descSetup.bmRequestType)
			{
			case DEVICE_RECIPIENT:
				if (descSetup.bValueL == 1)
					Rwuen = TRUE;
				break;

			case ENDPOINT_RECIPIENT:
				if (descSetup.bValueL == 0)
				{
					if((descSetup.bIndexL & 0x7f) == 0x00){
						StatusGet.Endpoint0= 1;
					}
					if((descSetup.bIndexL & 0x8f) == 0x81){
						StatusGet.Endpoint1= 1;
					}
					if((descSetup.bIndexL & 0x8f) == 0x03){
						StatusGet.Endpoint3= 1;
					}
				}
				break;
			default:
			break;
			}
			CLR_EP0_OUTPKTRDY_DATAEND();
			ep0State=EP0_STATE_INIT;
			break;

		case SET_INTERFACE:
			InterfaceGet.AlternateSetting= descSetup.bValueL;
			CLR_EP0_OUTPKTRDY_DATAEND(); 
			ep0State=EP0_STATE_INIT;
			break;

		case SYNCH_FRAME:
			ep0State=EP0_STATE_INIT;
			break;

    	  //////////////////////////////////////////////////////////////

		default:
			EdbgOutputDebugString("[UE:SETUP=%x]\r\n",descSetup.bRequest);
			CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
			ep0State=EP0_STATE_INIT;
			break;
		}
	}

	switch(ep0State)
	{
	case EP0_STATE_INIT:
		break; 

	//=== GET_DESCRIPTOR:DEVICE ===
	case EP0_STATE_GD_DEV_0:
		WrPktEp0((U8 *)&descDev+0,8); //EP0_PKT_SIZE
		SET_EP0_IN_PKT_RDY();
		ep0State=EP0_STATE_GD_DEV_1;
		break;

	case EP0_STATE_GD_DEV_1:
		WrPktEp0((U8 *)&descDev+0x8,8); 
		SET_EP0_IN_PKT_RDY();
		ep0State=EP0_STATE_GD_DEV_2;
		break;

	case EP0_STATE_GD_DEV_2:
		WrPktEp0((U8 *)&descDev+0x10,2);   //8+8+2=0x12
		SET_EP0_INPKTRDY_DATAEND();
		ep0State=EP0_STATE_INIT;
		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:
		WrPktEp0((U8 *)&descConf+0,8); //EP0_PKT_SIZE
		SET_EP0_IN_PKT_RDY();
		ep0State=EP0_STATE_GD_CFG_1;
		break;

	case EP0_STATE_GD_CFG_1:
		WrPktEp0((U8 *)&descConf+8,1); 
		WrPktEp0((U8 *)&descIf+0,7); 
		SET_EP0_IN_PKT_RDY();
		ep0State=EP0_STATE_GD_CFG_2;
		break;

	case EP0_STATE_GD_CFG_2:
		WrPktEp0((U8 *)&descIf+7,2); 
		WrPktEp0((U8 *)&descEndpt0+0,6); 
		SET_EP0_IN_PKT_RDY();
		ep0State=EP0_STATE_GD_CFG_3;
		break;

	case EP0_STATE_GD_CFG_3:
		WrPktEp0((U8 *)&descEndpt0+6,1); 
		WrPktEp0((U8 *)&descEndpt1+0,7); 
		SET_EP0_IN_PKT_RDY();
		ep0State=EP0_STATE_GD_CFG_4;            
		break;

	case EP0_STATE_GD_CFG_4:
		 //zero length data packit 
		SET_EP0_INPKTRDY_DATAEND();
		ep0State=EP0_STATE_INIT;            
		break;

	//=== GET_DESCRIPTOR:CONFIGURATION ONLY===
	case EP0_STATE_GD_CFG_ONLY_0:
		WrPktEp0((U8 *)&descConf+0,8); //EP0_PKT_SIZE
		SET_EP0_IN_PKT_RDY();
		ep0State=EP0_STATE_GD_CFG_ONLY_1;
		break;
    
	case EP0_STATE_GD_CFG_ONLY_1:
		WrPktEp0((U8 *)&descConf+8,1); 
		SET_EP0_INPKTRDY_DATAEND();
		ep0State=EP0_STATE_INIT;            
		break;

	//=== GET_DESCRIPTOR:INTERFACE ONLY===
	case EP0_STATE_GD_IF_ONLY_0:
		EdbgOutputDebugString("[GDI0]\r\n");
		WrPktEp0((U8 *)&descIf+0,8); 
		SET_EP0_IN_PKT_RDY();
		ep0State=EP0_STATE_GD_IF_ONLY_1;
		break;

	case EP0_STATE_GD_IF_ONLY_1:
		EdbgOutputDebugString("[GDI1]\r\n");
		WrPktEp0((U8 *)&descIf+8,1); 
		SET_EP0_INPKTRDY_DATAEND();
		ep0State=EP0_STATE_INIT;            
		break;

	//=== GET_DESCRIPTOR:ENDPOINT 0 ONLY===
	case EP0_STATE_GD_EP0_ONLY_0:
		EdbgOutputDebugString("[GDE00]\r\n");
		WrPktEp0((U8 *)&descEndpt0+0,7); 
		SET_EP0_INPKTRDY_DATAEND();
		ep0State=EP0_STATE_INIT;            
		break;
            
	//=== GET_DESCRIPTOR:ENDPOINT 1 ONLY===
	case EP0_STATE_GD_EP1_ONLY_0:
		EdbgOutputDebugString("[GDE10]\r\n");
		WrPktEp0((U8 *)&descEndpt1+0,7); 
		SET_EP0_INPKTRDY_DATAEND();
		ep0State=EP0_STATE_INIT;            
		break;
            
////////////////////////////////////////////

	case EP0_INTERFACE_GET:
		WrPktEp0((U8 *)&InterfaceGet+0,1);
		SET_EP0_INPKTRDY_DATAEND();
		ep0State=EP0_STATE_INIT;      
		break;

 
	//=== GET_DESCRIPTOR:STRING ===
	case EP0_STATE_GD_STR_I0:
		WrPktEp0((U8 *)descStr0, 4 );  
		SET_EP0_INPKTRDY_DATAEND();
		ep0State=EP0_STATE_INIT;     
		ep0SubState=0;
		break;

	case EP0_STATE_GD_STR_I1:
		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:
		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
		{
			WrPktEp0((U8 *)descStr2+(ep0SubState*EP0_PKT_SIZE),
			sizeof(descStr2)-(ep0SubState*EP0_PKT_SIZE)); 
			SET_EP0_INPKTRDY_DATAEND();
			ep0State=EP0_STATE_INIT;     
			ep0SubState=0;
		}
		break;

	case EP0_CONFIG_SET:

⌨️ 快捷键说明

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