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

📄 eth.lst

📁 cf8020+cp2200(网络)的驱动实现
💻 LST
字号:
C51 COMPILER V7.09   ETH                                                                   07/27/2007 15:11:24 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE ETH
OBJECT MODULE PLACED IN ETH.obj
COMPILER INVOKED BY: F:\Keil\C51\BIN\C51.EXE tcp\ETH.C LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\ETH.lst) OBJECT(ETH.obj)

line level    source

   1          //-----------------------------------------------------------------------------
   2          // Copyright (c) 2002 Jim Brady
   3          // Do not use commercially without author's permission
   4          // Last revised August 2002
   5          // Net ETH.C
   6          //
   7          // This module is the Ethernet layer
   8          //-----------------------------------------------------------------------------
   9          
  10          #include <stdlib.h>
  11          #include "net.h"
  12          #include "serial.h"
  13          #include "arp.h"
  14          #include "ip.h"
  15          #include "eth.h"
  16          #include "utils.h"
  17          #include "CP220x_ETH.h"                // Include CP220x Ethernet Routines
  18          
  19          //bit txd_buffer_select=0;              //选择网卡的发送缓冲区  
  20          extern UCHAR  debug;
  21          extern UCHAR  arpbuf[];
  22          extern UCHAR  my_hwaddr[]; 
  23          
  24          void Delay1ms(unsigned char T);
  25          
  26          extern UCHAR rcve_buf_allocated;
  27          extern uint volatile event_word;
  28          
  29          
  30          
  31          #define Rtl8019ResetLow         P5 &= ~(0x4);   // P52 
  32          #define Rtl8019ResetHigh        P5 |= 0x4;              // P52
  33          
  34          //------------------------------------------------------------------------
  35          // Initialize the Cirrus Logic 8019 chip
  36          //------------------------------------------------------------------------
  37          
  38          void ReadRtl8019NodeID(void)//读出网卡的物理地址存到my_ethernet_address.bytes[6]里  
  39          {
  40   1              unsigned char  i;
  41   1              for (i=0;i<6;i++)
  42   1              { 
  43   2                      //      my_hwaddr[i]=reg10;
  44   2                      //      my_hwaddr[i]=reg10;
  45   2              }
  46   1      }
  47          
  48          
  49          //------------------------------------------------------------------------
  50          // This functions checks 8019 status then sends an ethernet
  51          // frame to it by calling an assembler function. 
  52          //------------------------------------------------------------------------
  53          
  54          void send_frame(UCHAR * outbuf, uint len)/*发送一个数据包的命令,长度最小为60字节,最大1514字节*/
  55          {
C51 COMPILER V7.09   ETH                                                                   07/27/2007 15:11:24 PAGE 2   

  56   1              CP220x_SendD(outbuf, len);
  57   1      //      s3c44b0_eth_send(outbuf, len);
  58   1      //      printf("send packet\n");
  59   1      }
  60          
  61          //------------------------------------------------------------------------
  62          // This functions checks the 8019 receive event status
  63          // word to see if an ethernet frame has arrived.  If so,
  64          // set EVENT_ETH_ARRIVED bit in global event_word
  65          //------------------------------------------------------------------------
  66          void query_8019(void)
  67          {   
  68   1      
  69   1      }
  70          
  71          //------------------------------------------------------------------------
  72          // This function gets an incoming Ethernet frame from the 8019.
  73          // There may be more than 1 waiting but just allocate memory for
  74          // one and read one in.  Use the 8019 to queue incoming packets.
  75          //------------------------------------------------------------------------
  76          UCHAR * rcve_frame()//如果收到一个有效的数据包,返回收到的数据,否则返回NULL
  77          {
  78   1      //      UCHAR bnry,curr,next_page;
  79   1      //      
  80   1      //      uint len, ii;
  81   1      //      UCHAR temp;
  82   1      //      UCHAR * buf;
  83   1      //      if (buf_head!= buf_tail)
  84   1      
  85   1              return NULL;
  86   1      } 
  87          
  88          
  89          void eth_send(UCHAR  * outbuf, UCHAR * hwaddr, uint ptype, uint len)
  90          {
  91   1              ETH_HEADER  * eth;
  92   1              
  93   1              eth = (ETH_HEADER *)outbuf;
  94   1              
  95   1              // Add 14 byte Ethernet header]
  96   1          //Ethernet V2标准:14 = 目的MAC地址6 byte + 源MAC地址6 byte + 类型(2) = 14, 不包括LLC层
  97   1          //现不支持: 802.3标准. MAC数据报文最小长度46 - 1500字节。小于46, 填充0;
  98   1              
  99   1              memcpy((char*)eth->dest_hwaddr, hwaddr, 6);       //目的MAC地址6 byte
 100   1              memcpy((char*)eth->source_hwaddr, my_hwaddr, 6);  //源MAC地址6 byte
 101   1          eth->frame_type = ptype;                    //类型2 byte. 比如0x0800, 表示上层使用IP数据包.  =0x8137, 
             -表示为Novell IPX发过来。  
 102   1      #ifdef __LITTLEENDIAN__
                      eth->frame_type = ntohs(eth->frame_type);
              #endif
 105   1              
 106   1              // We just added 14 bytes to length
 107   1              send_frame(outbuf, len + 14);
 108   1      }
 109          
 110          //------------------------------------------------------------------------
 111          // This is the handler for incoming Ethernet frames
 112          //      This is designed to handle standard Ethernet (RFC 893) frames
 113          // See "TCP/IP Illustrated, Volume 1" Sect 2.2
 114          //------------------------------------------------------------------------
 115          void eth_rcve(uint Length, UCHAR* inbuf)
 116          {
C51 COMPILER V7.09   ETH                                                                   07/27/2007 15:11:24 PAGE 3   

 117   1              ETH_HEADER * eth;
 118   1              
 119   1              eth = (ETH_HEADER *)inbuf;
 120   1      
 121   1      #ifdef __LITTLEENDIAN__
                      eth->frame_type = ntohs(eth->frame_type);       
              #endif
 124   1              
 125   1              // Reject frames in IEEE 802 format where Eth type field
 126   1              // is used for length.  Todo: Make it handle this format
 127   1              if (eth->frame_type < 1520)
 128   1              {
 129   2                      return;      
 130   2              }
 131   1              //printf("frame_type %x", eth->frame_type);
 132   1              // Figure out what type of frame it is from Eth header
 133   1              // Call appropriate handler and supply address of buffer
 134   1              switch (eth->frame_type)
 135   1              {
 136   2                 case ARP_PACKET:
 137   2                         arp_rcve(inbuf);
 138   2                         break;
 139   2                         
 140   2                 case IP_PACKET:
 141   2      #ifdef __LITTLEENDIAN__
                                 eth->frame_type = ntohs(eth->frame_type);               
              #endif
 144   2                         ip_rcve(inbuf);
 145   2                         break;
 146   2                         
 147   2                 default:
 148   2      
 149   2                         break;
 150   2              }
 151   1      }
*** WARNING C280 IN LINE 115 OF TCP\ETH.C: 'Length': unreferenced local variable
 152          
 153          
 154          
 155          
 156          


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


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

⌨️ 快捷键说明

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