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

📄 upsd_usb.lst

📁 ST公司的upsd34XX评估板固定源程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 261   5                pTransmitBufferEP0 = NULL;         // it will be sent the next cycle
 262   5               }
 263   4             }
 264   3            #pragma asm
 265   3                    orl    UCON0,#uTX0E                            ; enable transmit
 266   3            #pragma endasm
 267   3           }
 268   2          return TRUE;
 269   2         }
 270   1      
 271   1        #pragma asm                            // No data going out, so disable endpoint
 272   1                    anl    UCON0,#uRX0E                                        ;mask
 273   1                    orl    UCON0,#uTSEQ0                               ;set TSEQ bit
 274   1        #pragma endasm
 275   1      
 276   1        return FALSE;
 277   1       }
 278          
 279          
 280          
 281          
 282          
 283          
 284          
 285          
 286          void TransmitDataEP0(uchar* pData, int nBytes)
 287          /******************************************************************************
 288           Function   : void TransmitDataEP0()
 289           Parameters : (uchar* pData, int nBytes)
 290           Description: Load and arm EP0 to transmit data.
 291               This routine prepates 0..8 bytes of data at endpoint0 to be trasmitted.
 292               Caller must then clear FIFO status flag (uTXD0F) to arm the endpoint.
 293           ******************************************************************************/
 294           {
 295   1        data unsigned char xBytes;
 296   1      
 297   1        if (nBytes > EP0_SIZE) xBytes = EP0_SIZE; else xBytes = nBytes;
 298   1      
 299   1                             // Disable endpoint, set DATA0/1 sequence bit and FIFO size
 300   1        #pragma asm
 301   1                    xrl    UCON0,#uTSEQ0                            ;toggle TSEQ bit
 302   1                    anl    UCON0,#(uTSEQ0+uRX0E)
 303   1        #pragma endasm
C51 COMPILER V7.06   UPSD_USB                                                              10/15/2004 20:55:31 PAGE 6   

 304   1        UCON0 |=xBytes;                            // set FIFO size
 305   1      
 306   1        while (xBytes--)
 307   1         {
 308   2          UDT0 = *pData++;                         // Load data into FIFO
 309   2         }
 310   1        UCON0 |= uTX0E;                            // Enable endpoint
 311   1       }
 312          
 313          
 314          
 315          
 316          
 317          
 318          
 319          void TransmitDataEPx(int x, uchar* pData, int nBytes)
 320          /******************************************************************************
 321           Function   : void TransmitDataEPx()
 322           Parameters : (int x, uchar* pData, int nBytes)
 323           Description: Loads EP1 or EP2 transmit FIFO.
 324                        Caller must then clear FIFO status flag (uTXD1F) to arm endpoint.
 325           ******************************************************************************/
 326           {
 327   1      
 328   1        data unsigned char xBytes;
 329   1      
 330   1        if (nBytes > 8)  xBytes = 8; else xBytes = nBytes;
 331   1        // Disable endpoint, set DATA0/1 sequence bit, endpoint selection, and FIFO size
 332   1        UCON1 &= ~uEP12SEL;                        //mask
 333   1        UCON1 |= ((x == 2) ? uEP12SEL : 0);        //set endpoint
 334   1        UCON1 &= uTSEQ1+uEP12SEL;                  //mask
 335   1        UCON1 ^= uTSEQ1;                           //toggle DATAx bit
 336   1        UCON1 |= xBytes;                           //set FIFO size
 337   1        while (nBytes--)
 338   1         {
 339   2          UDT1 = *pData++;                         // Load data into FIFO
 340   2         }
 341   1        UCON1 |= uTX1E;                            // Enable endpoint
 342   1        UIEN  |= uTXD1IE;                          // enable INT
 343   1       }
 344          
 345          
 346          
 347          
 348          
 349          
 350          
 351          
 352          
 353          
 354          
 355          
 356          
 357          
 358          
 359          
 360          
 361          
 362          
 363          
 364          //the following function changed on April 30, 2004
 365          
C51 COMPILER V7.06   UPSD_USB                                                              10/15/2004 20:55:31 PAGE 7   

 366          static void OnGetStatus()
 367          /******************************************************************************
 368           Function   : static void OnGetStatus()
 369           Parameters : none
 370           Description: Handler for GET_STATUS control requests.
 371           ******************************************************************************/
 372           {
 373   1        #pragma asm                                // send zero length packet
 374   1                    orl    UCON0,#uTSEQ0                               ;set TSEQ bit
 375   1                    anl    UCON0,#uTSEQ0+uRX0E                   ;mask, keep RX flag
 376   1                    orl    UCON0,#2                                   ;set FIFO size
 377   1        #pragma endasm
 378   1        
 379   1        if((setupPacket.wIndex.lo == 0x00) & (setupPacket.wIndex.hi == 0x00)){//device
 380   2              UDT0 = 1;
 381   2              UDT0 = 0;
 382   2              }
 383   1        else if((setupPacket.wIndex.lo == 0x81) & (setupPacket.wIndex.hi == 0x00)){//endpoint1
 384   2              if(ep1State == US_EP1STALL)
 385   2                      UDT0 = 1;
 386   2              else
 387   2                      UDT0 = 0;
 388   2      
 389   2              UDT0 = 0;
 390   2              }
 391   1        else{ 
 392   2              STALL_EP0();                  // No features currently implemented, so stall EP0
 393   2              }
 394   1        #pragma asm
 395   1                    orl    UCON0,#uTX0E                             ;enable transmit
 396   1        #pragma endasm
 397   1       }
 398          
 399          
 400          
 401          
 402          
 403          
 404          //the following function changed on April 30, 2004
 405          
 406          static void OnClearFeature()
 407          /******************************************************************************
 408           Function   : static void OnClearFeature()
 409           Parameters : none
 410           Description: Handler for CLEAR_FEATURE control requests.
 411           ******************************************************************************/
 412           {
 413   1         if((setupPacket.wValue.lo == 0x00) & (setupPacket.wIndex.lo == 0x81)){
 414   2              ep1State = US_EP1DEFAULT;
 415   2              }
 416   1        else{ 
 417   2              STALL_EP0();                  // No features currently implemented, so stall EP0
 418   2              }
 419   1      
 420   1        #pragma asm                                // Send back 0 length DATA1 packet
 421   1                    anl    UCON0,#uRX0E+uSTALL0+uTSEQ0+uTX0E  ;mask, keep RX,TX flag
 422   1                    orl    UCON0,#uTSEQ0+uTX0E         ;set TSEQ bit+enable endpoint
 423   1        #pragma endasm
 424   1       }
 425          
 426          
 427          
