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

📄 udp.lst

📁 mc51单片机对rtl8019编程,实现ethernet的收发控制.
💻 LST
字号:
C51 COMPILER V6.23a  UDP                                                                   05/11/2004 18:03:27 PAGE 1   


C51 COMPILER V6.23a, COMPILATION OF MODULE UDP
OBJECT MODULE PLACED IN udp.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE udp.c LARGE ROM(COMPACT) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          
   2          #include "ethernet.h"
   3          #include "ip.h"
   4          #include "udp.h"
   5          #include "ring.h"
   6          #include "arp.h"
   7          extern  Net_inf_struc   net_inf;
   8          xdata Uint8 tx_buf[1500];
   9          ring_struc ring;
  10          
  11          Uint8 rx_buf[MAX_DUP_BUFFER_LENGTH*MAX_DUP_BUFFER_COUNT];
  12          
  13          Bool udp_open(Uint8 *pip,Uint16 port_local,Uint16 port_remote)
  14          {
  15   1              if(net_inf.portnumber_local)
  16   1                      return FALSE;
  17   1              net_inf.portnumber_local = port_local;
  18   1              net_inf.portnumber_remote = port_remote;
  19   1              if(pip==NULL)
  20   1                      memset(net_inf.ip_remote,0,INADDR_LEN);
  21   1              else
  22   1                      memcpy(net_inf.ip_remote,pip,INADDR_LEN);
  23   1              ring_init(&ring,rx_buf,MAX_DUP_BUFFER_LENGTH,MAX_DUP_BUFFER_COUNT);
  24   1      }
  25          void udp_close()
  26          {
  27   1              net_inf.portnumber_local = 0;
  28   1              net_inf.portnumber_remote = 0;
  29   1      }
  30          
  31          Bool udp_sendto(Uint8 *pip,Uint16 remote_port,Uint8 *pbuf,Uint16 length)
  32          {
  33   1              xdata  Ip_struc* ipPkt;
  34   1              xdata  Udphdr_struc* udpPkt;
  35   1              
  36   1              ipPkt = ( Ip_struc*) (tx_buf + sizeof(Ether_header_struc));
  37   1              udpPkt = ( Udphdr_struc*) ((Uint8*) ipPkt + sizeof(Ip_struc));
  38   1              // UDP header
  39   1              udpPkt->source = net_inf.portnumber_local ;
  40   1              udpPkt->dest = remote_port;
  41   1              udpPkt->len = length+sizeof(Udphdr_struc);
  42   1              udpPkt->check = 0;
  43   1              //content
  44   1              memcpy((Uint16 *)udpPkt+ sizeof(Udphdr_struc),pbuf,length);
  45   1              // destination IP
  46   1              memcpy(&ipPkt->ip_dst, pip, INADDR_LEN);
  47   1              // fill source address for checksum - use a zero ip address if we do not have one (eg sending bootp)
  48   1              memcpy(&ipPkt->ip_src, net_inf.ip_local, INADDR_LEN);
  49   1              // packet length, protocol & id are the same
  50   1              ipPkt->ip_len = udpPkt->len + sizeof(Ip_struc);
  51   1              ipPkt->ip_p = IPPROTO_UDP;
  52   1              ipPkt->ip_id = 0;
  53   1              ipPkt->ip_ttl = 64;
  54   1              // insert checksum & send
  55   1              //udpPkt->check = cpu_checksum(( Uint16 *) ipPkt, (aLength | CPU_CHECKSUM_INC_IP) - sizeof(Ip_struc));
C51 COMPILER V6.23a  UDP                                                                   05/11/2004 18:03:27 PAGE 2   

  56   1              return ip_send(tx_buf);
  57   1      }
  58          Bool udp_send(Uint8 *pbuf,Uint16 length)
  59          {
  60   1              return udp_sendto(net_inf.ip_remote,net_inf.portnumber_remote,pbuf,length);
  61   1      }
  62          Uint16 udp_recv(Uint8 *pbuf,Uint16 length)
  63          {       
  64   1              Uint16 i;
  65   1              if(ring_read(&ring,tx_buf)){
  66   2                      i = tx_buf[0]<<8;
  67   2                      i |= tx_buf[1];
  68   2                      length = Min(length,i);
  69   2                      memcpy(pbuf,tx_buf+2,length);
  70   2                      return length;
  71   2              }
  72   1              return 0;
  73   1      }
  74          void udp_process(Uint8* pudp)
  75          {
  76   1              xdata  Udphdr_struc* udpPkt;
  77   1              udpPkt = (Udphdr_struc*)pudp;
  78   1              if(udpPkt->dest != net_inf.portnumber_local)
  79   1              return;
  80   1              if(net_inf.portnumber_remote == 0)
  81   1                      net_inf.portnumber_remote = udpPkt->source;
  82   1              if(udpPkt->source != net_inf.portnumber_remote)
  83   1              return;
  84   1              udpPkt->check = udpPkt->len-sizeof(Udphdr_struc);
  85   1              ring_write(&ring,pudp+sizeof(Udphdr_struc)-2);
  86   1      }
  87                                           
  88          void tick()
  89          {
  90   1              xdata Uint8 buffer[1500]; 
  91   1              Uint16 i;
  92   1              if(ethernet_receive(buffer)){
  93   2                      i = buffer[12]<<8;
  94   2                      i |= buffer[13];
  95   2                      switch(i){
  96   3                                      case ETHERTYPE_IP:
  97   3                                              ip_receive(buffer);
  98   3                                              break;
  99   3                                      case ETHERTYPE_ARP:
 100   3                                              arp_receive(buffer);
 101   3                                              break;
 102   3                              }       
 103   2              }       
 104   1       
 105   1      }
 106          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    834    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   3513    1534
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.

C51 COMPILER V6.23a  UDP                                                                   05/11/2004 18:03:27 PAGE 3   


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

⌨️ 快捷键说明

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