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

📄 f32x_usb_isr.lst

📁 C8051F320 SOURCE CODE 内容有: * USB Bulk Driver Example * USB Bulk Firmware Example * Host Ap
💻 LST
📖 第 1 页 / 共 3 页
字号:
 568   1         gEp2OutStatus.uNumBytes = 0;           // Reset byte counter
 569   1      
 570   1         // Get Suspend enable/disable status. If enabled, prepare temporary
 571   1         // variable bPower.
 572   1         if (SUSPEND_ENABLE)
 573   1         {
 574   2            bPower = 0x01;                      // Set bit0 (Suspend Enable)
 575   2         }
 576   1      
 577   1         // Get ISO Update enable/disable status. If enabled, prepare temporary
 578   1         // variable bPower.
 579   1         if (ISO_UPDATE_ENABLE)
 580   1         {
 581   2            bPower |= 0x80;                     // Set bit7 (ISO Update Enable)
 582   2         }
 583   1      
 584   1         UWRITE_BYTE(POWER, bPower);
 585   1      }
 586          
 587          
 588          //-----------------------------------------------------------------------------
 589          // Page_Erase
 590          //-----------------------------------------------------------------------------
 591          //
 592          // Return Value : None
 593          // Parameters   :
 594          // 1) BYTE* Page_Address
 595          //
 596          // Erases the page of FLASH located at Page_Address
 597          //-----------------------------------------------------------------------------
 598          void Page_Erase (BYTE* Page_Address)  small
 599          {
 600   1         BYTE EA_Save;                        // Used to save state of global
 601   1                                              // interrupt enable
 602   1         BYTE xdata *pwrite;                  // xdata pointer used to generate movx
 603   1      
 604   1         EA_Save = EA;                        // Save current EA
 605   1         EA = 0;                              // Turn off interrupts
 606   1         pwrite = (BYTE xdata *)(Page_Address); // Set write pointer to Page_Address
 607   1         PSCTL =  0x03;                       // Enable flash erase and writes
 608   1      
 609   1         FLKEY =  0xA5;                       // Write flash key sequence to FLKEY
 610   1         FLKEY =  0xF1;
 611   1         *pwrite = 0x00;                      // Erase flash page using a
 612   1                                              // write command
 613   1      
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 11  

 614   1         PSCTL = 0x00;                        // Disable flash erase and writes
 615   1         EA = EA_Save;                        // Restore state of EA
 616   1      }
 617          
 618          //-----------------------------------------------------------------------------
 619          // USBReset
 620          //-----------------------------------------------------------------------------
 621          //
 622          // Return Value : None
 623          // Parameters   :
 624          // 1) BYTE* PageAddress
 625          //
 626          // Writes data to the page of FLASH located at PageAddress
 627          //-----------------------------------------------------------------------------
 628          void Page_Write (BYTE* PageAddress)  small
 629          {
 630   1         BYTE EA_Save;                           // Used to save state of global
 631   1                                                 // interrupt enable
 632   1         BYTE xdata *pwrite;                     // Write Pointer
 633   1         BYTE xdata *pread;                      // Read Pointer
 634   1         UINT x;                                 // Counter for 0-512 bytes
 635   1      
 636   1         pread = (BYTE xdata *)(TempStorage);
 637   1         EA_Save = EA;                           // Save EA
 638   1         EA = 0;                                 // Turn off interrupts
 639   1         pwrite = (BYTE xdata *)(PageAddress);
 640   1         PSCTL = 0x01;                           // Enable flash writes
 641   1         for(x = 0; x<FLASH_PAGE_SIZE; x++)      // Write 512 bytes
 642   1         {
 643   2            FLKEY = 0xA5;                        // Write flash key sequence
 644   2            FLKEY = 0xF1;
 645   2            *pwrite = *pread;                    // Write data byte to flash
 646   2      
 647   2            pread++;                             // Increment pointers
 648   2            pwrite++;
 649   2         }
 650   1         PSCTL = 0x00;                           // Disable flash writes
 651   1         EA = EA_Save;                           // Restore EA
 652   1      }
 653          
 654          //-----------------------------------------------------------------------------
 655          // State_Machine
 656          //-----------------------------------------------------------------------------
 657          //
 658          // Return Value : None
 659          // Parameters   : None
 660          //
 661          // Determine new state and act on current state
 662          //-----------------------------------------------------------------------------
 663          void State_Machine(void)
 664          {
 665   1         switch (M_State)
 666   1         {
 667   2      
 668   2            case
 669   2               ST_WAIT_DEV:                  // Stay in Wait State
 670   2               break;
 671   2      
 672   2            case
 673   2               ST_IDLE_DEV:                  // Stay in Idle State
 674   2               break;
 675   2      
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 12  

 676   2            case ST_RX_SETUP:
 677   2               Receive_Setup();              // Decode host Setup Message
 678   2               break;
 679   2      
 680   2            case ST_RX_FILE:
 681   2               Receive_File();               // Receive File data from host
 682   2               break;
 683   2      
 684   2            case ST_TX_ACK:
 685   2               M_State = ST_RX_FILE;         // Ack complete, continue RX data
 686   2               break;
 687   2      
 688   2            case ST_TX_FILE:                     // Send file data to host
 689   2               if(BytesToWrite > MAX_BLOCK_SIZE)
 690   2               {
 691   3                  BulkOrInterruptIn(&gEp1InStatus, (BYTE*)(ReadIndex),MAX_BLOCK_SIZE);
 692   3                  //BytesToWrite -= MAX_BLOCK_SIZE;
 693   3                  //ReadIndex += MAX_BLOCK_SIZE;
 694   3      
 695   3                  //  Try to write a second packet to the fifo here
 696   3                  if(BytesToWrite > MAX_BLOCK_SIZE)
 697   3                  {
 698   4                     BulkOrInterruptIn(&gEp1InStatus, 
 699   4                                       (BYTE*)(ReadIndex),MAX_BLOCK_SIZE);
 700   4                  }
 701   3                  else
 702   3                  {
 703   4                     BulkOrInterruptIn(&gEp1InStatus, 
 704   4                                       (BYTE*)(ReadIndex),BytesToWrite);
 705   4                  }
 706   3               }
 707   2               else
 708   2               {
 709   3                  BulkOrInterruptIn(&gEp1InStatus, (BYTE*)(ReadIndex),BytesToWrite);
 710   3                  //BytesToWrite = 0;
 711   3                  //ReadIndex += BytesToWrite;
 712   3               }
 713   2               //BlocksWrote++;
 714   2               if ((BlocksWrote%8) == 0) 
 715   2               {
 716   3                  Led2 = ~Led2;
 717   3               }
 718   2               if (BlocksWrote == NumBlocks)
 719   2               {
 720   3                  Led2 = 0;
 721   3               }
 722   2               break;
 723   2      
 724   2            default:
 725   2               M_State = ST_ERROR;           // Unknown State, stay in Error State
 726   2               break;
 727   2         }
 728   1      }
 729          
 730          //-----------------------------------------------------------------------------
 731          // Receive_Setup
 732          //-----------------------------------------------------------------------------
 733          //
 734          // Return Value : None
 735          // Parameters   : None
 736          //
 737          // Determines whether a read or write request has been received
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 13  

 738          // Initializes variables for either a read or write operation
 739          //
 740          //-----------------------------------------------------------------------------
 741          
 742          void Receive_Setup(void)
 743          {
 744   1      
 745   1         if (Buffer[0] == READ_MSG)          // Check See if Read File Setup
 746   1         {
 747   2            PageIndex = 0;                   // Reset Index
 748   2            NumBlocks = LengthFile[2];       // Read NumBlocks from flash stg
 749   2            NumBlocks = (NumBlocks > MAX_NUM_BLOCKS)? MAX_NUM_BLOCKS: NumBlocks;
 750   2            Buffer[0] = SIZE_MSG;            // Send host size of transfer message
 751   2            Buffer[1] = LengthFile[1];
 752   2            Buffer[2] = LengthFile[0];
 753   2            BulkOrInterruptIn(&gEp1InStatus, &Buffer, 3);
 754   2            M_State = ST_TX_FILE;            // Go to TX data state
 755   2            BlocksWrote = 0;
 756   2            BytesToWrite = BytesToRead;
 757   2            ReadIndex = PageIndices[0];
 758   2            Led2 = 1;
 759   2         }
 760   1         else                                // Otherwise assume Write Setup Packet
 761   1         {
 762   2            BytesToRead = Buffer[1] + 256*Buffer[2];
 763   2            NumBlocks = (BYTE)(BytesToRead/MAX_BLOCK_SIZE);    // Find NumBlocks
 764   2      
 765   2            if (NumBlocks > MAX_NUM_BLOCKS)  // State Error if transfer too big
 766   2            {
 767   3               M_State = ST_ERROR;
 768   3            }
 769   2            else
 770   2            {
 771   3      
 772   3               if (BytesToRead % MAX_BLOCK_SIZE) 
 773   3               {
 774   4                  NumBlocks++;                // Increment NumBlocks 
 775   4                                                          // for last partial block
 776   4               }                  
 777   3      
 778   3               TempStorage[0].Piece[0] = Buffer[2];
 779   3               TempStorage[0].Piece[1] = Buffer[1];
 780   3               TempStorage[0].Piece[2] = NumBlocks;
 781   3      
 782   3               // Write Values to Flash
 783   3               Page_Erase(LengthFile);    // Store file data to flash
 784   3               Page_Write(LengthFile);
 785   3      
 786   3               PageIndex = 0;             // Reset Index
 787   3               BlockIndex = 0;
 788   3               BlocksRead = 0;
 789   3               Led1 = 1;
 790   3               M_State = ST_RX_FILE;      // Go to RX data state
 791   3            }
 792   2         }
 793   1      }
 794          
 795          //-----------------------------------------------------------------------------
 796          // Receive_Setup
 797          //-----------------------------------------------------------------------------
 798          //
 799          // Return Value : None
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 14  

 800          // Parameters   : None
 801          //
 802          // Increments BlockRead and BlockIndex
 803          // After every 8 packets or at the end of the transfer, sends a handshake
 804          //   signal to the host (0xFF)
 805          // Sets the state of the device
 806          //
 807          //-----------------------------------------------------------------------------
 808          
 809          void Receive_File(void)
 810          {
 811   1         BlocksRead++;       // Increment
 812   1         BlockIndex++;
 813   1         // If multiple of 8 or last packet, disable interrupts,
 814   1         // write page to flash, reset packet index, enable interrupts
 815   1         // Send handshake packet 0xFF to host after FLASH write
 816   1         if ((BlockIndex == (BLOCKS_PR_PAGE)) || (BlocksRead == NumBlocks))
 817   1         {
 818   2            Page_Erase((BYTE*)(PageIndices[PageIndex]));
 819   2            Page_Write((BYTE*)(PageIndices[PageIndex]));
 820   2            PageIndex++;
 821   2            Led1 = ~Led1;
 822   2            BlockIndex = 0;
 823   2            Buffer[0] = 0xFF;
 824   2      
 825   2            // Place Handshake packet (0xFF) on the OUT FIFO
 826   2            BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&Buffer, 1);
 827   2         }
 828   1      
 829   1         // Go to Idle state if last packet has been received
 830   1         if (BlocksRead == NumBlocks)
 831   1         {
 832   2            M_State = ST_IDLE_DEV;
 833   2            Led1 = 0;
 834   2         }
 835   1      }
 836          
 837          //-----------------------------------------------------------------------------
 838          // End Of File
 839          //-----------------------------------------------------------------------------


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1483    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    512    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     16      25
   IDATA SIZE       =     60    ----
   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 + -