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

📄 f32x_usb_utilities.lst

📁 C8051F320 SOURCE CODE 内容有: * USB Bulk Driver Example * USB Bulk Firmware Example * Host Ap
💻 LST
📖 第 1 页 / 共 2 页
字号:
 191          {
 192   1         BYTE bReturnState = EP_IDLE;           // Endpoint state return value
 193   1      
 194   1         PIF_STATUS pIfStatus;                  // Pointer to interface status
 195   1                                                // structure
 196   1      
 197   1         // Store address of selected config desc
 198   1         gDeviceStatus.pConfig = &gDescriptorMap.bCfg1;
 199   1      
 200   1         // Confirm that this configuration descriptor matches the requested
 201   1         // configuration value
 202   1         if (gDeviceStatus.pConfig[cfg_bConfigurationValue] != SelectConfig)
 203   1         {
 204   2            bReturnState = EP_ERROR;
 205   2         }
 206   1      
 207   1         else
 208   1         {
 209   2            // Store number of interfaces for this configuration
 210   2            gDeviceStatus.bNumInterf = gDeviceStatus.pConfig[cfg_bNumInterfaces];
 211   2      
 212   2            // Store total number of interface descriptors for this configuration
 213   2            gDeviceStatus.bTotalInterfDsc = MAX_IF;
 214   2      
 215   2            // Get pointer to the interface status structure
 216   2            pIfStatus = (PIF_STATUS)&gDeviceStatus.IfStatus[0];
 217   2      
 218   2            // Build Interface status structure for Interface0
 219   2            pIfStatus->bIfNumber = 0;           // Set interface number
 220   2            pIfStatus->bCurrentAlt = 0;         // Select alternate number zero
 221   2            pIfStatus->bNumAlts = 0;            // No other alternates
 222   2      
 223   2            SetInterface(pIfStatus);            // Configure Interface0, Alternate0
 224   2      
 225   2            gDeviceStatus.bDevState = DEV_CONFIG;// Set device state to configured
 226   2            gDeviceStatus.bCurrentConfig = SelectConfig;// Store current config
 227   2         }
 228   1      
 229   1         return bReturnState;
 230   1      }
 231          
 232          //-----------------------------------------------------------------------------
 233          // SetInterface
 234          //-----------------------------------------------------------------------------
 235          //
 236          // Return Value : None
 237          // Parameters   : 
 238          // 1) PIF_STATUS pIfStatus
 239          //
 240          //-----------------------------------------------------------------------------
 241          BYTE SetInterface(PIF_STATUS pIfStatus)
C51 COMPILER V7.06   F32X_USB_UTILITIES                                                    07/16/2008 15:35:22 PAGE 5   

 242          {
 243   1         BYTE bReturnState = EP_IDLE;
 244   1         BYTE bIndex;
 245   1      
 246   1         // Save current INDEX value
 247   1         UREAD_BYTE (INDEX, bIndex);
 248   1      
 249   1         // Add actions for each possible interface alternate selections
 250   1         switch(pIfStatus->bIfNumber)
 251   1         {
 252   2            // Configure endpoints for interface0
 253   2            case 0:
 254   2               // Configure Endpoint1 IN
 255   2               UWRITE_BYTE(INDEX, 1);           // Index to Endpoint1 registers
 256   2      
 257   2               // direction = IN ; Double-buffering enabled
 258   2               UWRITE_BYTE(EINCSRH, (rbInDIRSEL | rbInDBIEN));      
 259   2               gEp1InStatus.uNumBytes = 0;      // Reset byte counter
 260   2               gEp1InStatus.uMaxP = EP1_IN_MAXP;// Set maximum packet size
 261   2               gEp1InStatus.bEp = EP1_IN;       // Set endpoint address
 262   2               gEp1InStatus.bEpState = EP_IDLE; // Set endpoint state
 263   2      
 264   2               // Endpoint2 OUT
 265   2               UWRITE_BYTE(INDEX, 2);           // Index to Endpoint2 registers
 266   2               // Double-buffering enabled ; direction = OUT
 267   2               UWRITE_BYTE(EOUTCSRH, rbOutDBOEN);      
 268   2               gEp2OutStatus.uNumBytes = 0;     // Reset byte counter
 269   2               gEp2OutStatus.uMaxP = EP2_OUT_MAXP;// Set maximum packet size
 270   2               gEp2OutStatus.bEp = EP2_OUT;     // Set endpoint number
 271   2               gEp2OutStatus.bEpState = EP_IDLE;// Set endpoint state
 272   2      
 273   2               UWRITE_BYTE(INDEX, 0);           // Return to index 0
 274   2      
 275   2               break;
 276   2      
 277   2            // Configure endpoints for interface1
 278   2            case 1:
 279   2      
 280   2            // Configure endpoints for interface2
 281   2            case 2:
 282   2      
 283   2            // Default (error)
 284   2            default:
 285   2               bReturnState = EP_ERROR;
 286   2         }
 287   1         UWRITE_BYTE (INDEX, bIndex);           // Restore INDEX
 288   1      
 289   1         return bReturnState;
 290   1      }
 291          
 292          //-----------------------------------------------------------------------------
 293          // SetInterface
 294          //-----------------------------------------------------------------------------
 295          //
 296          // Return Value : None
 297          // Parameters   : 
 298          // 1) BYTE bEp
 299          // 2) UINT uNumBytes
 300          // 3) BYTE * pData
 301          //
 302          // Read from the selected endpoint FIFO
 303          //
