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

📄 main.lst

📁 upsd 3200序列的usb驱动
💻 LST
📖 第 1 页 / 共 2 页
字号:
 329   1          if (rcvReport.u.cmd == 0)
 330   1          {
 331   2              // Process the incoming data based on the current command
 332   2              switch (currentCmd.u.cmd)
 333   2              {
 334   3              case CMD_WRITE:
 335   3      
 336   3                  // Skip over command byte in first packet
 337   3                  if (rcvIndex == 0)
 338   3                  {
 339   4                      if (cbReceived <= 1)
 340   4                      {
 341   5                          // Error
 342   5                          return;
 343   5                      }
 344   4      
 345   4                      cbData = min(currentCmd.u.rw.nBytes, cbReceived - 1);
 346   4                      index = rcvIndex + 1;
 347   4                  }
 348   3                  else
 349   3                  {
 350   4                      cbData = min(currentCmd.u.rw.nBytes, cbReceived);
 351   4                      index = rcvIndex;
 352   4                  }
 353   3      
 354   3                  WriteBufferToFlash(
 355   3                      currentCmd.u.rw.flash,
 356   3                      currentCmd.u.rw.address,
 357   3                      rcvReport.u.buffer + index,
 358   3                      cbData);
 359   3      
 360   3                  currentCmd.u.rw.address += cbData;
 361   3                  currentCmd.u.rw.nBytes -= cbData;
 362   3                  if (currentCmd.u.rw.nBytes == 0)
 363   3                  {
 364   4                      // All done
 365   4                      currentCmd.u.cmd = 0;
C51 COMPILER V7.00 Beta 6  MAIN                                                            02/19/2003 15:59:28 PAGE 7   

 366   4      
 367   4                      if (currentCmd.u.rw.flash == PRIMARY_FLASH)
 368   4                      {
 369   5                          flash_reset();
 370   5                      }
 371   4                      else
 372   4                      {
 373   5                          flash_boot_reset();
 374   5                      }
 375   4                  }
 376   3                  
 377   3                  break;
 378   3      
 379   3              default:
 380   3      
 381   3                  break;
 382   3              }
 383   2          }
 384   1      }
 385          
 386          /////////////////// OnReportReceived()
 387          //
 388          // Called after all segments of a report have been received.
 389          
 390          static void OnReportReceived()
 391          {
 392   1          // If this is a new command coming in ...
 393   1          if (rcvReport.u.cmd)
 394   1          {
 395   2              if (rcvReport.u.cmd == CMD_STATUS)
 396   2              {
 397   3                  // For CMD_GET_STATUS, don't overwrite current cmd we're working on
 398   3                  returnStatus = TRUE;
 399   3              }
 400   2              else
 401   2              {
 402   3                  // Copy into 'current command' global variable
 403   3                  memcpy(currentCmd.u.buffer, rcvReport.u.buffer, sizeof(rcvReport));
 404   3                  memset((uchar*)&status, 0, sizeof(status));
 405   3      
 406   3                  g_debug1 = currentCmd.u.cmd;
 407   3              }
 408   2      
 409   2              // Some commands are processed at this point
 410   2              switch (rcvReport.u.cmd)
 411   2              {
 412   3              case CMD_RESET:
 413   3                  WDKEY=0; // watchdog will trigger reset in a second
 414   3                  currentCmd.u.cmd = 0;
 415   3                  break;
 416   3              case CMD_SET_PAGE:
 417   3                  UPSD_xreg.PAGE = rcvReport.u.setRegs.page;
 418   3                  currentCmd.u.cmd = 0;
 419   3                  break;
 420   3              case CMD_SET_VM:
 421   3                  UPSD_xreg.VM = rcvReport.u.setRegs.vm;
 422   3                  currentCmd.u.cmd = 0;
 423   3                  break;
 424   3              case CMD_SET_REGS:
 425   3                  UPSD_xreg.PAGE = rcvReport.u.setRegs.page;
 426   3                  UPSD_xreg.VM = rcvReport.u.setRegs.vm;
 427   3                  currentCmd.u.cmd = 0;
C51 COMPILER V7.00 Beta 6  MAIN                                                            02/19/2003 15:59:28 PAGE 8   

 428   3                  break;
 429   3              default:
 430   3                  // Prepare first segment of any response to go back to host
 431   3                  PrepareTransmitSegment(0);
 432   3                  break;
 433   3              }
 434   2          }
 435   1      }
 436          
 437          /////////////////// OnReportTransmitted()
 438          //
 439          // A complete feature report has been successfully transmitted.
 440          
 441          static void OnReportTransmitted()
 442          {
 443   1          if (returnStatus)
 444   1          {
 445   2              returnStatus = FALSE;
 446   2          }
 447   1      
 448   1          // If there's more data to go ...
 449   1          if (currentCmd.u.cmd)
 450   1          {
 451   2              // Prepare first segment of next report
 452   2              PrepareTransmitSegment(0);
 453   2          }
 454   1      }
 455          
 456          /////////////////// HandleReport()
 457          //
 458          // Handles HID Get_Report and Set_Report SETUP packets.
 459          //
 460          // Returns TRUE if the SETUP packet is a Get_Report or Set_Report
 461          // request; else returns FALSE.
 462          
 463          static BOOL HandleReport()
 464          {
 465   1          // If it is a HID Set_Report request...
 466   1          if ((setupPacket.bmRequestType == CLASS_INTERFACE_TO_DEVICE)
 467   1              && (setupPacket.bRequest == HID_SET_REPORT))
 468   1          {
 469   2              // Prepare to receive report
 470   2              rcvIndex = 0;
 471   2              return TRUE;
 472   2          }
 473   1          // Else if it is a HID Get_Report request ...
 474   1          else if ((setupPacket.bmRequestType == CLASS_INTERFACE_TO_HOST)
 475   1              && (setupPacket.bRequest == HID_GET_REPORT))
 476   1          {
 477   2              // Transmit first segment of response (should be already prepared)
 478   2              UCON0 &= ~uTSEQ0;
 479   2              TransmitDataEP0(txReport.u.buffer, EP0_SIZE);
 480   2      
 481   2              // Prepare next segment while first one is going out
 482   2              txIndex = EP0_SIZE;
 483   2              PrepareTransmitSegment(txIndex);
 484   2              return TRUE;
 485   2          }
 486   1      
 487   1          return FALSE;
 488   1      }
 489          
