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

📄 main.lst

📁 单片机tcpip_c51源程序.rar
💻 LST
📖 第 1 页 / 共 2 页
字号:
 221   3                              {
 222   4                                      uart_frame_space=0;
 223   4                                      uart_receive_enable=true;
 224   4                              }
 225   3                       }
 226   2              }
 227   1              if (uart_trans_willing)
 228   1              {
 229   2                              uart_trans_willing=false;
 230   2                              TI=1;
 231   2              }
 232   1              
 233   1          if (being_echo)
 234   1          {
 235   2                   net_overtime_count++;
 236   2                   if (net_overtime_count>18000)
 237   2                   {
 238   3                      being_echo=0;
 239   3                      if (first_arp)
 240   3                              first_arp=0;
 241   3                      else    
C51 COMPILER V7.50   MAIN                                                                  12/23/2005 11:15:15 PAGE 5   

 242   3                              remote_echo=1;
 243   3                      net_overtime_count=0;
 244   3                   }
 245   2          }           
 246   1              runtime++;
 247   1              dog++;
 248   1      }
 249          
 250          /*************************************************************************/
 251          //    串口中断程序,该程序在认为串口的接收是终端在响应串口的发送
 252          //    在串口未发送完成之前,不处理完罗接收的数据
 253          /*************************************************************************/
 254          void uart_interrupt(void)  interrupt 4 
 255          {
 256   1              if (RI)
 257   1              {
 258   2                      RI=0;
 259   2                      if ((!uart_received_finished)&& uart_receive_enable)
 260   2                      {
 261   3                              if (!uart_receiving)
 262   3                              {
 263   4                                      uart_receiving=1;
 264   4                                      uart_receive_count=0;
 265   4                                      uart_receive_buf[uart_receive_count++]=SBUF;
 266   4                              }
 267   3                              else
 268   3                              {
 269   4                                      uart_char_space=0;
 270   4                                      uart_receive_buf[uart_receive_count++]=SBUF;
 271   4                              }
 272   3                      }
 273   2              }
 274   1              if (TI)
 275   1              {
 276   2                      TI=0;
 277   2                      if (uart_trans_count<uart_trans_length)
 278   2                      {
 279   3                                      ACC=uart_trans_buf[uart_trans_count++];
 280   3                                      TB8=P;
 281   3                                      SBUF=ACC;
 282   3                      }
 283   2                      else
 284   2                      {
 285   3                                      uart_trans_finished=1;
 286   3                                      uart_trans_count=0;
 287   3                                      uart_trans_length=0;
 288   3                      }
 289   2                                      
 290   2              }
 291   1      }
 292          
 293          //*******************************************************************************
 294          /* Receive a UDP datagram: return non-0 if client state-change */
 295          int udp_receive(ETHERFRAME *efp, int len)
 296          {
 297   1          UDPKT *udp;
 298   1          int ret=0;
 299   1          NODE loc, rem;
 300   1          udp = (UDPKT *)efp->edata;
 301   1          getudp_srce(efp, &rem);                         /* Get srce & dest nodes */
 302   1          getudp_locdest(efp, &loc);
 303   1          if (loc.port == locnode.port)                   /* Client response */
C51 COMPILER V7.50   MAIN                                                                  12/23/2005 11:15:15 PAGE 6   

 304   1          {
 305   2              //      UDP 将数据拷贝至串口接收缓冲区,置接收完成标志(在合并方式)
 306   2              //              UDP 将数据拷贝至串口发送缓冲区,置发送标志(在模块方式)
 307   2              EA=0;
 308   2              memcpy(uart_trans_buf+uart_trans_length,udp->udpdata,len);
 309   2              uart_trans_length=uart_trans_length+len;
 310   2              uart_trans_finished=0;
 311   2              if (uart_trans_count==0)
 312   2                                      uart_trans_willing=1;
 313   2                      EA=1;        
 314   2              ret = CLIENT_DONE;                          /* ..and exit */
 315   2          }
 316   1          else if (loc.port == ECHOPORT)                  /* Echo req: resend data */
 317   1              udp_transmit(efp, &loc, &rem, udp->udpdata, len);
 318   1          return(ret);
 319   1      }
 320          
 321          /*****************************************************************/
 322          //本机的网络处理子程序
 323          //
 324          /*****************************************************************/
 325          int do_net_process(ETHERFRAME *efp,int rxlen)
 326          {
 327   1              ARPKT *arp;
 328   1              IPKT  *ip;
 329   1              ICMPKT *icmp;
 330   1              NODE node;
 331   1              int txlen;
 332   1              int len;
 333   1              int ret=0;
 334   1              ip=(IPKT *)efp->edata;
 335   1              if (is_arp(efp,rxlen))
 336   1              {
 337   2                  arp = (ARPKT *)efp->edata;
 338   2                    
 339   2                  if (arp->op==ARPREQ && arp->dip==locnode.ip)
 340   2                  {                                       /* ARP request? */
 341   3                      node.ip = arp->sip;                 /* Make ARP response */
 342   3                      memcpy(node.mac, arp->smac, MACLEN);
 343   3                      txlen = make_arp(efp, &locnode, &node, ARPRESP);
 344   3                      put_ethernet(efp, txlen);              /* Send packet */
 345   3                  }
 346   2                  if (arp->op==ARPRESP && arp->dip==locnode.ip)
 347   2                  {                                       /* ARP response? */
 348   3                      memcpy(remnode.mac,arp->smac, MACLEN);
 349   3                      being_echo=0;
 350   3                      if (first_arp)
 351   3                          first_arp=0;
 352   3                      else 
 353   3                          remote_echo=1;
 354   3                      ret = ARP_RX;
 355   3                  }
 356   2              }
 357   1          else if ((rxlen=is_ip(efp, rxlen))!=0)    /* IP datagram? */
 358   1                       if (ip->i.dip==locnode.ip || ip->i.dip==BCASTIP)
 359   1                                              
 360   1                {
 361   2                  getip_srce(efp, &node);
 362   2                  if ((len=is_icmp(ip, rxlen))!=0)        /* ICMP? */
 363   2                  {
 364   3                      icmp = (ICMPKT *)ip;
 365   3                      if (icmp->c.type == ICREQ)          /* Echo request? */
C51 COMPILER V7.50   MAIN                                                                  12/23/2005 11:15:15 PAGE 7   

 366   3                      {
 367   4                          len = (WORD)max(len, 0);       /* Make response */
 368   4                          txlen = make_icmp(efp, &locnode, &node, ICREP,
 369   4                                            icmp->c.codetype, (WORD)len);
 370   4                          put_ethernet(efp, txlen);          /* Send packet */
 371   4                      }
 372   3      //                else if (icmp->c.type == ICUNREACH)
 373   3      //                    printf("\r\nICMP: destination unreachable\r\n");
 374   3                  }
 375   2                  else if ((len=is_udp(ip, rxlen))!=0)    /* UDP? */
 376   2                  {
 377   3                      ret = udp_receive(efp, max(len, 0));
 378   3                  }
 379   2              }
 380   1              return (ret);
 381   1      }
 382          
 383          //**********************************
 384          void flush_gate_mac()
 385          {                       
 386   1              int ret;
 387   1              remote_echo=0;
 388   1              remnode.mac[0]=0xff;
 389   1              remnode.mac[1]=0xff;
 390   1              remnode.mac[2]=0xff;
 391   1              remnode.mac[3]=0xff;
 392   1              remnode.mac[4]=0xff;
 393   1              remnode.mac[5]=0xff;
 394   1              ret=make_arp(&etherframe,&locnode, &remnode, ARPREQ);           //请求网关或控制主机的物理地址
 395   1              put_ethernet(&etherframe,ret);
 396   1              being_echo=1;
 397   1      }
 398          //************************************************
 399          void do_uart_process(void)
 400          {
 401   1              if (being_echo==0)                      // 1 arp wait response
 402   1              {
 403   2                      if (remote_echo==0)
 404   2                      {
 405   3                              if (!memcmp(remnode.mac, bcast, MACLEN))
 406   3                                      flush_gate_mac();
 407   3                              else
 408   3                                      send_ip();
 409   3                      }               
 410   2                      else
 411   2                      {
 412   3                               remote_echo=0;
 413   3                               send_ip();
 414   3                      }        
 415   2               }
 416   1      }
 417          
 418          //************************************************
 419          void send_ip(void)
 420          {
 421   1              int ret;
 422   1          memcpy((BYTE *)&etherframe+sizeof(ETHERHDR)+sizeof(IPHDR)+sizeof(UDPHDR),uart_receive_buf,uart_receive
             -_count);
 423   1              remnode.port=locnode.port;
 424   1              ret=make_udp(&etherframe, &locnode,&remnode,(WORD)(uart_receive_count));
 425   1              uart_received_finished=0;  
 426   1              uart_receive_count=0;
C51 COMPILER V7.50   MAIN                                                                  12/23/2005 11:15:15 PAGE 8   

 427   1              put_ethernet(&etherframe,ret);
 428   1      }
 429          
 430          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2092    ----
   CONSTANT SIZE    =      6    ----
   XDATA SIZE       =   2075      96
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      1    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      8    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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