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

📄 periph.lst

📁 一个不错的usb加密卡的设计
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.10  PERIPH                                                                 11/29/2002 10:53:59 PAGE 1   


C51 COMPILER V6.10, COMPILATION OF MODULE PERIPH
OBJECT MODULE PLACED IN .\PERIPH.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\PERIPH.C OPTIMIZE(6,SPEED) DEBUG OBJECTEXTEND

stmt level    source

   1          #pragma NOIV					// Do not generate interrupt vectors
   2          //-----------------------------------------------------------------------------
   3          //	File:		periph.c
   4          //	Contents:	Hooks required to implement USB peripheral function.
   5          //
   6          //	Copyright (c) 1997 AnchorChips, Inc. All rights reserved
   7          //-----------------------------------------------------------------------------
   8          #include <ezusb.h>
   9          #include <ezregs.h>
  10          
  11          extern BOOL	GotSUD;			// Received setup data flag
  12          extern BOOL	Sleep;
  13          extern BOOL	Rwuen;
  14          extern BOOL	Selfpwr;
  15          
  16          BYTE	Configuration;		// Current configuration
  17          BYTE	AlternateSetting;	// Alternate settings
  18          BYTE  suspCount;
  19          //-----------------------------------------------------------------------------
  20          // Task Dispatcher hooks
  21          //	The following hooks are called by the task dispatcher.
  22          //-----------------------------------------------------------------------------
  23          
  24          void TD_Init(void) 				// Called once at startup
  25          {
  26   1      	// Enable endpoints 0-7 IN and OUT
  27   1      	IN07VAL |= bmEP1 + bmEP2 + bmEP3 + bmEP4 + bmEP5 + bmEP6 + bmEP7;
  28   1      	//IN07VAL |= bmEP1;
  29   1      	OUT07VAL |= bmEP1 + bmEP2 + bmEP3 + bmEP4 + bmEP5 + bmEP6 + bmEP7;
  30   1      //	OUT07VAL |= bmEP1;
  31   1      
  32   1         // Enable interrupts for the OUT endpoints
  33   1         OUT07IEN |= bmEP1 + bmEP2 + bmEP3 + bmEP4 + bmEP5 + bmEP6 + bmEP7;
  34   1        //  OUT07IEN |= bmEP1;
  35   1      
  36   1         suspCount = 1;
  37   1      
  38   1         OEA = 0xFF;
  39   1      
  40   1         Rwuen = TRUE;				// Enable remote-wakeup
  41   1      }
  42          
  43          void TD_Poll(void) 				// Called repeatedly while the device is idle
  44          {
  45   1      }
  46          
  47          BOOL TD_Suspend(void) 			// Called before the device goes into suspend mode
  48          {
  49   1      	return(TRUE);
  50   1      }
  51          
  52          BOOL TD_Resume(void) 			// Called after the device resumes
  53          {
  54   1      	return(TRUE);
  55   1      }
C51 COMPILER V6.10  PERIPH                                                                 11/29/2002 10:53:59 PAGE 2   

  56          
  57          //-----------------------------------------------------------------------------
  58          // Device Request hooks
  59          //	The following hooks are called by the end point 0 device request parser.
  60          //-----------------------------------------------------------------------------
  61          
  62          BOOL DR_GetDescriptor(void)
  63          {
  64   1      	return(TRUE);
  65   1      }
  66          
  67          BOOL DR_SetConfiguration(void)	// Called when a Set Configuration command is received
  68          {
  69   1      	Configuration = SETUPDAT[2];
  70   1      	return(TRUE);				// Handled by user code
  71   1      }
  72          
  73          BOOL DR_GetConfiguration(void)	// Called when a Get Configuration command is received
  74          {
  75   1      	IN0BUF[0] = Configuration;
  76   1      	EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
  77   1      	return(TRUE);				// Handled by user code
  78   1      }
  79          
  80          BOOL DR_SetInterface(void) 		// Called when a Set Interface command is received
  81          {
  82   1      	AlternateSetting = SETUPDAT[2];
  83   1      	return(TRUE);				// Handled by user code
  84   1      }
  85          
  86          BOOL DR_GetInterface(void) 		// Called when a Set Interface command is received
  87          {
  88   1      	IN0BUF[0] = AlternateSetting;
  89   1      	EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
  90   1      	return(TRUE);				// Handled by user code
  91   1      }
  92          
  93          BOOL DR_GetStatus(void)
  94          {
  95   1      	return(TRUE);
  96   1      }
  97          
  98          BOOL DR_ClearFeature(void)
  99          {
 100   1      	return(TRUE);
 101   1      }
 102          
 103          BOOL DR_SetFeature(void)
 104          {
 105   1      	return(TRUE);
 106   1      }
 107          
 108          #define EZUSB_UNARM_EP(ep_id)  			EPIO[ep_id].cntrl = bmEPBUSY
 109          
 110          BOOL DR_VendorCmnd(void)
 111          {
 112   1         return(TRUE);
 113   1      }
 114          
 115          //-----------------------------------------------------------------------------
 116          // USB Interrupt Handlers
 117          //	The following functions are called by the USB interrupt jump table.
