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

📄 main.lst

📁 ST公司的upsd34XX评估板固定源程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
                while ((UPSD_xreg.DATAIN_B & 0x04)==0)
                 {
                  for (w=0;w<600*50;w++);                  // wait 50 ms
                 }
              
                UPSD_xreg.DRIVE_C &= 0xEF;                 // set PC4 as input
                UPSD_xreg.DIRECTION_C &= 0xEF;             // set PC4 as input
              
                UsbInitialize();
                printfLCD("\rUSB Reconnected.");
               }
              
              #endif
 291          
 292          
 293          
 294          
 295          
 296          
 297          
 298          
 299          
 300          
 301          
 302          
 303          
C51 COMPILER V7.06   MAIN                                                                  10/15/2004 20:55:29 PAGE 6   

 304          
 305          
 306          static void WriteBufferToFlash(uchar flash, uint16 address, uchar* buf, uint16 cb)
 307          /******************************************************************************
 308           Function   : static void WriteBufferToFlash()
 309           Parameters : (uchar flash, uint16 address, uchar* buf, uint16 cb)
 310           Description: WriteBufferToFlash()
 311           ******************************************************************************/
 312           {
 313   1                  // Assume desired flash segment is mapped into high 32k of xdata space
 314   1        volatile uchar xdata* p = (volatile uchar xdata*) address;
 315   1      
 316   1        if (flash == PRIMARY_FLASH)
 317   1         {
 318   2          while (cb--)
 319   2           {
 320   3            flash_write_with_poll(p, *buf++);
 321   3            status.u.status.checkSum += *p++;
 322   3           }
 323   2         }
 324   1        else
 325   1         {
 326   2          while (cb--)
 327   2           {
 328   3            flash_boot_write_with_poll(p, *buf++);
 329   3            status.u.status.checkSum += *p++;
 330   3           }
 331   2         }
 332   1       }
 333          
 334          
 335          
 336          
 337          static void ReadBufferFromFlash(uint16 address, uchar* buf, uint16 cb)
 338          /******************************************************************************
 339           Function   : static void ReadBufferFromFlash()
 340           Parameters : (uint16 address, uchar* buf, uint16 cb)
 341           Description: ReadBufferFromFlash()
 342           ******************************************************************************/
 343           {
 344   1                  // Assume desired flash segment is mapped into high 32k of xdata space
 345   1        volatile uchar xdata* p = (volatile uchar xdata*) address;
 346   1      
 347   1        while (cb--)
 348   1         {
 349   2          *buf++ = *p++;
 350   2         }
 351   1       }
 352          
 353          
 354          
 355          
 356          
 357          
 358          
 359          
 360          
 361          
 362          
 363          
 364          
 365          void OnDeviceConfigured()
