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

📄 eth.lst

📁 单片机控制RTL8019AS的程序,C语言编写,仿真通过.
💻 LST
📖 第 1 页 / 共 2 页
字号:
 163   1              page(0);
 164   1              bnry=reg03;             //bnry page have read 读页指针
 165   1              page(1);
 166   1              curr=reg07;             //curr writepoint 8019写页指针
 167   1              page(0);
 168   1              if ((curr==0))  return;
 169   1              bnry=bnry++;
 170   1              if (bnry>0x7f)  bnry=0x4c;
 171   1              if (bnry!=curr) //此时表示有新的数据包在缓冲区里
 172   1              {
 173   2                      EA = 0;
 174   2                  event_word |= EVENT_ETH_ARRIVED;
 175   2              EA = 1;
 176   2              }
 177   1              reg0b=0x00; reg0a=0x00;  reg00=0x22;//complete dma page 0
 178   1      }
 179          
C51 COMPILER V7.06   ETH                                                                   10/09/2006 21:51:54 PAGE 4   

 180          //------------------------------------------------------------------------
 181          // This function gets an incoming Ethernet frame from the 8019.
 182          // There may be more than 1 waiting but just allocate memory for
 183          // one and read one in.  Use the 8019 to queue incoming packets.
 184          //------------------------------------------------------------------------
 185          UCHAR xdata * rcve_frame(void)//如果收到一个有效的数据包,返回收到的数据,否则返回NULL
 186          {
 187   1              UCHAR bnry,curr,next_page;
 188   1      
 189   1              UINT len, ii;
 190   1              UCHAR temp;
 191   1              UCHAR xdata * buf;
 192   1      
 193   1              page(0);
 194   1              bnry=reg03;             //bnry page have read 读页指针
 195   1              page(1);
 196   1              curr=reg07;             //curr writepoint 8019写页指针
 197   1              page(0);
 198   1              if ((curr==0))  return NULL;    //读的过程出错
 199   1              next_page=bnry;
 200   1              bnry=bnry++;
 201   1              if (bnry>0x7f)  bnry=0x4c;
 202   1              if (bnry!=curr) //此时表示有新的数据包在缓冲区里
 203   1              {
 204   2                      //读取一包的前4个字节:4字节的8019头部
 205   2                      page(0);
 206   2                      reg09=bnry;             //read page address high好像有问题,bnry++过,应该--吧@
 207   2                      reg08=0x00;     //read page address low
 208   2                      reg0b=0x00;             //read count high
 209   2                      reg0a=4;                //read count low;
 210   2                      reg00=0x0a;             //read dma
 211   2                      
 212   2                      temp = reg10;           temp = reg10;
 213   2                      next_page = temp-1;     
 214   2                      len = reg10;            temp = reg10;
 215   2                      len += temp<<8; 
 216   2                      reg0b=0x00; reg0a=0x00;  reg00=0x22;//complete dma page 0
 217   2      
 218   2                      // Allocate enough memory to hold the incoming frame
 219   2                      buf = (UCHAR xdata *)malloc(len);
 220   2                      if (buf == NULL)
 221   2                      {
 222   3                              // out of RAM
 223   3                              // Tell 8019 to skip the frame
 224   3                              page(1);
 225   3                              curr=reg07;     //page1
 226   3                              page(0);                //切换回page0
 227   3                      bnry = curr -1;
 228   3                      if      (bnry < 0x4c) bnry =0x7f;
 229   3                      reg03=bnry;     //write to bnry   
 230   3                              reg07=0xff;             //清除中断状态可以不用
 231   3                              return NULL;
 232   3                      }
 233   2                      // This flag keeps track of allocated rcve memory
 234   2                      rcve_buf_allocated = TRUE;
 235   2                      // Call the assembler function to get the incoming frame
 236   2                      reg09=bnry;     //read page address high
 237   2                      reg08=4;        //read page address low
 238   2                      reg0b=len>>8;   //read count high
 239   2                      reg0a=len&0xff; //read count low;
 240   2                      reg00=0x0a;     //read dma
 241   2              for(ii=0;ii<len;ii++)
C51 COMPILER V7.06   ETH                                                                   10/09/2006 21:51:54 PAGE 5   

 242   2              {
 243   3                      buf[ii]=reg10;
 244   3              }
 245   2                      reg0b=0x00;     reg0a=0x00; reg00=0x22; //dma complete  page0     
 246   2                      // Return pointer to start of buffer
 247   2                      bnry=next_page;
 248   2                      if (bnry<0x4c)  bnry=0x7f;
 249   2                      reg03=bnry;     //write to bnry    
 250   2              reg07=0xff;
 251   2                      return (buf);   
 252   2              }
 253   1              return NULL;
 254   1      }
 255          
 256          
 257          
 258           
 259                          
 260          
 261          void eth_send(UCHAR xdata * outbuf, UCHAR * hwaddr, UINT ptype, UINT len)
 262          {
 263   1              ETH_HEADER xdata * eth;
 264   1         
 265   1         eth = (ETH_HEADER xdata *)outbuf;
 266   1                
 267   1              // Add 14 byte Ethernet header
 268   1              memcpy(eth->dest_hwaddr, hwaddr, 6);
 269   1              memcpy(eth->source_hwaddr, my_hwaddr, 6); 
 270   1         eth->frame_type = ptype;
 271   1      
 272   1         // We just added 14 bytes to length
 273   1         send_frame(outbuf, len + 14);
 274   1      }
 275          
 276          //------------------------------------------------------------------------
 277          // This is the handler for incoming Ethernet frames
 278          //      This is designed to handle standard Ethernet (RFC 893) frames
 279          // See "TCP/IP Illustrated, Volume 1" Sect 2.2
 280          //------------------------------------------------------------------------
 281          void eth_rcve(UCHAR xdata * inbuf)
 282          {
 283   1         ETH_HEADER xdata * eth;
 284   1         
 285   1         eth = (ETH_HEADER xdata *)inbuf;
 286   1         
 287   1         // Reject frames in IEEE 802 format where Eth type field
 288   1         // is used for length.  Todo: Make it handle this format
 289   1         if (eth->frame_type < 1520)
 290   1         {
 291   2      
 292   2            return;      
 293   2         }
 294   1      
 295   1         // Figure out what type of frame it is from Eth header
 296   1         // Call appropriate handler and supply address of buffer
 297   1         switch (eth->frame_type)
 298   1         {
 299   2                 case ARP_PACKET:
 300   2                 arp_rcve(inbuf);
 301   2                 break;
 302   2                            
 303   2                 case IP_PACKET:
C51 COMPILER V7.06   ETH                                                                   10/09/2006 21:51:54 PAGE 6   

 304   2                 ip_rcve(inbuf);
 305   2            break;
 306   2      
 307   2            default:
 308   2            break;
 309   2         }
 310   1      }
 311          
 312          
 313          
 314          
 315          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    961    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      24
   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 + -