C51 COMPILER V7.06   F32X_USB_UTILITIES                                                    07/16/2008 15:35:22 PAGE 6   

 304          //-----------------------------------------------------------------------------
 305          void FIFORead (BYTE bEp, UINT uNumBytes, BYTE * pData)
 306          {
 307   1         BYTE TargetReg;
 308   1         UINT i;
 309   1      
 310   1         // If >0 bytes requested,
 311   1         if (uNumBytes)
 312   1         {
 313   2            TargetReg = FIFO_EP0 + bEp;         // Find address for target
 314   2                                                // endpoint FIFO
 315   2      
 316   2            USB0ADR = (TargetReg & 0x3F);       // Set address (mask out bits7-6)
 317   2            USB0ADR |= 0xC0;                    // Set auto-read and initiate
 318   2                                                // first read
 319   2      
 320   2            // Unload <NumBytes> from the selected FIFO
 321   2            for(i=0;i<uNumBytes-1;i++)
 322   2            {
 323   3               while(USB0ADR & 0x80);           // Wait for BUSY->'0' (data ready)
 324   3               pData[i] = USB0DAT;              // Copy data byte
 325   3            }
 326   2      
 327   2      
 328   2            while(USB0ADR & 0x80);              // Wait for BUSY->'0' (data ready)
 329   2            pData[i] = USB0DAT;                 // Copy data byte
 330   2            USB0ADR = 0;                        // Clear auto-read
 331   2         }
 332   1      }
 333          
 334          //-----------------------------------------------------------------------------
 335          // FIFOWrite
 336          //-----------------------------------------------------------------------------
 337          //
 338          // Return Value : None
 339          // Parameters   : 
 340          // 1) BYTE bEp
 341          // 2) UINT uNumBytes
 342          // 3) BYTE * pData
 343          //
 344          // Write to the selected endpoint FIFO
 345          //
 346          //-----------------------------------------------------------------------------
 347          void FIFOWrite (BYTE bEp, UINT uNumBytes, BYTE * pData)
 348          {
 349   1         BYTE TargetReg;
 350   1         UINT i;
 351   1      
 352   1         // If >0 bytes requested,
 353   1         if (uNumBytes)
 354   1         {
 355   2            TargetReg = FIFO_EP0 + bEp;         // Find address for target
 356   2                                                // endpoint FIFO
 357   2      
 358   2            while(USB0ADR & 0x80);              // Wait for BUSY->'0'
 359   2                                                // (register available)
 360   2            USB0ADR = (TargetReg & 0x3F);       // Set address (mask out bits7-6)
 361   2      
 362   2            // Write <NumBytes> to the selected FIFO
 363   2            for(i=0;i<uNumBytes;i++)
 364   2            {
 365   3               USB0DAT = pData[i];
C51 COMPILER V7.06   F32X_USB_UTILITIES                                                    07/16/2008 15:35:22 PAGE 7   

 366   3               while(USB0ADR & 0x80);           // Wait for BUSY->'0' (data ready)
 367   3            }
 368   2         }
 369   1      }
 370          
 371          //-----------------------------------------------------------------------------
 372          // End Of File
 373          //-----------------------------------------------------------------------------


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    566    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      12
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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