亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fw.c

?? ezUSB fireware 的固件
?? C
字號:
//-----------------------------------------------------------------------------
//	File:		fw.c
//	Contents:	Firmware frameworks task dispatcher and device request parser
//				source.
//
//	Copyright (c) 1997 AnchorChips, Inc. All rights reserved
//      Adapted for use with HIDs by Jan Axelson (jan@lvr.com)
//-----------------------------------------------------------------------------
#include "ezusb.h"
#include "ezregs.h"

//-----------------------------------------------------------------------------
// Random Macros
//-----------------------------------------------------------------------------
#define	min(a,b) (((a)<(b))?(a):(b))
#define	max(a,b) (((a)>(b))?(a):(b))

//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
#define	DELAY_COUNT				0x9248*8L		// Delay for 8 sec at 24Mhz, 4 sec at 48
                                                                                      
//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
volatile BOOL	GotSUD;
BOOL		Rwuen;
BOOL		Selfpwr;
volatile BOOL	Sleep;						// Sleep mode enable flag

WORD	pDeviceDscr;	// Pointer to Device Descriptor; Descriptors may be moved
WORD	pConfigDscr;	
WORD	pStringDscr;
// HID code start
WORD	pReportDscr;
BYTE	reportlen;
// HID code end	

//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
void SetupCommand(void);
void TD_Init(void);
void TD_Poll(void);
BOOL TD_Suspend(void);
BOOL TD_Resume(void);

BOOL DR_GetDescriptor(void);
BOOL DR_SetConfiguration(void);
BOOL DR_GetConfiguration(void);
BOOL DR_SetInterface(void);
BOOL DR_GetInterface(void);
BOOL DR_GetStatus(void);
BOOL DR_ClearFeature(void);
BOOL DR_SetFeature(void);
BOOL DR_VendorCmnd(void);

//-----------------------------------------------------------------------------
// Code
//-----------------------------------------------------------------------------

