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

📄 eth.lst

📁 C51的tcpip源程序 包含了TCP,IP,ARP,ICMP等协议的接口
💻 LST
📖 第 1 页 / 共 2 页
字号:
 175   1              free(outbuf);
 176   1      }
 177          
 178          //------------------------------------------------------------------------
 179          // This functions checks the 8019 receive event status
C51 COMPILER V7.10   ETH                                                                   07/24/2008 16:32:06 PAGE 4   

 180          // word to see if an ethernet frame has arrived.  If so,
 181          // set EVENT_ETH_ARRIVED bit in global event_word
 182          //------------------------------------------------------------------------
 183          void query_8019(void)
 184          {   
 185   1      char bnry,curr;
 186   1              page(0);
 187   1              bnry=reg03;             //bnry page have read 读页指针
 188   1              page(1);
 189   1              curr=reg07;             //curr writepoint 8019写页指针
 190   1              page(0);
 191   1              if ((curr==0))  return;
 192   1              bnry=bnry++;
 193   1              if (bnry>0x7f)  bnry=0x4c;
 194   1              if (bnry!=curr) //此时表示有新的数据包在缓冲区里
 195   1              {
 196   2                      EA = 0;
 197   2                  event_word |= EVENT_ETH_ARRIVED;
 198   2              EA = 1;
 199   2              }
 200   1              reg0b=0x00; reg0a=0x00;  reg00=0x22;//complete dma page 0
 201   1      }
 202          
 203          //------------------------------------------------------------------------
 204          // This function gets an incoming Ethernet frame from the 8019.
 205          // There may be more than 1 waiting but just allocate memory for
 206          // one and read one in.  Use the 8019 to queue incoming packets.
 207          //------------------------------------------------------------------------
 208          UCHAR xdata * rcve_frame(void)//如果收到一个有效的数据包,返回收到的数据,否则返回NULL
 209          {
 210   1      UCHAR bnry,curr,next_page;
 211   1      
 212   1      UINT len, ii;
 213   1      UCHAR temp;
 214   1      UCHAR xdata * buf;
 215   1      
 216   1              page(0);
 217   1              bnry=reg03;             //bnry page have read 读页指针
 218   1              page(1);
 219   1              curr=reg07;             //curr writepoint 8019写页指针
 220   1              page(0);
 221   1              if ((curr==0))  return NULL;    //读的过程出错
 222   1              next_page=bnry;
 223   1              bnry=bnry++;
 224   1              if (bnry>0x7f)  bnry=0x4c;
 225   1              if (bnry!=curr) //此时表示有新的数据包在缓冲区里
 226   1              {
 227   2                      //读取一包的前4个字节:4字节的8019头部
 228   2                      page(0);
 229   2                      reg09=bnry;             //read page address high
 230   2                      reg08=0x00;     //read page address low
 231   2                      reg0b=0x00;             //read count high
 232   2                      reg0a=4;                //read count low;
 233   2                      reg00=0x0a;             //read dma
 234   2                      
 235   2                      temp = reg10;           temp = reg10;
 236   2                      next_page = temp-1;             //next page start-1
 237   2                      len = reg10;            temp = reg10;
 238   2                      len += temp<<8;
 239   2                      reg0b=0x00; reg0a=0x00;  reg00=0x22;//complete dma page 0
 240   2      
 241   2                      // Allocate enough memory to hold the incoming frame
C51 COMPILER V7.10   ETH                                                                   07/24/2008 16:32:06 PAGE 5   

 242   2                      buf = (UCHAR xdata *)malloc(len);
 243   2                      if (buf == NULL)
 244   2                      {
 245   3                              // out of RAM
 246   3                              // Tell 8019 to skip the frame
 247   3                              page(1);
 248   3                              curr=reg07;     //page1
 249   3                              page(0);                //切换回page0
 250   3                      bnry = curr -1;
 251   3                      if      (bnry < 0x4c) bnry =0x7f;
 252   3                      reg03=bnry;     //write to bnry   
 253   3                              reg07=0xff;             //清除中断状态可以不用
 254   3                              return NULL;
 255   3                      }
 256   2                      // This flag keeps track of allocated rcve memory
 257   2                      rcve_buf_allocated = TRUE;
 258   2                      // Call the assembler function to get the incoming frame
 259   2                      reg09=bnry;     //read page address high
 260   2                      reg08=4;        //read page address low
 261   2                      reg0b=len>>8;   //read count high
 262   2                      reg0a=len&0xff; //read count low;
 263   2                      reg00=0x0a;     //read dma
 264   2              for(ii=0;ii<len;ii++)
 265   2              {
 266   3                      buf[ii]=reg10;
 267   3              }
 268   2                      reg0b=0x00;     reg0a=0x00; reg00=0x22; //dma complete  page0     
 269   2                      // Return pointer to start of buffer
 270   2                      bnry=next_page;
 271   2                      if (bnry<0x4c)  bnry=0x7f;
 272   2                      reg03=bnry;     //write to bnry    
 273   2              reg07=0xff;
 274   2                      return (buf);   
 275   2              }
 276   1              return NULL;
 277   1      }
 278          
 279          
 280          
 281           
 282                          
 283          
 284          void eth_send(UCHAR xdata * outbuf, UCHAR * hwaddr, UINT ptype, UINT len)
 285          {
 286   1              ETH_HEADER xdata * eth;
 287   1         
 288   1         eth = (ETH_HEADER xdata *)outbuf;
 289   1                
 290   1              // Add 14 byte Ethernet header
 291   1              memcpy(eth->dest_hwaddr, hwaddr, 6);
 292   1              memcpy(eth->source_hwaddr, my_hwaddr, 6); 
 293   1         eth->frame_type = ptype;
 294   1      
 295   1         // We just added 14 bytes to length
 296   1         send_frame(outbuf, len + 14);
 297   1      }
 298          
 299          //------------------------------------------------------------------------
 300          // This is the handler for incoming Ethernet frames
 301          //      This is designed to handle standard Ethernet (RFC 893) frames
 302          // See "TCP/IP Illustrated, Volume 1" Sect 2.2
 303          //------------------------------------------------------------------------
C51 COMPILER V7.10   ETH                                                                   07/24/2008 16:32:06 PAGE 6   

 304          void eth_rcve(UCHAR xdata * inbuf)
 305          {
 306   1         ETH_HEADER xdata * eth;
 307   1         
 308   1         eth = (ETH_HEADER xdata *)inbuf;
 309   1         
 310   1         // Reject frames in IEEE 802 format where Eth type field
 311   1         // is used for length.  Todo: Make it handle this format
 312   1         if (eth->frame_type < 1520)
 313   1         {
 314   2            if (debug) serial_send("ETH: IEEE 802 pkt rejected\r");
 315   2            return;      
 316   2         }
 317   1      
 318   1         // Figure out what type of frame it is from Eth header
 319   1         // Call appropriate handler and supply address of buffer
 320   1         switch (eth->frame_type)
 321   1         {
 322   2                 case ARP_PACKET:
 323   2                 arp_rcve(inbuf);
 324   2                 break;
 325   2                            
 326   2                 case IP_PACKET:
 327   2                 ip_rcve(inbuf);
 328   2            break;
 329   2      
 330   2            default:
 331   2                      if (debug) serial_send("Error: Unknown pkt rcvd\r");
 332   2            break;
 333   2         }
 334   1      }
 335          
 336          
 337          
 338          
 339          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    969    ----
   CONSTANT SIZE    =     53    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      26
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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