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

📄 host_811.lst

📁 51+sl811读写U盘的源程序+原理图
💻 LST
📖 第 1 页 / 共 4 页
字号:
 741          			return FALSE;
 742          	}
 743          
 744          	//------------------------------------------------
 745          	// Get HUB Class Specific Descriptor (per port switching)
 746          	//------------------------------------------------
 747          	if(uDev[usbaddr].bClass==HUBCLASS)
 748              {														// enumerating a HUB device		
 749             		pHub =(pHubDesc)DBUF;								// Ask for 71 bytes ???
 750          	    if (!GetHubDesc(uAddr,0x00,0x47,DBUF))
 751          			return FALSE;									// Get Hub Desriptor
 752          		if (!GetStatus(uAddr,STATUS)) 
 753          			return FALSE;     								// Get Status
 754          		if (!Set_Configuration(uAddr,DEVICE))
 755          			return FALSE;  									// Set configuration
 756          
 757          		pNumPort = pHub->bNbrPort;							// save no. of ports available
 758          		for(i=1; i<=pNumPort; i++)							// ClearPortFeature: C_PORT_CONNECTION off
 759          		    if(!PortFeature(uAddr,CLEAR_FEATURE, C_PORT_CONNECTION,i))	
 760          				return FALSE;
 761          
 762          		for(i=1; i<=pNumPort; i++)							// SetPortFeature: PORT_POWER on
 763          		{
 764          		    if(!PortFeature(uAddr,SET_FEATURE, PORT_POWER, i)) 	
 765          				return FALSE;								
 766          		}
 767          
 768          		for(i=1; i<=pHub->bNbrPort; i++)					// GetPortStatus(wHubStatus,wHubChange)
 769          		   if( !GetPortStatus(uAddr,i,STATUS) ) 			//
 770          				return FALSE;								//
 771          
 772          		for(i=2;i<=pNumPort+1;i++)							// clear port present status
 773          		{													// address #2..#5 only
 774          			uHub.bPortPresent[i] = 0;						// clear status
 775          			uHub.bPortNumber[i] = 0;						//
 776          		}
 777          		HUB_DEVICE = TRUE;									// Set Hub flag, as long as a hub is attached 
 778          	}														// directly to the HUB_DEVICE will be set
 779          
 780          	return TRUE;
 781          }
 782          
 783          //*****************************************************************************************
 784          // Full-speed and low-speed detect - Device atttached directly to SL811HS
 785          //*****************************************************************************************
 786          int speed_detect() 
 787          {
 788          	pNumPort	= 0;					// zero no. of downstream ports
 789          	SLAVE_FOUND	= FALSE;				// Clear USB device found flag
 790          	FULL_SPEED  = TRUE;					// Assume full speed device
 791          	HUB_DEVICE  = FALSE;				// not HUB device
 792          	DATA_STOP	= FALSE;				//
C51 COMPILER V6.10  HOST_811                                                               09/04/2002 22:22:07 PAGE 14  

 793           
 794          	SL811Write(cSOFcnt,0xAE);      		// Set SOF high counter, no change D+/D-, host mode
 795          	SL811Write(CtrlReg,0x08);      		// Reset USB engine, full-speed setup, suspend disable
 796          	EZUSB_Delay(10);					// Delay for HW stablize
 797          	SL811Write(CtrlReg,0x00);      		// Set to normal operation
 798          	SL811Write(IntEna,0x61);      		// USB-A, Insert/Remove, USB_Resume.
 799          	SL811Write(IntStatus,INT_CLEAR);	// Clear Interrupt enable status
 800          	EZUSB_Delay(10);					// Delay for HW stablize
 801          
 802          	if(SL811Read(IntStatus)&USB_RESET)
 803          	{									// test for USB reset
 804          		SL811Write(IntStatus,INT_CLEAR);// Clear Interrupt enable status
 805          		EZUSB_Delay(30);				// Blink LED - waiting for slave USB plug-in
 806          		OUTB ^= ACTIVE_BLINK;			// Blink Active LED
 807          		OUTA |= PORTX_LED;				// clear debug LEDs
 808          		return 0;						// exit speed_detect()
 809          	}
 810          
 811          	if((SL811Read(IntStatus)&USB_DPLUS)==0)	// Checking full or low speed	
 812          	{									// ** Low Speed is detected ** //
 813          		SL811Write(cSOFcnt,0xEE);   	// Set up host and low speed direct and SOF cnt
 814          		SL811Write(cDATASet,0xE0); 		// SOF Counter Low = 0xE0; 1ms interval
 815          		SL811Write(CtrlReg,0x21);  		// Setup 6MHz and EOP enable         
 816          		uHub.bPortSpeed[1] = 1;			// low speed for Device #1
 817          		FULL_SPEED = FALSE;				// low speed device flag
 818          	}
 819          	else	
 820          	{									// ** Full Speed is detected ** //
 821          		SL811Write(cSOFcnt,0xAE);   	// Set up host & full speed direct and SOF cnt
 822          		SL811Write(cDATASet,0xE0);  	// SOF Counter Low = 0xE0; 1ms interval
 823          		SL811Write(CtrlReg,0x05);   	// Setup 48MHz and SOF enable
 824          		uHub.bPortSpeed[1] = 0;			// full speed for Device #1
 825          	}
 826          
 827          	OUTB |= ACTIVE_BLINK;				// clear Active LED
 828          	SLAVE_FOUND = TRUE;					// Set USB device found flag
 829          	SLAVE_ENUMERATED = FALSE;			// no slave device enumeration
 830          
 831          	SL811Write(EP0Status,0x50);   		// Setup SOF Token, EP0
 832          	SL811Write(EP0Counter,0x00);		// reset to zero count
 833          	SL811Write(EP0Control,0x01);   		// start generate SOF or EOP
 834          
 835          	EZUSB_Delay(25);					// Hub required approx. 24.1mS
 836          	SL811Write(IntStatus,INT_CLEAR);	// Clear Interrupt status
 837          	return 0;    						// exit speed_detect();
 838          }
 839          
 840          //*****************************************************************************************
 841          // Detect USB Device
 842          //*****************************************************************************************
 843          int slave_detect(void)
 844          {
 845          	int retDataRW = FALSE;
 846          	
 847          	//-------------------------------------------------------------------------
 848          	// Wait for EZUSB enumeration
 849          	//-------------------------------------------------------------------------
 850          	if(!CONFIG_DONE)						// start SL811H after EZ-USB is configured
 851          		return 0;
 852          
 853          	//-------------------------------------------------------------------------
 854          	// Wait for SL811HS enumeration
C51 COMPILER V6.10  HOST_811                                                               09/04/2002 22:22:07 PAGE 15  

 855          	//-------------------------------------------------------------------------
 856          	if(!SLAVE_ENUMERATED)					// only if slave is not configured
 857          	{
 858          		speed_detect();						// wait for an USB device to be inserted to 
 859          		if(SLAVE_FOUND)						// the SL811HST host
 860          		{
 861          	  		if(EnumUsbDev(1))				// enumerate USB device, assign USB address = #1
 862          			{
 863          			   	SLAVE_ENUMERATED = TRUE;	// Set slave USB device enumerated flag
 864          				uHub.bPortPresent[1] = 1;	// set device addr #1 present
 865          				Set_ezDEV(1);				// inform master of new attach/detach
 866          			}	
 867          		}
 868          	}
 869          
 870          	//-------------------------------------------------------------------------
 871          	// SL811HS enumerated, proceed accordingly
 872          	//-------------------------------------------------------------------------
 873          	else									
 874          	{													
 875          		OUTB &= ~ACTIVE_BLINK;				// Turn on Active LED, indicate successful slave enum
 876          		if(Slave_Detach())					// test for slave device detach ???
 877          			return 0;						// exit now.
 878          		//----------------------------------------------
 879          		// HUB DEVICE Polling (Addr #1, EndPt #1)		
 880          		//----------------------------------------------
 881          		// Polling of Hub deivce Endpoint #1 for any Port Attachement
 882          		// for onboard HUB device, after enumeration, start to
 883          		// transfer IN token to check for ports attachment
 884          		// wLen = wPayload = 1 byte, always use USB address #1
 885          		// if return is TRUE, a data pkt was ACK, data in HubChange
 886          		// else is a NAK, no data was received 
 887          		if(HUB_DEVICE && dsPoll)									
 888          		{												
 889          			retDataRW = DataRW(HUB_ADDR,uDev[1].bEPAddr[1],uDev[1].wPayLoad[1],1,HubChange);
 890          			if(retDataRW) 
 891          			{											
 892          				HubPortEnum();							
 893          				Set_ezDEV(1);                           // inform master of new attach/detach
 894          			}											
 895          			EZUSB_Delay(10);							// maintain a polling interval 
 896          		}												
 897          	} // end of else
 898          
 899          	return 0;
 900          }
 901          
 902          //*****************************************************************************************
 903          // Slave_Detach
 904          //*****************************************************************************************
 905          int Slave_Detach(void)
 906          {
 907          	if( (SL811Read(IntStatus)&INSERT_REMOVE) || (SL811Read(IntStatus)&USB_RESET) )
 908          	{												// Test USB detached?
 909          		SLAVE_ENUMERATED = FALSE;					// return to un-enumeration
 910          		uHub.bPortPresent[1] = 0;					// Device #1 not present
 911          
 912          		Set_ezDEV(1);								// inform master of slave detach
 913          		SL811Write(IntStatus,INT_CLEAR); 			// clear interrupt status
 914          		return TRUE;								// exit now !!!
 915          	}
 916          
C51 COMPILER V6.10  HOST_811                                                               09/04/2002 22:22:07 PAGE 16  

 917          	return FALSE;
 918          }
 919          
 920          //*****************************************************************************************
 921          // Indicate to EZUSB's endpoint #2 IN of a new device attach/detach
 922          //*****************************************************************************************
 923          void Set_ezDEV(BYTE chg)
 924          {
 925          	if( (dsPoll) && (!(IN2CS & bmEPBUSY)) )
 926          	{
 927          		IN2BUF[0] = chg;	// Arm endpoint #2, inform EZUSB host of attach/detatch
 928          		IN2BC = 1;
 929          	}
 930          }
 931          
 932          //*****************************************************************************************
 933          // SL811H variables initialization
 934          //*****************************************************************************************
 935          void sl811h_init(void)
 936          {	
 937          	int i;
 938          
 939          	for(i=0;i<MAX_DEV;i++)
 940          	{
 941          		uHub.bPortPresent[i] = 0;
 942          		uHub.bPortNumber[i] = 0;
 943          	}
 944          
 945          	SL811H_DATA = 0x00;
 946          	SL811H_ADDR = 0x00;
 947          	pNumPort	= 0x00;			
 948          
 949          	FULL_SPEED = TRUE;	
 950          	HUB_DEVICE = FALSE;
 951          	SLAVE_FOUND = FALSE;
 952          	SLAVE_ENUMERATED = FALSE;
 953          	BULK_OUT_DONE = FALSE;
 954          	DESC_XFER = FALSE;
 955          	DATA_XFER = FALSE;
 956          	DATA_XFER_OUT = FALSE;
 957          	DATA_INPROCESS = FALSE;
 958          	pLS_HUB = FALSE;
 959          	IN2BUF[0] = 0;
 960          
 961              dsPoll = 1;				    // poll downstream port conections
 962          
 963          	//----------------------------
 964          	// SL811H + EZUSB I/Os setup
 965          	//----------------------------
 966          	PORTBCFG &= 0xAC;			// Select i/o function for PB6, PB4, PB1, PB0
 967          	OEB      |= 0x43;			// Set  PB6(Output), PB4(Input), PB1(Output), PB0(Output) 
 968          	OUTB     |= 0x43;			// Default output high
 969          
 970          	PORTACFG &= 0x0F;			// Select i/o function for PA7~PA4
 971          	OEA      |= 0xF0;			// Set PA7~PA4(Output)
 972          	OUTA     |= 0xF0;			// Default output high
 973          
 974          	//----------------------------
 975          	// Debug Monitor I/Os setup
 976          	//----------------------------
 977          	PORTBCFG |= 0x0C;			// Select alternate function RxD1(PB2) & RxD1(PB3)
 978          	PORTCCFG |= 0xC0;			// Select alternate function nWR(PC6) & nRD(PC7)
C51 COMPILER V6.10  HOST_811                                                               09/04/2002 22:22:07 PAGE 17  

 979          								// Also needed for SL811H
 980          	//----------------------------
 981          	// SL811HST hardware reset
 982          	//----------------------------
 983          	OUTB &= ~nRESET;			// reset SL811HST
 984          	EZUSB_Delay(5);				// for 5ms
 985          	OUTB |= nRESET;				// clear reset
 986          	OUTB &= ~nHOST_SLAVE_MODE;	// set to Host mode
 987          }

C51 COMPILATION COMPLETE.  0 WARNING(S),  6 ERROR(S)

⌨️ 快捷键说明

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