C51 COMPILER V7.06   MAIN                                                                  10/15/2004 20:55:29 PAGE 7   

 366          /******************************************************************************
 367           Function   : void OnDeviceConfigured()
 368           Parameters : none
 369           Description: Called after device is completely configured.
 370           ******************************************************************************/
 371           {
 372   1        TXD1F = 1;                                 // Set up first tx on EP1 if not
 373   1       }
 374          
 375          
 376          
 377          
 378          
 379          
 380          
 381          
 382          static void PrepareTransmitSegment(uchar index)
 383          /******************************************************************************
 384           Function   : static void PrepareTransmitSegment()
 385           Parameters : (uchar index) -  current byte index into txReport.
 386           Description: Prepare next segment of feature report for transmission.
 387           ******************************************************************************/
 388           {
 389   1        data uchar cbData;
 390   1        data uchar i;
 391   1      
 392   1        if (returnStatus)
 393   1         {
 394   2          if (index == 0)               // Prepare the whole status report on first call
 395   2           {
 396   3            status.u.cmd               = CMD_STATUS;
 397   3            status.u.status.currentCmd = currentCmd.u.cmd;
 398   3            status.u.status.page       = UPSD_xreg.PAGE;
 399   3            status.u.status.vm         = UPSD_xreg.VM;
 400   3            memcpy(&txReport, &status, CMD_SIZE);
 401   3           }
 402   2          return;
 403   2         }
 404   1      
 405   1      
 406   1        /*= The Read command is executed very fast, it can be present at this place.
 407   1                         If you use some time-consuming operations
 408   1                   or your routine takes more than 450us, place your code
 409   1                  instead of CMD_ERASE, where can be long services ... =*/
 410   1      
 411   1        switch (currentCmd.u.cmd)
 412   1         {
 413   2          case CMD_READ:
 414   2      
 415   2          if (index == 0)         // First segment needs 0 command byte to indicate data
 416   2           {
 417   3            cbData = min(currentCmd.u.rw.nBytes, EP0_SIZE - 1);
 418   3            index = 1;
 419   3            txReport.u.cmd = 0;
 420   3           }
 421   2          else
 422   2           {
 423   3            cbData = min(currentCmd.u.rw.nBytes, EP0_SIZE);
 424   3           }
 425   2      
 426   2          ReadBufferFromFlash(
 427   2          currentCmd.u.rw.address,
C51 COMPILER V7.06   MAIN                                                                  10/15/2004 20:55:29 PAGE 8   

 428   2          txReport.u.buffer + index,
 429   2          cbData);
 430   2      
 431   2          currentCmd.u.rw.address += cbData;
 432   2          if ((currentCmd.u.rw.nBytes -= cbData) == 0)
 433   2           {
 434   3            currentCmd.u.cmd = 0;                  // All done
 435   3           }
 436   2      
 437   2          break;
 438   2      
 439   2          default:
 440   2      
 441   2          for (i = 0; i < EP0_SIZE; i++)
 442   2           {
 443   3            txReport.u.buffer[index + i] = 0;
 444   3           }
 445   2      
 446   2          break;
 447   2         }
 448   1       }
 449          
 450          
 451          
 452          
 453          
 454          static void OnReportTransmitted()
 455          /******************************************************************************
 456           Function   : static void OnReportTransmitted()
 457           Parameters : none
 458           Description: A complete feature report has been successfully transmitted.
 459           ******************************************************************************/
 460           {
 461   1        if (returnStatus)
 462   1         {
 463   2          returnStatus = FALSE;
 464   2         }
 465   1      
 466   1        if (currentCmd.u.cmd)                      // If there's more data to go ...
 467   1         {
 468   2          PrepareTransmitSegment(0);             // Prepare first segment of next report
 469   2      
 470   2         }
 471   1       }
 472          
 473          
 474          
 475          
 476          
 477          
 478          
 479          
 480          
 481          
 482          
 483          
 484          
 485          
 486          static void OnReportSegmentReceived(uchar cbReceived)
 487          /******************************************************************************
 488           Function   : static void OnReportSegmentReceived()
 489           Parameters : (uchar cbReceived)
C51 COMPILER V7.06   MAIN                                                                  10/15/2004 20:55:29 PAGE 9   

 490           Description: Called as each EP0_SIZE segment of a report is received.
 491           ******************************************************************************/
 492           {
 493   1        data uchar cbData;
 494   1        data uchar index;
 495   1                                    // If this is data coming in (not a new command) ...
 496   1        if (rcvReport.u.cmd == 0)
 497   1         {
 498   2                               // Process the incoming data based on the current command
 499   2          switch (currentCmd.u.cmd)
 500   2           {
 501   3            case CMD_WRITE:
 502   3      
 503   3            if (rcvIndex == 0)                 // Skip over command byte in first packet
 504   3             {
 505   4              if (cbReceived <= 1)
 506   4               {
 507   5                return;                            // Error
 508   5               }
 509   4      
 510   4              cbData = min(currentCmd.u.rw.nBytes, cbReceived - 1);
 511   4              index = rcvIndex + 1;
 512   4             }
 513   3            else
 514   3             {
 515   4              cbData = min(currentCmd.u.rw.nBytes, cbReceived);
 516   4              index = rcvIndex;
 517   4             }
 518   3      
 519   3            WriteBufferToFlash(
 520   3            currentCmd.u.rw.flash,
 521   3            currentCmd.u.rw.address,
 522   3            rcvReport.u.buffer + index,
 523   3            cbData);
 524   3      
 525   3            currentCmd.u.rw.address += cbData;
 526   3            currentCmd.u.rw.nBytes -= cbData;
 527   3            if (currentCmd.u.rw.nBytes == 0)
 528   3             {
 529   4              currentCmd.u.cmd = 0;                // All done
 530   4              if (currentCmd.u.rw.flash == PRIMARY_FLASH)
 531   4               {
 532   5                flash_reset();
 533   5               }
 534   4              else
 535   4               {
 536   5                flash_boot_reset();
 537   5               }
 538   4             }
 539   3      
 540   3            break;
 541   3      
 542   3            default:
 543   3      
 544   3            break;
 545   3           }
 546   2         }
 547   1       }
 548          
 549          
 550          
 551          
C51 COMPILER V7.06   MAIN                                                                  10/15/2004 20:55:29 PAGE 10  

 552          
 553          
 554          
 555          
 556          static void OnReportReceived()
 557          /******************************************************************************
 558           Function   : static void OnReportReceived()
 559           Parameters : none
 560           Description: Called after all segments of a report have been received.
 561           ******************************************************************************/

⌨️ 快捷键说明

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