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

📄 fwhid.lst

📁 soome examples of I2C transfer
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.14  FWHID                                                                  04/03/2003 11:25:17 PAGE 1   


C51 COMPILER V6.14, COMPILATION OF MODULE FWHID
OBJECT MODULE PLACED IN .\FWHID.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\USB_I2CI\FWHID.C DEBUG OBJECTEXTEND PRINT(.\FWHID.lst) OBJECT(.\FWHID.ob
                    -j) 

stmt level    source

   1          #include "ezusb.h"
   2          #include "ezregs.h"
   3          //-----------------------------------------------------------------------------
   4          // Random Macros
   5          //-----------------------------------------------------------------------------
   6          #define	min(a,b) (((a)<(b))?(a):(b))
   7          #define	max(a,b) (((a)>(b))?(a):(b))
   8          //-----------------------------------------------------------------------------
   9          // Constants
  10          //-----------------------------------------------------------------------------
  11          #define	DELAY_COUNT				0x9248*8L		// Delay for 8 sec at 24Mhz, 4 sec at 48
  12          //-----------------------------------------------------------------------------
  13          // Global Variables
  14          //-----------------------------------------------------------------------------
  15          volatile BOOL	GotSUD;
  16          BOOL		Rwuen;
  17          BOOL		Selfpwr;
  18          volatile BOOL	Sleep;						// Sleep mode enable flag
  19          
  20          WORD	pDeviceDscr;	// Pointer to Device Descriptor; Descriptors may be moved
  21          WORD	pConfigDscr;	
  22          WORD	pStringDscr;
  23          
  24          
  25          WORD	pReportDscr;
  26          BYTE	reportlen;
  27          
  28          
  29          //-----------------------------------------------------------------------------
  30          // Prototypes
  31          //-----------------------------------------------------------------------------
  32          void SetupCommand(void);
  33          void TD_Init(void);
  34          void TD_Poll(void);
  35          BOOL TD_Suspend(void);
  36          BOOL TD_Resume(void);
  37          
  38          BOOL DR_GetDescriptor(void);
  39          BOOL DR_SetConfiguration(void);
  40          BOOL DR_GetConfiguration(void);
  41          BOOL DR_SetInterface(void);
  42          BOOL DR_GetInterface(void);
  43          BOOL DR_GetStatus(void);
  44          BOOL DR_ClearFeature(void);
  45          BOOL DR_SetFeature(void);
  46          BOOL DR_VendorCmnd(void);
  47          
  48          //-----------------------------------------------------------------------------
  49          // Code
  50          //-----------------------------------------------------------------------------
  51          
  52          // Task dispatcher
  53          void main(void)
  54          {
C51 COMPILER V6.14  FWHID                                                                  04/03/2003 11:25:17 PAGE 2   

  55   1      	DWORD	i;
  56   1      	WORD	offset;
  57   1      	DWORD	DevDescrLen;
  58   1      	DWORD	j=0;
  59   1      	WORD	IntDescrAddr;
  60   1      	WORD	ExtDescrAddr;
  61   1      
  62   1      	// Initialize Global States
  63   1      	Sleep = FALSE;					// Disable sleep mode
  64   1      	Rwuen = FALSE;					// Disable remote wakeup
  65   1      	Selfpwr = FALSE;				// Disable self powered
  66   1      	GotSUD = FALSE;					// Clear "Got setup data" flag
  67   1      
  68   1      	// Initialize user device
  69   1      	TD_Init();
  70   1      
  71   1      	// The following section of code is used to relocate the descriptor table. 
  72   1      	// Since the SUDPTRH and SUDPTRL are assigned the address of the descriptor 
  73   1      	// table, the descriptor table must be located in on-part memory.
  74   1      	// The 4K demo tools locate all code sections in external memory.
  75   1      	// The descriptor table is relocated by the frameworks ONLY if it is found 
  76   1      	// to be located in external memory.
  77   1      	pDeviceDscr = (WORD)&DeviceDscr;
  78   1      	pConfigDscr = (WORD)&ConfigDscr;
  79   1      	pStringDscr = (WORD)&StringDscr;
  80   1      // HID code start
  81   1      	pReportDscr = (WORD)&ReportDscr;
  82   1      // HID code end
  83   1      
  84   1      	if ((WORD)&DeviceDscr & 0xe000)
  85   1      	{
  86   2      		IntDescrAddr = INTERNAL_DSCR_ADDR;
  87   2      		ExtDescrAddr = (WORD)&DeviceDscr;
  88   2      		DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
  89   2      		for (i = 0; i < DevDescrLen; i++)
  90   2      			*((BYTE xdata *)IntDescrAddr+i) = 0xCD;
  91   2      		for (i = 0; i < DevDescrLen; i++)
  92   2      			*((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
  93   2      		pDeviceDscr = IntDescrAddr;
  94   2      		offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
  95   2      		pConfigDscr -= offset;
  96   2      		pStringDscr -= offset;
  97   2      // HID code start
  98   2      		pReportDscr -= offset;
  99   2      // HID code end
 100   2      	}
 101   1      
 102   1      	EZUSB_IRQ_ENABLE();				// Enable USB interrupt (INT2)
 103   1      	EZUSB_ENABLE_RSMIRQ();				// Wake-up interrupt
 104   1      
 105   1      	// The 8051 is responsible for all USB events, even those that have happened
 106   1      	// before this point.  We cannot ignore pending USB interrupts.
 107   1      	// The chip will come out of reset with the flags all cleared.
 108   1      	//	USBIRQ = 0xff;				// Clear any pending USB interrupt requests
 109   1      	PORTCCFG |= 0xc0;				// Turn on r/w lines for external memory 
 110   1      
 111   1      	USBBAV = USBBAV | 1 & ~bmBREAK;	// Disable breakpoints and autovectoring
 112   1      	USBIEN |= bmSUDAV | bmSUTOK | bmSUSP | bmURES;	// Enable selected interrupts
 113   1      	EA = 1;						// Enable 8051 interrupts
 114   1      
 115   1      	// This loop waits until we receive a setup packet from the host.
 116   1      	// NOTE: The device will continue to renumerate until it receives a setup
C51 COMPILER V6.14  FWHID                                                                  04/03/2003 11:25:17 PAGE 3   

 117   1      	// packet.  This fixes a microsoft USB bug that loses disconnect/reconnect 
 118   1      	// events during initial USB device driver configuration dialog box.
 119   1      	// B2 Load:  This code is not needed for B2 load, only for renumeration.
 120   1      	#ifndef NO_RENUM
 121   1      		while(!GotSUD)
 122   1      		{
 123   2      			if(!GotSUD)
 124   2      				EZUSB_Discon(TRUE);	// renumerate until setup received
 125   2      			for(j=0;(j<DELAY_COUNT) && (!GotSUD);++j);
 126   2      		}
 127   1      	#endif
 128   1      
 129   1      
 130   1      	CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
 131   1      
 132   1      	// Task Dispatcher
 133   1      	while(TRUE)					// Main Loop
 134   1      	{
 135   2      		if(GotSUD)				// Wait for SUDAV
 136   2      		{
 137   3      			SetupCommand();	 		// Implement setup command
 138   3        			GotSUD = FALSE;		   	// Clear SUDAV flag
 139   3      		}
 140   2      
 141   2      		// Poll User Device
 142   2      		// NOTE: Idle mode stops the processor clock.  There are only two
 143   2      		// ways out of idle mode, the WAKEUP pin, and detection of the USB
 144   2      		// resume state on the USB bus.  The timers will stop and the
 145   2      		// processor will not wake up on any other interrupts.
 146   2      		if (Sleep)
 147   2      		    {
 148   3          		if(TD_Suspend())
 149   3          		    { 
 150   4          		    Sleep = FALSE;	   		// Clear the "go to sleep" flag.  Do it here to prevent any race condition b
             -etween wakeup and the next sleep.
 151   4          		    do
 152   4          		        {
 153   5             			    EZUSB_Susp();			// Place processor in idle mode.
 154   5          		        }
 155   4                      while(!Rwuen && EZUSB_EXTWAKEUP());
 156   4                      // Must continue to go back into suspend if the host has disabled remote wakeup
 157   4                      // *and* the wakeup was caused by the external wakeup pin.
 158   4                      
 159   4          			// 8051 activity will resume here due to USB bus or Wakeup# pin activity.
 160   4          			EZUSB_Resume();	// If source is the Wakeup# pin, signal the host to Resume.		
 161   4          			TD_Resume();
 162   4          		    }   
 163   3      		    }
 164   2      		TD_Poll();
 165   2      	}
 166   1      }
 167          
 168          // Device request parser
 169          void SetupCommand(void)
 170          // A Setup packet has been received.
 171          {
 172   1      	//*dscr_ptr is the address of a descriptor??	
 173   1      	void	*dscr_ptr;
 174   1      	DWORD	i;
 175   1      
 176   1      	switch(SETUPDAT[1])
 177   1      	//SETUPDAT[1] contains the control request
C51 COMPILER V6.14  FWHID                                                                  04/03/2003 11:25:17 PAGE 4   

 178   1      	{
 179   2      		case SC_GET_DESCRIPTOR:						// *** Get Descriptor
 180   2      			if(DR_GetDescriptor())
 181   2      			//If the request is Get_Descriptor, find out which descriptor was requested.
 182   2      				switch(SETUPDAT[3])
 183   2      				//The descriptor type is in the high byte of wValue, stored in SETUPDAT[3].			
 184   2      				{
 185   3      					case GD_DEVICE:				// Device
 186   3      					//If the request is for a device descriptor, store the pointers
 187   3      					//in SUDPTRH and SUDPTRL and the hardware does the rest.
 188   3      						SUDPTRH = MSB(pDeviceDscr);
 189   3      						SUDPTRL = LSB(pDeviceDscr);
 190   3      						break;
 191   3      					case GD_CONFIGURATION:			// Configuration
 192   3      					/*If the request is for a configuration descriptor, find out if the
 193   3      					configuration is valid. The config. index is in the low byte of
 194   3      					wValue, stored in SETUPDAT[2].

⌨️ 快捷键说明

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