// Task dispatcher
void main(void)
{
	DWORD	i;
	WORD	offset;
	DWORD	DevDescrLen;
	DWORD	j=0;
	WORD	IntDescrAddr;
	WORD	ExtDescrAddr;

	// Initialize Global States
	Sleep = FALSE;					// Disable sleep mode
	Rwuen = FALSE;					// Disable remote wakeup
	Selfpwr = FALSE;				// Disable self powered
	GotSUD = FALSE;					// Clear "Got setup data" flag

	// Initialize user device
	TD_Init();

	// The following section of code is used to relocate the descriptor table. 
	// Since the SUDPTRH and SUDPTRL are assigned the address of the descriptor 
	// table, the descriptor table must be located in on-part memory.
	// The 4K demo tools locate all code sections in external memory.
	// The descriptor table is relocated by the frameworks ONLY if it is found 
	// to be located in external memory.
	pDeviceDscr = (WORD)&DeviceDscr;
	pConfigDscr = (WORD)&ConfigDscr;
	pStringDscr = (WORD)&StringDscr;
// HID code start
	pReportDscr = (WORD)&ReportDscr;
// HID code end

	if ((WORD)&DeviceDscr & 0xe000)
	{
		IntDescrAddr = INTERNAL_DSCR_ADDR;
		ExtDescrAddr = (WORD)&DeviceDscr;
		DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
		for (i = 0; i < DevDescrLen; i++)
			*((BYTE xdata *)IntDescrAddr+i) = 0xCD;
		for (i = 0; i < DevDescrLen; i++)
			*((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
		pDeviceDscr = IntDescrAddr;
		offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
		pConfigDscr -= offset;
		pStringDscr -= offset;
// HID code start
		pReportDscr -= offset;
// HID code end
	}

	EZUSB_IRQ_ENABLE();				// Enable USB interrupt (INT2)
	EZUSB_ENABLE_RSMIRQ();				// Wake-up interrupt

	// The 8051 is responsible for all USB events, even those that have happened
	// before this point.  We cannot ignore pending USB interrupts.
	// The chip will come out of reset with the flags all cleared.
	//	USBIRQ = 0xff;				// Clear any pending USB interrupt requests
	PORTCCFG |= 0xc0;				// Turn on r/w lines for external memory 

	USBBAV = USBBAV | 1 & ~bmBREAK;	// Disable breakpoints and autovectoring
	USBIEN |= bmSUDAV | bmSUTOK | bmSUSP | bmURES;	// Enable selected interrupts
	EA = 1;						// Enable 8051 interrupts

	// This loop waits until we receive a setup packet from the host.
	// NOTE: The device will continue to renumerate until it receives a setup
	// packet.  This fixes a microsoft USB bug that loses disconnect/reconnect 
	// events during initial USB device driver configuration dialog box.
	// B2 Load:  This code is not needed for B2 load, only for renumeration.
	#ifndef NO_RENUM
		while(!GotSUD)
		{
			if(!GotSUD)
				EZUSB_Discon(TRUE);	// renumerate until setup received
			for(j=0;(j<DELAY_COUNT) && (!GotSUD);++j);
		}
	#endif


	CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)

	// Task Dispatcher
	while(TRUE)					// Main Loop
	{
		if(GotSUD)				// Wait for SUDAV
		{
			SetupCommand();	 		// Implement setup command
  			GotSUD = FALSE;		   	// Clear SUDAV flag
		}

		// Poll User Device
		// NOTE: Idle mode stops the processor clock.  There are only two
		// ways out of idle mode, the WAKEUP pin, and detection of the USB
		// resume state on the USB bus.  The timers will stop and the
		// processor will not wake up on any other interrupts.
		if (Sleep)
		    {
    		if(TD_Suspend())
    		    { 
    		    Sleep = FALSE;	   		// Clear the "go to sleep" flag.  Do it here to prevent any race condition between wakeup and the next sleep.
    		    do
    		        {
       			    EZUSB_Susp();			// Place processor in idle mode.
    		        }
                while(!Rwuen && EZUSB_EXTWAKEUP());
                // Must continue to go back into suspend if the host has disabled remote wakeup
                // *and* the wakeup was caused by the external wakeup pin.
                
    			// 8051 activity will resume here due to USB bus or Wakeup# pin activity.
    			EZUSB_Resume();	// If source is the Wakeup# pin, signal the host to Resume.		
    			TD_Resume();
    		    }   
		    }
		TD_Poll();
	}
}

// Device request parser
void SetupCommand(void)
// A Setup packet has been received.
{
	//*dscr_ptr is the address of a descriptor??	
	void	*dscr_ptr;
	DWORD	i;

	switch(SETUPDAT[1])
	//SETUPDAT[1] contains the control request
	{
		case SC_GET_DESCRIPTOR:						// *** Get Descriptor
			if(DR_GetDescriptor())
			//If the request is Get_Descriptor, find out which descriptor was requested.
				switch(SETUPDAT[3])
				//The descriptor type is in the high byte of wValue, stored in SETUPDAT[3].			
				{
					case GD_DEVICE:				// Device
					//If the request is for a device descriptor, store the pointers
					//in SUDPTRH and SUDPTRL and the hardware does the rest.
						SUDPTRH = MSB(pDeviceDscr);
						SUDPTRL = LSB(pDeviceDscr);
						break;
					case GD_CONFIGURATION:			// Configuration
					/*If the request is for a configuration descriptor, find out if the
					configuration is valid. The config. index is in the low byte of
					wValue, stored in SETUPDAT[2].

				       	*/
					
						if(dscr_ptr = (void *)EZUSB_GetConfigDscr(SETUPDAT[2]))
						{
							SUDPTRH = MSB(dscr_ptr);
							SUDPTRL = LSB(dscr_ptr);
						}
						else
							EZUSB_STALL_EP0(); 	// Stall End Point 0
						break;
					case GD_STRING:				// String
						if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2]))
						{
							// Workaround for rev D errata number 8
							// If you're certain that you will never run on rev D,
							// you can just do this:
							// SUDPTRH = MSB(dscr_ptr);
							// SUDPTRL = LSB(dscr_ptr);
							STRINGDSCR *sdp;
							BYTE len;

							sdp = dscr_ptr;

							len = sdp->length;
							if (len > SETUPDAT[6]) 
								len = SETUPDAT[6]; //limit to the requested length
							
							while (len)
							{
								for(i=0; i<min(len,64); i++)
									*(IN0BUF+i) = *((BYTE xdata *)sdp+i);

								//set length and arm Endpoint
								EZUSB_SET_EP_BYTES(IN0BUF_ID,min(len,64));	
								len -= min(len,64);

								// Wait for it to go out (Rev C and above)
								while(EP0CS & 0x04)
									;
							}

							// Arm a 0 length packet just in case.  There was some reflector traffic about
							// Apple hosts asking for too much data.  This will keep them happy and will
							// not hurt valid hosts because the next SETUP will clear this.
							EZUSB_SET_EP_BYTES(IN0BUF_ID,0);	
							// Clear the HS-nak bit
							EP0CS = bmHS;
						}
						else 
							EZUSB_STALL_EP0();	// Stall End Point 0
						break;
//HID code start
					case GD_REPORT:				
						//HID Report descriptor
						//Assumes there is one report descriptor.
						//To do: add the ability to return a specific report descriptor.
						//Can't use SUDPTRH and SUDPTRL because the report descriptor doesn't store 
						//its length in the first bytes.
						//Instead, adapt code from the String descriptor rev D errata code (above).
						{
							//rdp holds the address of a REPORTDSCR structure.
							REPORTDSCR *rdp;
							//dscr_ptr is the address of the report descriptor
							dscr_ptr = (REPORTDSCR xdata *) pReportDscr;
							rdp = dscr_ptr;

							//Get the report descriptor's length
							reportlen = sizeof(REPORTDSCR);
							// If the descriptor is longer than the requested amount,
							// limit the data returned to the requested amount. 
							if (reportlen > SETUPDAT[6]) 
								reportlen = SETUPDAT[6]; 
							// If the host requests more bytes than the descriptor contains,
							// the device will send the descriptor only.
 							
							while (reportlen)
							{
								//Copy the data to send into Endpoint 0's IN buffer.
								//In each transaction, send the entire descriptor or 64 bytes, whichever is less.
								//The data to send begins at the address pointed to by *rdp.
								for(i=0; i<min(reportlen,64); i++)
									*(IN0BUF+i) = *((BYTE xdata *)rdp+i);

								//Set the amount of data to send and arm the endpoint
								EZUSB_SET_EP_BYTES(IN0BUF_ID,min(reportlen,64));	
								// If reportlen <= 64, all bytes have been copied, so set reportlen =0.
								// Else, set reportlen = number of bytes remaining to send.
								reportlen -= min(reportlen,64);

								// Wait for the data to go out (Rev C and above)
								while(EP0CS & 0x04);
							}
							
                                                }
						//else 
						//	EZUSB_STALL_EP0();	// Stall End Point 0

						break;
//HID code end

					default:				// Invalid request
						EZUSB_STALL_EP0();		// Stall End Point 0
				}
			break;                                                                       
		case SC_GET_INTERFACE:						// *** Get Interface
			DR_GetInterface();
			break;
		case SC_SET_INTERFACE:						// *** Set Interface
			DR_SetInterface();
			break;
		case SC_SET_CONFIGURATION:					// *** Set Configuration
			DR_SetConfiguration();
			break;
		case SC_GET_CONFIGURATION:					// *** Get Configuration
			DR_GetConfiguration();
			break;
		case SC_GET_STATUS:						// *** Get Status
			if(DR_GetStatus())
				switch(SETUPDAT[0])
				{
					case GS_DEVICE:				// Device
						IN0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
						IN0BUF[1] = 0;
						EZUSB_SET_EP_BYTES(IN0BUF_ID,2);
						break;
					case GS_INTERFACE:			// Interface
						IN0BUF[0] = 0;
						IN0BUF[1] = 0;
						EZUSB_SET_EP_BYTES(IN0BUF_ID,2);
						break;
					case GS_ENDPOINT:			// End Point
						IN0BUF[0] = EPIO[EPID(SETUPDAT[4])].cntrl & bmEPSTALL;
						IN0BUF[1] = 0;
						EZUSB_SET_EP_BYTES(IN0BUF_ID,2);
						break;
					default:				// Invalid Command
						EZUSB_STALL_EP0();		// Stall End Point 0
				}
			break;
		case SC_CLEAR_FEATURE:						// *** Clear Feature
			if(DR_ClearFeature())
				switch(SETUPDAT[0])
				{
					case FT_DEVICE:				// Device
						if(SETUPDAT[2] == 1)
							Rwuen = FALSE; 		// Disable Remote Wakeup
						else
							EZUSB_STALL_EP0();	// Stall End Point 0
						break;
					case FT_ENDPOINT:			// End Point
						if(SETUPDAT[2] == 0)
                  {
							EZUSB_UNSTALL_EP( EPID(SETUPDAT[4]) );
                     EZUSB_RESET_DATA_TOGGLE( SETUPDAT[4] );
                  }
						else
							EZUSB_STALL_EP0();	// Stall End Point 0
						break;
				}                                                     
			break;
		case SC_SET_FEATURE:						// *** Set Feature
			if(DR_SetFeature())
				switch(SETUPDAT[0])
				{
					case FT_DEVICE:				// Device
						if(SETUPDAT[2] == 1)
							Rwuen = TRUE;		// Enable Remote Wakeup
						else
							EZUSB_STALL_EP0();	// Stall End Point 0
						break;
					case FT_ENDPOINT:			// End Point
						if(SETUPDAT[2] == 0)
							EZUSB_STALL_EP( EPID(SETUPDAT[4]) );
						else
							EZUSB_STALL_EP0();	 // Stall End Point 0
						break;
				}
			break;
		default:							// *** Invalid Command
			if(DR_VendorCmnd())
				EZUSB_STALL_EP0();				// Stall End Point 0
	}

	// Acknowledge handshake phase of device request
	// Required for rev C does not effect rev B
	EP0CS |= bmBIT1;
}

