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

📄 f34x_usb_standard_requests.lst

📁 学习usb编程很好的例子 自己学习用的。
💻 LST
📖 第 1 页 / 共 3 页
字号:
 198          //-----------------------------------------------------------------------------
 199          // Clear_Feature
 200          //-----------------------------------------------------------------------------
 201          //
 202          // Return Value : None
 203          // Parameters   : None
 204          //
 205          // This routine can clear Halt Endpoint features on endpoint 1 and 2.
 206          //
 207          //-----------------------------------------------------------------------------
 208          
 209          void Clear_Feature()                            
 210          {                                               
 211   1      
 212   1         if ((USB_State != DEV_CONFIGURED)          ||// Send procedural stall if device isn't configured
 213   1         (Setup.bmRequestType == IN_DEVICE)         ||// or request is made to host(remote wakeup not supported)
 214   1         (Setup.bmRequestType == IN_INTERFACE)      ||// or request is made to interface
 215   1         Setup.wValue.c[MSB]  || Setup.wIndex.c[MSB]||// or msbs of value or index set to non-zero value
 216   1         Setup.wLength.c[MSB] || Setup.wLength.c[LSB])// or data length set to non-zero.
 217   1         {
 218   2            Force_Stall();
 219   2         }
 220   1      
 221   1         else
 222   1         {
 223   2            if ((Setup.bmRequestType == IN_ENDPOINT)&&// Verify that packet was directed at an endpoint
 224   2            (Setup.wValue.c[LSB] == ENDPOINT_HALT)  &&// the feature selected was HALT_ENDPOINT
 225   2            ((Setup.wIndex.c[LSB] == IN_EP1) ||       // and that the request was directed at EP 1 in
 226   2            (Setup.wIndex.c[LSB] == OUT_EP2)))        // or EP 2 out
 227   2            {
 228   3               if (Setup.wIndex.c[LSB] == IN_EP1)
 229   3               {
 230   4                  POLL_WRITE_BYTE (INDEX, 1);         // Clear feature endpoint 1 halt
 231   4                  POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);
 232   4                  Ep_Status[1] = EP_IDLE;             // Set endpoint 1 status back to idle
 233   4               }
 234   3               else
 235   3               {
 236   4                  POLL_WRITE_BYTE (INDEX, 2);         // Clear feature endpoint 2 halt
 237   4                  POLL_WRITE_BYTE (EOUTCSR1, rbOutCLRDT);
 238   4                  Ep_Status[2] = EP_IDLE;             // Set endpoint 2 status back to idle
 239   4               }
 240   3            }
 241   2            else
C51 COMPILER V7.50   F34X_USB_STANDARD_REQUESTS                                            08/01/2007 13:13:23 PAGE 5   

 242   2            {
 243   3               Force_Stall();                         // Send procedural stall
 244   3            }
 245   2         }
 246   1         POLL_WRITE_BYTE(INDEX, 0);                   // Reset Index to 0
 247   1         if (Ep_Status[0] != EP_STALL)
 248   1         {
 249   2            // Indicate setup packet has been serviced
 250   2            POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
 251   2         }
 252   1      }
 253          
 254          //-----------------------------------------------------------------------------
 255          // Set_Feature
 256          //-----------------------------------------------------------------------------
 257          //
 258          // Return Value : None
 259          // Parameters   : None
 260          //
 261          // This routine will set the EP Halt feature for endpoints 1 and 2
 262          //
 263          //-----------------------------------------------------------------------------
 264          
 265          void Set_Feature(void)                          
 266          {                                             
 267   1      
 268   1         if ((USB_State != DEV_CONFIGURED)          ||// Make sure device is configured, setup data
 269   1         (Setup.bmRequestType == IN_DEVICE)         ||// is all valid and that request is directed at
 270   1         (Setup.bmRequestType == IN_INTERFACE)      ||// an endpoint
 271   1         Setup.wValue.c[MSB]  || Setup.wIndex.c[MSB]||
 272   1         Setup.wLength.c[MSB] || Setup.wLength.c[LSB])
 273   1         {
 274   2            Force_Stall();                            // Otherwise send stall to host
 275   2         }
 276   1      
 277   1         else
 278   1         {
 279   2            if ((Setup.bmRequestType == IN_ENDPOINT)&&// Make sure endpoint exists and that halt
 280   2            (Setup.wValue.c[LSB] == ENDPOINT_HALT)  &&// endpoint feature is selected
 281   2            ((Setup.wIndex.c[LSB] == IN_EP1)        ||
 282   2            (Setup.wIndex.c[LSB] == OUT_EP2)))
 283   2            {
 284   3               if (Setup.wIndex.c[LSB] == IN_EP1)
 285   3               {
 286   4                  POLL_WRITE_BYTE (INDEX, 1);         // Set feature endpoint 1 halt
 287   4                  POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
 288   4                  Ep_Status[1] = EP_HALT;
 289   4               }
 290   3               else
 291   3               {
 292   4                  POLL_WRITE_BYTE (INDEX, 2);         // Set feature Ep2 halt
 293   4                  POLL_WRITE_BYTE (EOUTCSR1, rbOutSDSTL);
 294   4                  Ep_Status[2] = EP_HALT;
 295   4               }
 296   3            }
 297   2            else
 298   2            {
 299   3               Force_Stall();                         // Send procedural stall
 300   3            }
 301   2         }
 302   1         POLL_WRITE_BYTE(INDEX, 0);
 303   1         if (Ep_Status[0] != EP_STALL)
C51 COMPILER V7.50   F34X_USB_STANDARD_REQUESTS                                            08/01/2007 13:13:23 PAGE 6   

 304   1         {
 305   2            // Indicate setup packet has been serviced
 306   2            POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
 307   2         }
 308   1      }
 309          
 310          //-----------------------------------------------------------------------------
 311          // Set_Address
 312          //-----------------------------------------------------------------------------
 313          //
 314          // Return Value : None
 315          // Parameters   : None
 316          //
 317          // Set new function address
 318          //
 319          //-----------------------------------------------------------------------------
 320          
 321          void Set_Address(void)                          
 322          {
 323   1         if ((Setup.bmRequestType != IN_DEVICE)     ||// Request must be directed to device
 324   1         Setup.wIndex.c[MSB]  || Setup.wIndex.c[LSB]||// with index and length set to zero.
 325   1         Setup.wLength.c[MSB] || Setup.wLength.c[LSB]||
 326   1         Setup.wValue.c[MSB]  || (Setup.wValue.c[LSB] & 0x80))
 327   1         {
 328   2           Force_Stall();                             // Send stall if setup data invalid
 329   2         }
 330   1      
 331   1         Ep_Status[0] = EP_ADDRESS;                   // Set endpoint zero to update address next status phase
 332   1         if (Setup.wValue.c[LSB] != 0)
 333   1         {
 334   2            USB_State = DEV_ADDRESS;                  // Indicate that device state is now address
 335   2         }
 336   1         else
 337   1         {
 338   2            USB_State = DEV_DEFAULT;                  // If new address was 0x00, return device to default
 339   2         }                                            // state
 340   1         if (Ep_Status[0] != EP_STALL)
 341   1         {
 342   2            // Indicate setup packet has been serviced
 343   2            POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
 344   2         }
 345   1      }
 346          
 347          //-----------------------------------------------------------------------------
 348          // Get_Descriptor
 349          //-----------------------------------------------------------------------------
 350          //
 351          // Return Value : None
 352          // Parameters   : None
 353          //
 354          // This routine sets the data pointer and size to correct 
 355          // descriptor and sets the endpoint status to transmit
 356          //
 357          //-----------------------------------------------------------------------------
 358          
 359          void Get_Descriptor(void)                       
 360          {                                              
 361   1      
 362   1         switch(Setup.wValue.c[MSB])                  // Determine which type of descriptor
 363   1         {                                            // was requested, and set data ptr and
 364   2            case DSC_DEVICE:                          // size accordingly
 365   2               DataPtr = (BYTE*) &DeviceDesc;
C51 COMPILER V7.50   F34X_USB_STANDARD_REQUESTS                                            08/01/2007 13:13:23 PAGE 7   

 366   2               DataSize = DeviceDesc.bLength;
 367   2               break;
 368   2      
 369   2            case DSC_CONFIG:
 370   2               DataPtr = (BYTE*) &ConfigDesc;
 371   2                                                      // Compiler Specific - The next statement reverses the
 372   2                                                      // bytes in the configuration descriptor for the compiler
 373   2               DataSize = ConfigDesc.wTotalLength.c[MSB] + 256*ConfigDesc.wTotalLength.c[LSB];
 374   2               break;
 375   2      
 376   2            case DSC_STRING:
 377   2               DataPtr = StringDescTable[Setup.wValue.c[LSB]];
 378   2                                                      // Can have a maximum of 255 strings
 379   2               DataSize = *DataPtr;
 380   2               break;
 381   2      
 382   2            case DSC_INTERFACE:
 383   2               DataPtr = (BYTE*) &InterfaceDesc;
 384   2               DataSize = InterfaceDesc.bLength;
 385   2               break;
 386   2      
 387   2            case DSC_ENDPOINT:
 388   2               if ((Setup.wValue.c[LSB] == IN_EP1) ||
 389   2               (Setup.wValue.c[LSB] == OUT_EP2))
 390   2               {
 391   3                  if (Setup.wValue.c[LSB] == IN_EP1)
 392   3                  {
 393   4                     DataPtr = (BYTE*) &Endpoint1Desc;
 394   4                     DataSize = Endpoint1Desc.bLength;
 395   4                  }
 396   3                  else
 397   3                  {
 398   4                     DataPtr = (BYTE*) &Endpoint2Desc;
 399   4                     DataSize = Endpoint2Desc.bLength;
 400   4                  }
 401   3               }
 402   2               else
 403   2               {

⌨️ 快捷键说明

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