C51 COMPILER V7.06   UPSD_USB                                                              10/15/2004 20:55:31 PAGE 8   

 428          //the following function changed on April 30, 2004
 429          
 430          static void OnSetFeature()
 431          /******************************************************************************
 432           Function   : static void OnSetFeature()
 433           Parameters : none
 434           Description: Handler for Set_FEATURE control requests.
 435           ******************************************************************************/
 436           {
 437   1        if((setupPacket.wValue.lo == 0x00) & (setupPacket.wIndex.lo == 0x81)){
 438   2              ep1State = US_EP1STALL;
 439   2              }
 440   1        else{ 
 441   2              STALL_EP0();                  // No features currently implemented, so stall EP0
 442   2              }
 443   1      
 444   1        #pragma asm                                // Send back 0 length DATA1 packet
 445   1                    anl    UCON0,#uRX0E+uSTALL0+uTSEQ0+uTX0E  ;mask, keep RX,TX flag
 446   1                    orl    UCON0,#uTSEQ0+uTX0E         ;set TSEQ bit+enable endpoint
 447   1        #pragma endasm
 448   1       }
 449          
 450          
 451          
 452          
 453          
 454          static void OnSetAddress()
 455          /******************************************************************************
 456           Function   : static void OnSetAddress()
 457           Parameters : none
 458           Description: Handler for SET_ADDRESS SETUP packets
 459           ******************************************************************************/
 460           {
 461   1        #pragma asm                                // Send back 0 length DATA1 packet
 462   1                    anl    UCON0,#uRX0E+uSTALL0+uTSEQ0+uTX0E  ;mask, keep RX,TX flag
 463   1                    orl    UCON0,#uTSEQ0+uTX0E         ;set TSEQ bit+enable endpoint
 464   1        #pragma endasm
 465   1       }
 466          
 467          
 468          
 469          
 470          static void OnGetConfiguration()
 471          /******************************************************************************
 472           Function   : static void OnGetConfiguration()
 473           Parameters : none
 474           Description: Handler for GET_CONFIGURATION SETUP requests.
 475           ******************************************************************************/
 476           {
 477   1        #pragma asm                                // send one byte length packet
 478   1                    orl    UCON0,#uTSEQ0                               ;set TSEQ bit
 479   1                    anl    UCON0,#uTSEQ0+uRX0E                   ;mask, keep RX flag
 480   1                    orl    UCON0,#1                                   ;set FIFO size
 481   1        #pragma endasm
 482   1      
 483   1        if (usbState == US_CONFIGURED)
 484   1         {
 485   2          UDT0 = 1;             //non-zero bConfigurationValue when device is configured
 486   2         }
 487   1        else
 488   1         {
 489   2          UDT0 = 0;                  //The value zero shall be returned in address state
C51 COMPILER V7.06   UPSD_USB                                                              10/15/2004 20:55:31 PAGE 9   

 490   2         }
 491   1        #pragma asm
 492   1                    orl    UCON0,#uTX0E                             ;enable transmit
 493   1        #pragma endasm
 494   1       }
 495          
 496          
 497          
 498          
 499          static void OnSetConfiguration()
 500          /******************************************************************************
 501           Function   : static void OnSetConfiguration()
 502           Parameters : none
 503           Description: Handler for SET_CONFIGURATION SETUP requests.
 504           ******************************************************************************/
 505           {
 506   1        if (setupPacket.wValue.lo == 0)
 507   1         {
 508   2          if (usbState == US_CONFIGURED )
 509   2           {
 510   3            #pragma asm                            // Send back 0 length DATA1 packet
 511   3                    anl    UCON0,#uRX0E                          ;mask, keep RX flag
 512   3                    orl    UCON0,#uTSEQ0+uTX0E         ;set TSEQ bit+enable endpoint
 513   3            #pragma endasm
 514   3           }
 515   2          usbState = US_ADDRESSED;
 516   2         }
 517   1        else
 518   1        if (setupPacket.wValue.lo == 1)
 519   1         {
 520   2          usbState = US_CONFIGURED;
 521   2      
 522   2          #pragma asm                              // Send back 0 length DATA1 packet
 523   2                    anl    UCON0,#uRX0E                          ;mask, keep RX flag
 524   2                    orl    UCON0,#uTSEQ0+uTX0E         ;set TSEQ bit+enable endpoint
 525   2          #pragma endasm
 526   2      
 527   2          OnDeviceConfigured();
 528   2         }
 529   1        else

⌨️ 快捷键说明

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