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

📄 main.lst

📁 cp2200网卡的tcp/ip源程序( 包含驱动),十分难得哦
💻 LST
📖 第 1 页 / 共 3 页
字号:
 550   1         // Program the MAC address
 551   1         MAC_SetAddress(&MYMAC); 
 552   1      
 553   1         // Enable Reception and configure Loopback mode
 554   1         MAC_Write(MACCN, 0x0001);           // Enable Reception without loopback
 555   1      
 556   1      }
 557          
 558          void MAC_Write(unsigned char mac_reg_offset, unsigned int mac_reg_data)
 559          {
 560   1      
 561   1         // Step 1: Write the address of the indirect register to MACADDR.
 562   1         MACADDR = mac_reg_offset;              
 563   1      
 564   1         // Step 2: Copy the contents of <mac_reg_data> to MACDATAH:MACDATAL
 565   1         MACDATAH = (mac_reg_data >> 8);    // Copy High Byte
 566   1         MACDATAL = (mac_reg_data & 0xFF);  // Copy Low Byte
 567   1      
 568   1         // Step 3: Perform a write on MACRW to transfer the contents of MACDATAH:MACDATAL
 569   1         // to the indirect MAC register.
 570   1         MACRW = 0;
 571   1         
 572   1         return;
 573   1      }
 574          
 575          
 576          //-----------------------------------------------------------------------------
 577          // MAC_SetAddress
 578          //-----------------------------------------------------------------------------
 579          //
 580          // Return Value : None
 581          // Parameters   : 
 582          //   1)  MACADDRESS* pMAC - pointer to a 6-byte MAC address structure.
 583          // 
 584          // Sets the current MAC address to the MAC address pointed to by <pMAC>.
 585          //-----------------------------------------------------------------------------
 586          void MAC_SetAddress(MACADDRESS* pMAC)
 587          {
 588   1         UINT1 temp_int;
 589   1      
 590   1         temp_int.Char[0] = pMAC->Char[5];
 591   1         temp_int.Char[1] = pMAC->Char[4];
 592   1         MAC_Write(MACAD0, temp_int.Int);
 593   1         
 594   1         temp_int.Char[0] = pMAC->Char[3];
 595   1         temp_int.Char[1] = pMAC->Char[2];
 596   1         MAC_Write(MACAD1, temp_int.Int);
 597   1         
 598   1         temp_int.Char[0] = pMAC->Char[1];
 599   1         temp_int.Char[1] = pMAC->Char[0];
 600   1         MAC_Write(MACAD2, temp_int.Int);
 601   1         
 602   1         return;
 603   1      }
 604          
 605          
 606          
 607          void eth_rcve(UCHAR xdata * inbuf)
 608          {
 609   1         ETH_HEADER xdata * eth;
 610   1         
 611   1         eth = (ETH_HEADER xdata *)inbuf;
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 11  

 612   1         
 613   1         // Reject frames in IEEE 802 format where Eth type field
 614   1         // is used for length.  Todo: Make it handle this format
 615   1         if (eth->frame_type < 1520)
 616   1         {
 617   2      //      free(inbuf);
 618   2            return;      
 619   2         }
 620   1      
 621   1         // Figure out what type of frame it is from Eth header
 622   1         // Call appropriate handler and supply address of buffer
 623   1         switch (eth->frame_type)
 624   1         {
 625   2                 case ARP_PACKET:
 626   2                 arp_rcve(inbuf);
 627   2                 break;
 628   2                            
 629   2                 case IP_PACKET:
 630   2                 ip_rcve(inbuf);
 631   2            break;
 632   2      
 633   2            default:
 634   2                      ;
 635   2            break;
 636   2         }
 637   1      }
 638          
 639          
 640          void eth_send(UCHAR xdata * outbuf, UCHAR * hwaddr, UINT ptype, UINT len)
 641          {
 642   1              ETH_HEADER xdata * eth;
 643   1         
 644   1         eth = (ETH_HEADER xdata *)outbuf;
 645   1                
 646   1              // Add 14 byte Ethernet header
 647   1              memcpy(eth->dest_hwaddr, hwaddr, 6);
 648   1              memcpy(eth->source_hwaddr, my_hwaddr, 6); 
 649   1         eth->frame_type = ptype;
 650   1      
 651   1         // We just added 14 bytes to length
 652   1         CP220x_Send(outbuf, len + 14);
 653   1      }
 654          
 655          void CP220x_Send( UCHAR xdata * outbuf, UINT len)
 656          {
 657   1      
 658   1         int i; 
 659   1         unsigned int ramaddr;
 660   1      
 661   1         // Define Macro to increment the RAM address Pointer
 662   1         #define INC_RAMADDR  ramaddr++; \
 663   1                              RAMADDRH = (ramaddr >> 8);\
 664   1                              RAMADDRL = (ramaddr & 0x00FF);
 665   1      
 666   1      
 667   1         // Step 1: Poll TXBUSY until it becomes 0x00
 668   1         while(TXBUSY);
 669   1      
 670   1         // Step 2: Set the TXSTARTH:TXSTARTL address to 0x0000
 671   1         TXSTARTH = 0x00;
 672   1         TXSTARTL = 0x00;
 673   1      
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 12  

 674   1      
 675   1         // Step 3: Load data into transmit buffer
 676   1         // When the random access method is used, we do not need to check for
 677   1         // aborted packets. This method will be slightly slower than the Autowrite
 678   1         // method, however, it reduces code space requirements.
 679   1        
 680   1            // Setup RAM Address Pointer To 0x0000    
 681   1            RAMADDRH = 0x00;
 682   1            RAMADDRL = 0x00;
 683   1            ramaddr = 0x0000;
 684   1      
 685   1            // Step 3d: Load the packet payload
 686   1            for(i = 0; i < len; i++){
 687   2               RAMTXDATA = outbuf[i];
 688   2               INC_RAMADDR
 689   2            }
 690   1            
 691   1            // Step 3e: Pad short packets
 692   1            while(ramaddr < 64){
 693   2               RAMTXDATA = 0;
 694   2               INC_RAMADDR
 695   2            }
 696   1            
 697   1            // Set the TXENDH:TXENDL address to <ramaddr - 1>
 698   1            ramaddr--;
 699   1            TXENDH = (ramaddr >> 8);
 700   1            TXENDL = (ramaddr & 0x00FF);
 701   1      
 702   1      
 703   1         // Step 4: Set the TXSTARTH:TXSTARTL address back to 0x0000
 704   1         TXSTARTH = 0x00;
 705   1         TXSTARTL = 0x00;
 706   1         
 707   1         // Step 5: Write '1' to TXGO to begin transmission
 708   1         TXCN = 0x01;
 709   1      //   free(outbuf);
 710   1       
 711   1      }
 712          
 713          UCHAR xdata * rcve_frame(void)
 714          
 715          {
 716   1         bit rx_ok;
 717   1         bit skip = 0;
 718   1         UINT1 cplen;   
 719   1         unsigned int i;
 720   1         UCHAR xdata * buf;
 721   1      
 722   1         unsigned char interrupt_read;
 723   1         unsigned char valid_bits;
 724   1         unsigned char num_packets;
 725   1      
 726   1         // Clear interrupt flags.
 727   1         interrupt_read = INT1;
 728   1         interrupt_read = INT0;
 729   1         
 730   1         // Check for packet received interrupt
 731   1         if( interrupt_read & RXINT)
 732   1         {   
 733   2            // Count the number of packets in the receive buffer         
 734   2            // This is equal to the number of bits set to 1 in TLBVALID
 735   2            valid_bits = TLBVALID;     
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 13  

 736   2                  for(num_packets = 0; valid_bits; num_packets++)      
 737   2            {                                 
 738   3               valid_bits &= valid_bits - 1; 
 739   3            }
 740   2         
 741   2            // If the receive buffer has 7 packets, then disable reception.
 742   2            if( num_packets >= 7) 
 743   2            {
 744   3               RXCN = RXINH;           // Inhibit New Packet Reception
 745   3            }
 746   2                }
 747   1      
 748   1         // Step 1: Check the RXOK bit to see if packet was received correctly
 749   1         rx_ok = (CPINFOL & RXOK) && (CPINFOH & RXVALID);
 750   1      
 751   1         // Step 2: If packet received correctly, read the length, otherwise, skip packet.
 752   1         if(rx_ok){
 753   2         
 754   2            // Read the packet length
 755   2            cplen.Char[0] = CPLENH;
 756   2            cplen.Char[1] = CPLENL;
 757   2                buf=inbuf1;
 758   2      //        buf = (UCHAR xdata *)malloc(cplen.Int);
 759   2              
 760   2         } else {
 761   2           
 762   2            // Set packet length to zero
 763   2            cplen.Int = 0;
 764   2            
 765   2            // Skip packet
 766   2            skip = 1;      
 767   2                buf = NULL;
 768   2         }   
 769   1      
 770   1         // Step 3: Read the entire packet from the buffer 
 771   1         
 772   1         // If packet will fit in the buffer
 773   1         if(1){
 774   2            
 775   2            // Copy entire packet
 776   2            for(i = 0; i < cplen.Int; i++){
 777   3               buf[i] = RXAUTORD;
 778   3            }
 779   2                              rcve_buf_allocated = TRUE;
 780   2      
 781   2      
 782   2         } else {
 783   2      
 784   2            // Set packet length to zero
 785   2            cplen.Int = 0;
 786   2            
 787   2            // Skip packet
 788   2            skip = 1; 
 789   2         }
 790   1            
 791   1         // Step 4: Skip the packet, or clear the valid bit if the entire packet
 792   1         // has been unloaded from the buffer.
 793   1         
 794   1         if(skip)
 795   1         {
 796   2            RXCN |= 0x02;                    // Skip the packet
 797   2         } 
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 14  

 798   1      
 799   1         else 
 800   1         {
 801   2            RXCN |= 0x04;                    // Clear the valid bit only
 802   2         }
 803   1      
 804   1         // If there are no more packets in the receive buffer, enable reception
 805   1         if(TLBVALID == 0x00)
 806   1         {
 807   2            RXCN = 0x00;   
 808   2         }
 809   1         
 810   1         // Return the number of bytes added to the buffer
 811   1         return(buf);
 812   1      }
 813          
 814          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1272    ----
   CONSTANT SIZE    =     18    ----
   XDATA SIZE       =     32    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      9      32
   IDATA SIZE       =      2    ----
   BIT SIZE         =   ----       3
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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