C51 COMPILER V7.00 Beta 6  MAIN                                                            02/19/2003 15:59:28 PAGE 9   

 490          /////////////////// UsbIsr()
 491          //
 492          // USB interrupt service routine.
 493          
 494          static void UsbIsr() interrupt USB_VECTOR
 495          {
 496   1          uchar cb;
 497   1          uchar i;
 498   1          volatile uchar x;
 499   1          BOOL ret;
 500   1              
 501   1          // If data successfully transmitted on EP0 IN ...
 502   1          if (UISTA & uTXD0F)
 503   1          {
 504   2              // Reset transmit FIFO and clear transmit enable bit
 505   2              UCON0 |= (uRX0E | uTX0E | 8);
 506   2              UCON0 &= ~uTX0E;
 507   2      
 508   2              // If in the middle of transmitting a report ...
 509   2              if (txIndex < FEATURE_REPORT_SIZE)
 510   2              {
 511   3                  // Transmit next segment of outgoing report
 512   3                  cb = min(FEATURE_REPORT_SIZE - txIndex, EP0_SIZE);
 513   3                  TransmitDataEP0(txReport.u.buffer + txIndex, cb);
 514   3      
 515   3                  // Clear the interrupt and let the packet go out
 516   3                  UISTA &= ~uTXD0F;
 517   3      
 518   3                  if ((txIndex += cb) >= FEATURE_REPORT_SIZE)
 519   3                  {
 520   4                      OnReportTransmitted();
 521   4                  }
 522   3                  else
 523   3                  {
 524   4                      // Prepare the next segment while that last one is going out
 525   4                      PrepareTransmitSegment(txIndex);
 526   4                  }    
 527   3              }
 528   2              else
 529   2              {
 530   3                  // Handle standard control requests
 531   3                  BaseEp0TxHandler();
 532   3      
 533   3                  // Clear the interrupt
 534   3                  UISTA &= ~uTXD0F;
 535   3              }
 536   2          }
 537   1      
 538   1          // If data received on EP0 OUT ...
 539   1          if (UISTA & uRXD0F)
 540   1          {
 541   2              // If it's a SETUP packet ...
 542   2              if (USTA & uSETUP)
 543   2              {
 544   3                  // Read the SETUP packet
 545   3                  ret = ReadSetupPacket();
 546   3      
 547   3                  // Clear interrupt so next packet can come in now
 548   3                  UISTA &= ~uRXD0F;
 549   3      
 550   3                  if (ret)
 551   3                  {                
C51 COMPILER V7.00 Beta 6  MAIN                                                            02/19/2003 15:59:28 PAGE 10  

 552   4                      // If this is not a HID report ...
 553   4                      if (!HandleReport())
 554   4                      {
 555   5                          // ... pass it on to the basic SETUP packet handler
 556   5                          OnSetupPacket();
 557   5                      }
 558   4                  }                    
 559   3              }
 560   2              else
 561   2              {
 562   3                  // If in the middle of receiving a report ...
 563   3                  if ((USTA & 0x0F) && (rcvIndex < OUTPUT_REPORT_SIZE))
 564   3                  {
 565   4                      // Read the next segment
 566   4                      cb = USTA & 0x0F;
 567   4                      for (i = 0; i < cb; i++)
 568   4                      {
 569   5                          rcvReport.u.buffer[rcvIndex + i] = UDR0;
 570   5                      }
 571   4      
 572   4                      // Toggle data toggle bit
 573   4                      USTA ^= uRSEQ;
 574   4      
 575   4                      // Next packet can come in now
 576   4                      UISTA &= ~uRXD0F;
 577   4                  
 578   4                      // Handle report as it comes in and/or when all done
 579   4                      OnReportSegmentReceived(cb);
 580   4                      if ((rcvIndex += cb) >= OUTPUT_REPORT_SIZE)
 581   4                      {
 582   5                          OnReportReceived();
 583   5                  
 584   5                          // Transmit 0 length ack packet
 585   5                          UCON0 = uTSEQ0 | uRX0E | uTX0E;
 586   5                      }
 587   4                  }
 588   3                  else
 589   3                  {
 590   4                      // Toggle data toggle bit
 591   4                      USTA ^= uRSEQ;
 592   4      
 593   4                      // Next packet can come in now
 594   4                      UISTA &= ~uRXD0F;
 595   4                  }
 596   3              }
 597   2              }
 598   1      
 599   1          // If data transmitted on EP1 ...
 600   1          if (UISTA & uTXD1F)
 601   1          {
 602   2              // Load up next input report with LCD display data
 603   2              OnTransmitEP1();
 604   2      
 605   2              // Clear the interrupt
 606   2              UISTA &= ~uTXD1F;
 607   2          }
 608   1      
 609   1          // If there is a resume bus condition ...
 610   1          if (UISTA & uRESUMEF)
 611   1          {
 612   2              // Handle bus activity while in suspended state
 613   2              UISTA &= ~uRESUMEF;
C51 COMPILER V7.00 Beta 6  MAIN                                                            02/19/2003 15:59:28 PAGE 11  

 614   2          }
 615   1      
 616   1          // Handle suspend interrupt
 617   1          if (UISTA & uSUSPENDF)
 618   1          {
 619   2              UISTA &= ~uSUSPENDF;
 620   2      
 621   2              // Delay (from Hynix code)
 622   2              for (i = 10; i; i--)
 623   2              {
 624   3                  x = i;
 625   3              }
 626   2      
 627   2              UCON1 |= uFRESUM;
 628   2      
 629   2              // Delay (from Hynix code)
 630   2              for (i = 6; i; i--)
 631   2              {
 632   3                  x = i;
 633   3              }
 634   2      
 635   2              UCON1 &= ~uFRESUM;        
 636   2          }
 637   1      
 638   1          // Handle USB bus reset
 639   1          if (UISTA & uRSTF)
 640   1          {
 641   2              UISTA &= ~uRSTF;
 642   2              UsbInitialize();
 643   2          }
 644   1      
 645   1          // Just clear EOP interrupts
 646   1          UISTA &= ~(uEOPF);
 647   1      }
 648          
 649          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1655    ----
   CONSTANT SIZE    =     31    ----
   XDATA SIZE       =    520      34
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   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 + -