C51 COMPILER V6.10  PERIPH                                                                 11/29/2002 10:53:59 PAGE 3   

 118          //-----------------------------------------------------------------------------
 119          
 120          
 121          // Setup Data Available Interrupt Handler
 122          void ISR_Sudav(void) interrupt 0
 123          {
 124   1      	GotSUD = TRUE;				// Set flag
 125   1      
 126   1      
 127   1      	EZUSB_IRQ_CLEAR();
 128   1      	USBIRQ = bmSUDAV;			// Clear SUDAV IRQ
 129   1      }
 130          
 131          // Setup Token Interrupt Handler
 132          void ISR_Sutok(void) interrupt 0
 133          {
 134   1      	EZUSB_IRQ_CLEAR();
 135   1      	USBIRQ = bmSUTOK;			// Clear SUTOK IRQ
 136   1      }
 137          
 138          void ISR_Sof(void) interrupt 0
 139          {
 140   1      	EZUSB_IRQ_CLEAR();
 141   1      	USBIRQ = bmSOF;				// Clear SOF IRQ
 142   1      }
 143          
 144          void ISR_Ures(void) interrupt 0
 145          {
 146   1         //
 147   1         // Arm all of the OUT endpoints so they can accept data
 148   1         //
 149   1         EPIO[OUT1BUF_ID].bytes = 0;
 150   1         EPIO[OUT2BUF_ID].bytes = 0;
 151   1         EPIO[OUT3BUF_ID].bytes = 0;
 152   1         EPIO[OUT4BUF_ID].bytes = 0;
 153   1         EPIO[OUT5BUF_ID].bytes = 0;
 154   1         EPIO[OUT6BUF_ID].bytes = 0;
 155   1         EPIO[OUT7BUF_ID].bytes = 0;
 156   1      
 157   1      	EZUSB_IRQ_CLEAR();
 158   1      	USBIRQ = bmURES;			// Clear URES IRQ
 159   1      }
 160          
 161          void ISR_IBN(void) interrupt 0
 162          {
 163   1         // ISR for the IN Bulk NAK (IBN) interrupt.
 164   1      }
 165          
 166          void ISR_Susp(void) interrupt 0
 167          {
 168   1         Sleep = TRUE;
 169   1      
 170   1         EZUSB_IRQ_CLEAR();
 171   1         USBIRQ = bmSUSP;
 172   1      }
 173          
 174          void ISR_Ep0in(void) interrupt 0
 175          {
 176   1      }
 177          
 178          void ISR_Ep0out(void) interrupt 0
 179          {
C51 COMPILER V6.10  PERIPH                                                                 11/29/2002 10:53:59 PAGE 4   

 180   1      }
 181          
 182          void ISR_Ep1in(void) interrupt 0
 183          {
 184   1      }
 185          
 186          void ISR_Ep1out(void) interrupt 0
 187          {
 188   1         int i;
 189   1      
 190   1         //
 191   1         // workaround to cover the case where the host thinks the
 192   1         // previous IN completed but EZ-USB didn't receive a valid
 193   1         // handshake (i.e. the ACK was scrambled).  If we have
 194   1         // received new OUT data (which we have, because we're in this
 195   1         // ISR) but the corresponding IN endpoint is still busy, then
 196   1         // we know we missed the handshake.  The solution is to flip
 197   1         // the data toggle and proceed with the new data.
 198   1         //
 199   1         // NOTE: This workaround is specific to this particular loopback
 200   1         // application and should not be included in normal endpoint handling
 201   1         // firmware.
 202   1         //
 203   1         if (EPIO[IN1BUF_ID].cntrl & bmEPBUSY)
 204   1         {
 205   2            TOGCTL = 0x08 | IN1BUF_ID;
 206   2            WRITEDELAY();
 207   2            if (TOGCTL & 0x80)
 208   2               TOGCTL |= 0x20;
 209   2            else
 210   2               TOGCTL |= 0x40;
 211   2         }
 212   1      
 213   1         // Loop the data to the IN endpoint
 214   1         for (i=0; i < OUT1BC; i++)
 215   1         {
 216   2            IN1BUF[i] = OUT1BUF[i];
 217   2      	 
 218   2         }
 219   1      
 220   1         // Arm the IN endpoint
 221   1          IN1BC = OUT1BC;
 222   1         
 223   1      
 224   1         // Arm the OUT so it can receive the next packet
 225   1         OUT1BC = 0;
 226   1      
 227   1      
 228   1         // clear the IRQ

⌨️ 快捷键说明

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