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

📄 usbisr.lst

📁 单片机和D12通讯的C程序.实现了单片机通过USB口和电脑通讯.
💻 LST
📖 第 1 页 / 共 3 页
字号:
 362   5                                              bDataLength = D12ReadBuffer(D12_SELECT_ENDPOINT_ENDPOINT2_OUT,sSysInformation.sRamControl.iRamRemaind
             -Length, pBuffer);
 363   5                                              if (bDataLength == D12_BUFFER_LENGTH_ERROR)
 364   5                                              {
 365   6                                                      //D12_BUFFER_LENGTH_ERROR shows received data length is longer than expected length,
 366   6                                                      //this is a serious error,so we stall control endpoint
 367   6                                                      sSysInformation.sRamControl.bRamRwStatus = IDLE;
 368   6                                                      //D12SetEndpointStatus(D12_SELECT_ENDPOINT_ENDPOINT2_OUT,D12_ENDPOINT_STALL);                   //set endpoint2-out 
             -stall                                
 369   6                                                      GENERIC_ENDPOINT_STALL(D12_SELECT_ENDPOINT_ENDPOINT2_OUT)
 370   6                                              }
 371   5                                              else
 372   5                                              {
 373   6                                                      //get remaind data length
 374   6                                                      sSysInformation.sRamControl.iRamRemaindLength -= bDataLength;
 375   6                                                      //If remaind data length is 0, current control-out transfer will be finished.
 376   6                                                      //We should return zero length data packet as status stage  of control-out transfer 
 377   6                                                      //to tell host that the current control-out transfer is completed. see 8.5.2.1
 378   6                                                      if (sSysInformation.sUsbSetUpDealwith.wRemaindLength<=0)
 379   6                                                      {
 380   7                                                              sSysInformation.sRamControl.bRamRwStatus = IDLE;
 381   7                                                      }
 382   6                                              }
 383   5                                      }
 384   4                                      //If we has already received all data,but host still issue an out token,it is an error.
 385   4                                      else
 386   4                                      {
 387   5                                              sSysInformation.sRamControl.bRamRwStatus = IDLE;
 388   5                                              //D12SetEndpointStatus(D12_SELECT_ENDPOINT_ENDPOINT2_OUT,D12_ENDPOINT_STALL);                   //set endpoint2-out s
             -tall                                
 389   5                                              GENERIC_ENDPOINT_STALL(D12_SELECT_ENDPOINT_ENDPOINT2_OUT)
 390   5                                      }
 391   4                              }
 392   3                      }
 393   2                      //If Host issued a RAM_COMMAND_READ command,but before complete this command,
 394   2                      //host issued another OUT token,it is an error,and we should stall endpoint2-out.
 395   2                      else
 396   2                      {
 397   3                              sSysInformation.sRamControl.bRamRwStatus = IDLE;
 398   3                              GENERIC_ENDPOINT_STALL(D12_SELECT_ENDPOINT_ENDPOINT2_OUT)
 399   3                              //D12SetEndpointStatus(D12_SELECT_ENDPOINT_ENDPOINT2_OUT,D12_ENDPOINT_STALL);                   //set endpoint2-out sta
             -ll                                
 400   3                      }
 401   2              }
 402   1      }
 403          
 404          //
 405          //*************************************************************************
 406          //      Paremeter:
 407          //              In : None
 408          //              Out: None
 409          //      Function:
 410          //              See Ep2Out notes.
 411          void Ep2In(void)                //endpoint2 IN transaction process
 412          {
 413   1              unsigned char data bLastTransactionStatus;
 414   1              unsigned char data i,j;
 415   1              unsigned char data bDataLength;
 416   1              unsigned char xdata * data pBuffer;
 417   1      
C51 COMPILER V7.01  USBISR                                                                 02/17/2006 15:09:24 PAGE 8   

 418   1              bLastTransactionStatus = D12ReadLastTransactionStatus(D12_SET_ENDPOINT_STATUS_ENDPOINT2_IN); 
 419   1      
 420   1              if (sSysInformation.sRamControl.bRamCommand != RAM_COMMAND_LOOPBACK)
 421   1              {
 422   2                       if (sSysInformation.sRamControl.bRamRwStatus == TRANSMIT)
 423   2                       {
 424   3                              for (j=0;j<2;j++)
 425   3                              {
 426   4                                      if (sSysInformation.sRamControl.iRamRemaindLength >0)
 427   4                                      {
 428   5                                              if (sSysInformation.sRamControl.iRamRemaindLength > D12_EP2_MAX_PACKET_SIZE)
 429   5                                              {
 430   6                                                      //if this time we can not transfer all remaind data to host,
 431   6                                                      //we still set TRANSMIT flag
 432   6                                                      sSysInformation.sRamControl.bRamRwStatus = TRANSMIT;
 433   6                                                      bDataLength = D12_EP2_MAX_PACKET_SIZE;
 434   6                                              }
 435   5                                              else
 436   5                                              {
 437   6                                                      //if this time we can transfer all remaind data to Host
 438   6                                                      //reset bRamRwStatus status to IDLE
 439   6                                                      sSysInformation.sRamControl.bRamRwStatus = IDLE;
 440   6                                                      bDataLength = (unsigned char)(sSysInformation.sRamControl.iRamRemaindLength);
 441   6                                              }
 442   5      
 443   5                                              pBuffer = &mRamBuffer + sSysInformation.sRamControl.iRamStartAddress+\
 444   5                                                              (sSysInformation.sRamControl.iRamRwLength-sSysInformation.sRamControl.iRamRemaindLength);
 445   5      
 446   5      //                                      if (bDataLength >0)
 447   5      //                                      {
 448   5                                              D12_COMMAND_ADDRESS =  D12_SELECT_ENDPOINT_ENDPOINT2_IN;        //select endpoint,the optional read one byte
             - is not read
 449   5                                      
 450   5                                              D12_COMMAND_ADDRESS =  D12_WRITE_BUFFER_SELECTED_ENDPOINT;              //write endpoint buffer
 451   5                                              D12_DATA_ADDRESS = 0;                           //first byte is reserved,should wirte 0x00
 452   5                                              D12_DATA_ADDRESS = bDataLength;         //the second byte is the data length that will be write to buffer
 453   5                                              #ifndef _INT_MODE_      
                                                              #ifdef _Debug_
                                                                      printf("Write buffer:");
                                                              #endif
                                                      #endif
 458   5                      
 459   5                                              for(i=0; i<bDataLength; i++)            
 460   5                                              {
 461   6                                                      D12_DATA_ADDRESS = *pBuffer;
 462   6                                                      #ifndef _INT_MODE_      
                                                                      #ifdef _Debug_
                                                                              printf("%x,",(unsigned int)(*pBuffer));
                                                                      #endif
                                                              #endif
 467   6                                                      pBuffer++;
 468   6                                              }
 469   5                                              #ifndef _INT_MODE_      
                                                              #ifdef _Debug_
                                                                      printf("\n");
                                                              #endif
                                                      #endif
 474   5                                              D12_COMMAND_ADDRESS =  D12_VALIDATE_BUFFER_SELECTED_ENDPOINT;                   //validate buffer
 475   5      
 476   5                                              //D12WriteBuffer(D12_SELECT_ENDPOINT_ENDPOINT2_IN,bDataLength,pBuffer);
 477   5                                              sSysInformation.sRamControl.iRamRemaindLength -= bDataLength;
 478   5      //                                      }
C51 COMPILER V7.01  USBISR                                                                 02/17/2006 15:09:24 PAGE 9   

 479   5                                      }
 480   4                              }
 481   3                      }
 482   2                      else
 483   2                      {
 484   3                              //if Hsot issue a IN transacton,but we are not at transmit state,it is an error 
 485   3                              sSysInformation.sRamControl.bRamRwStatus = IDLE;
 486   3                              GENERIC_ENDPOINT_STALL(D12_SELECT_ENDPOINT_ENDPOINT2_IN)
 487   3                              //D12SetEndpointStatus(D12_SELECT_ENDPOINT_ENDPOINT2_IN,D12_ENDPOINT_STALL);                    //set endpoint2-in stall
             -                                
 488   3                      }
 489   2              }
 490   1      
 491   1      }
 492          
 493          
 494          //
 495          //*************************************************************************
 496          //      Paremeter:
 497          //              In : None
 498          //              Out: None
 499          //      Function:
 500          //              According to the interrupt source of PDIUSBD12,call corresponding 
 501          //              function to implementate interrupt service routine.
 502          void UsbIsr(void)
 503          {
 504   1              unsigned char data bD12InterruptRegister;       //used to save D12 innterrupt register value
 505   1      
 506   1              bD12InterruptRegister = D12ReadInterruptRegister();
 507   1      
 508   1              #ifndef _INT_MODE_      
                              #ifdef _Debug_
                                      printf("D12 Int is :0x%x\n",(unsigned int)(bD12InterruptRegister));
                              #endif  
                      #endif
 513   1      
 514   1      
 515   1              if(bD12InterruptRegister != 0) 
 516   1              {
 517   2      
 518   2                      if(bD12InterruptRegister & D12_INT_ENDP0_IN)                    Ep0In();
 519   2                      if(bD12InterruptRegister & D12_INT_ENDP0_OUT)                   Ep0Out();
 520   2                      if(bD12InterruptRegister & D12_INT_ENDP1_IN)                    Ep1In();
 521   2                      if(bD12InterruptRegister & D12_INT_ENDP1_OUT)                   Ep1Out();
 522   2                      if(bD12InterruptRegister & D12_INT_ENDP2_IN)                    Ep2In();
 523   2                      if(bD12InterruptRegister & D12_INT_ENDP2_OUT)                   Ep2Out();
 524   2                      if(bD12InterruptRegister & D12_INT_BUS_RESET)                   sSysInformation.bBusReset = TRUE;
 525   2                      if(bD12InterruptRegister & D12_INT_SUSPEND_CHANGE)              sSysInformation.bSuspendChange = TRUE;
 526   2              }
 527   1      }
 528          


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

C51 COMPILER V7.01  USBISR                                                                 02/17/2006 15:09:24 PAGE 10  


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

⌨️ 快捷键说明

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