// Wake-up interrupt handler
void resume_isr(void) interrupt WKUP_VECT
{
	EZUSB_CLEAR_RSMIRQ();
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产在线播放一区二区三区| 91精品国产综合久久精品| 欧美日韩久久不卡| 国产欧美精品日韩区二区麻豆天美| 亚洲综合色婷婷| 国产精一品亚洲二区在线视频| 欧美色倩网站大全免费| 中文字幕精品综合| 精品一区二区久久久| 欧美视频一区二区三区四区| 国产精品免费观看视频| 精品午夜一区二区三区在线观看| 91电影在线观看| 亚洲欧美日韩国产中文在线| 国产精品18久久久久久久网站| 91精品国产麻豆国产自产在线| 一区二区三区中文字幕在线观看| 不卡av在线网| 国产午夜精品理论片a级大结局| 日韩国产精品91| 欧美日韩一区二区电影| 亚洲欧美日韩一区二区三区在线观看| 国产成人午夜精品影院观看视频| 精品国产一区二区国模嫣然| 免费在线观看一区| 欧美久久久久久久久中文字幕| 亚洲精品乱码久久久久久黑人 | 51精品视频一区二区三区| ...av二区三区久久精品| 成人免费视频免费观看| 国产三级欧美三级| 丁香婷婷综合激情五月色| 久久精品视频一区二区| 国产精品一级片| 欧美极品另类videosde| 成熟亚洲日本毛茸茸凸凹| 欧美国产精品中文字幕| 成人黄色一级视频| 亚洲欧美乱综合| 91福利在线看| 日韩成人精品在线观看| 欧美电影免费观看高清完整版在| 久久99国产精品久久99果冻传媒| 日韩一区二区中文字幕| 久久国产精品99久久人人澡| 日韩一级片网址| 在线免费视频一区二区| 欧美一区日韩一区| 久久久99久久| 国产精品久久久99| 美国十次综合导航| 色婷婷久久一区二区三区麻豆| 亚洲精品五月天| 在线观看av不卡| 美女性感视频久久| 日本一区二区久久| 色婷婷国产精品| 五月婷婷激情综合| 久久久久国产免费免费| 97精品视频在线观看自产线路二| 亚洲国产一二三| 欧美一级搡bbbb搡bbbb| 国产91丝袜在线播放0| 亚洲一区欧美一区| 26uuu色噜噜精品一区| 亚洲成a人片综合在线| 91国内精品野花午夜精品| 亚洲精品伦理在线| 精品欧美一区二区久久| 色综合天天性综合| 久久精品国产亚洲aⅴ| 椎名由奈av一区二区三区| 制服丝袜激情欧洲亚洲| 9人人澡人人爽人人精品| 天天操天天综合网| 日韩理论片在线| 欧美成人福利视频| 欧洲中文字幕精品| 成人晚上爱看视频| 男女激情视频一区| 亚洲一区二区三区激情| 久久久久亚洲蜜桃| 在线成人av影院| 99国产精品久久| 国产精品一二三四五| 日韩综合小视频| 自拍av一区二区三区| 久久久国际精品| 6080yy午夜一二三区久久| 色婷婷国产精品| 成人av一区二区三区| 精品中文字幕一区二区小辣椒| 亚洲国产美国国产综合一区二区| 国产人久久人人人人爽| 欧美变态tickling挠脚心| 欧美日韩大陆在线| 欧美最新大片在线看| 成人一道本在线| 国产精品18久久久久久久久久久久| 日韩精品亚洲一区| 亚洲国产日韩综合久久精品| 自拍偷拍欧美精品| 国产精品网站一区| 日本一区二区三级电影在线观看| 欧美一区二区三区日韩视频| 欧美伊人精品成人久久综合97 | 成人视屏免费看| 狠狠久久亚洲欧美| 蓝色福利精品导航| 久久国产日韩欧美精品| 免费欧美在线视频| 美女看a上一区| 麻豆国产91在线播放| 日韩精品1区2区3区| 日本不卡视频在线观看| 免费成人小视频| 美美哒免费高清在线观看视频一区二区| 午夜久久久久久久久| 偷拍与自拍一区| 人人狠狠综合久久亚洲| 青青草91视频| 国产乱码精品一区二区三| 国产精品亚洲专一区二区三区| 国产在线精品国自产拍免费| 国产精品性做久久久久久| 国产99精品国产| 本田岬高潮一区二区三区| 一本一道波多野结衣一区二区| 色综合天天视频在线观看| 精品视频一区二区三区免费| 欧美午夜不卡在线观看免费| 欧美精品丝袜久久久中文字幕| 91精品国产综合久久精品| 精品久久久久久无| 国产午夜精品久久久久久免费视| 国产清纯美女被跳蛋高潮一区二区久久w| 亚洲国产成人午夜在线一区| 亚洲人成在线观看一区二区| 亚洲一区二区三区爽爽爽爽爽| 日本午夜精品一区二区三区电影| 日本少妇一区二区| 福利一区二区在线| 欧美色视频一区| 久久免费精品国产久精品久久久久| 中文成人综合网| 亚洲午夜免费电影| 国内精品久久久久影院色| 99精品热视频| 日韩一区二区三区在线视频| 国产清纯白嫩初高生在线观看91 | 国产99久久久国产精品潘金| 国产a久久麻豆| 欧美在线三级电影| 精品国产欧美一区二区| 国产精品蜜臀在线观看| 亚洲成人av一区二区三区| 国产精品自拍在线| 日本久久精品电影| 26uuu国产一区二区三区| 亚洲欧美日韩国产中文在线| 久久精品国产精品亚洲综合| 97se亚洲国产综合自在线不卡| 欧美精品日韩综合在线| 国产日韩v精品一区二区| 五月激情丁香一区二区三区| 不卡区在线中文字幕| 欧美一卡2卡3卡4卡| 亚洲欧美日韩在线| 国产精品一区一区| 欧美精品久久一区| ㊣最新国产の精品bt伙计久久| 蜜臀精品久久久久久蜜臀| 91网站在线观看视频| 精品美女被调教视频大全网站| 亚洲精品国产无天堂网2021| 国产精品123区| 日韩视频一区二区三区| 一区二区三区在线高清| 粉嫩久久99精品久久久久久夜| 欧美一区二区在线免费播放 | www国产亚洲精品久久麻豆| 亚洲精品高清在线| 成人h动漫精品一区二| 欧美精品一区二区三| 性感美女极品91精品| 日本韩国一区二区三区| 亚洲人亚洲人成电影网站色| 国产精品一二三四区| 精品少妇一区二区| 免费成人美女在线观看.| 欧美视频日韩视频| 亚洲电影一级黄| 欧美性受xxxx黑人xyx性爽| 亚洲视频一二三区| 91在线视频观看| 综合在线观看色| 91亚洲精华国产精华精华液| 国产精品久久久久永久免费观看| 国产高清成人在线| 亚洲国产高清在线|