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

📄 ethernet.lst

📁 51 单片机上网
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.07   ETHERNET                                                              06/30/2006 16:21:46 PAGE 1   


C51 COMPILER V7.07, COMPILATION OF MODULE ETHERNET
OBJECT MODULE PLACED IN ethernet.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE ethernet.c LARGE OPTIMIZE(SIZE) BROWSE

stmt level    source

   1          #include <reg52.h>
   2          #include <absacc.h>
   3          #include <string.h>
   4          #include <stdio.h>
   5          #include "reg_ne2k.h"
   6          #include "ethernet.h"
   7          
   8          sbit HW_RESET=0xb4;
   9          BYTE mymac[MACLEN];
  10          
  11          typedef struct {                    /*  NIC hardware packet header */
  12              BYTE stat;                      /*  Error status */
  13              BYTE next;                      /*  Pointer to next block */
  14              WORD len;                       /*  Length of this frame incl. CRC */
  15          } NICHDR;
  16          NICHDR nichdr;
  17          
  18          void delay_ms(int number);
  19          void resetnic();
  20          void getnic(WORD addr,BYTE buf[],WORD len);
  21          void putnic(WORD addr,BYTE buf[],WORD len);
  22          BYTE nicwrap(BYTE page);
  23          
  24          //***************************************************
  25          //              接收数据包,将8019中的数据包读入指定的数据包缓冲区pkt,帧头读入nichdr结构中
  26          //              全局变量 nichdr 
  27          //      全局变量 next_packet
  28          //      返回:如果接收到数据包,返回数据包长度len,(该长度为减去校验和长度) 
  29          //           否则  : 0
  30          //      get packet into buffer,return length (excel  CRC ),or 0 if no available
  31          //***************************************************
  32          WORD get_ethernet(void *efp)            
  33          {
  34   1              WORD current_offset;
  35   1              BYTE curr_page;
  36   1              BYTE bnry;
  37   1              
  38   1              if (EN0_ISR &0x10) resetnic();     
  39   1              /* Get the Receive Page, CURR */
  40   1              EN_CMD = EN_NODMA + EN_PAGE1 + EN_START;  
  41   1              curr_page = EN1_CURPAG;
  42   1              EN_CMD = EN_NODMA + EN_PAGE0 + EN_START;
  43   1              bnry=EN0_BOUNDARY+1;            /* Get the BOUNDARY Register  */
  44   1              if (bnry>RX_STOP_PG)  bnry=RX_START_PG;
  45   1              /* Remove one frame from the ring.  Boundary is always a page behind. */
  46   1      //      if (curr_page==0) return (0);
  47   1              if (bnry!=curr_page)
  48   1              {
  49   2                      current_offset = (WORD)(bnry << 8);
  50   2                      /* Get the header of this packet */
  51   2                      memset(&nichdr,0xee,sizeof(nichdr));
  52   2                      getnic(current_offset, (BYTE *)&nichdr,sizeof(nichdr));
  53   2                      nichdr.len=(nichdr.len/256)+((nichdr.len %256)<<8);
  54   2                                              //keil c 在结构中使用该方法时,编译器编译的不正确(keil c bug)
  55   2      //              nichdr.len=(nichdr.len>>8)&0xff+(nichdr.len&0xff)<<8;
C51 COMPILER V7.07   ETHERNET                                                              06/30/2006 16:21:46 PAGE 2   

  56   2                      if ((nichdr.stat &0x01) && nichdr.len>=MINFRAMEC  && nichdr.len<=MAXFRAMEC)
  57   2                              getnic(current_offset+sizeof(nichdr),(BYTE *)efp,nichdr.len-sizeof(nichdr));
  58   2                      if (nichdr.next>=RX_START_PG && nichdr.next<RX_STOP_PG)
  59   2                              bnry=nichdr.next;
  60   2                      else
  61   2                              bnry=nicwrap(bnry+1);           //nic error
  62   2                      bnry=nicwrap(bnry-1);
  63   2                      EN0_BOUNDARY=bnry;
  64   2                      return (nichdr.len-sizeof(nichdr)-sizeof(ETHERHDR));
  65   2              }       
  66   1              return (0);
  67   1      }
  68          
  69          //*************************************************************
  70          //  Send Ethernet packet give Len   excl. CRC,return 0 if NIC busy
  71          //  全局变量   locnode.mac   (本地的以太物理地址 ) 
  72          //     
  73          //*************************************************************
  74           WORD put_ethernet(void *efp,WORD len)
  75           {
  76   1               if  (EN_CMD & EN_TRANS)  /* if still TXing,return 0 */
  77   1                   len=0;
  78   1               else  
  79   1               {
  80   2                      len=min(MAXFRAME,max(len,MINFRAME));
  81   2                      EN_CMD=EN_PAGE0+EN_NODMA;
  82   2                      EN0_ISR=EN_RREAD+EN_START;
  83   2                      EN0_TCNTLO=(BYTE)(len & 0xff);
  84   2                      EN0_TCNTHI=(BYTE)(len>>8);
  85   2                      putnic(TX_START_PG<<8,(BYTE *)efp,len);
  86   2                      EN_CMD=EN_NODMA+EN_PAGE0+EN_TRANS;
  87   2               }
  88   1               return(len);
  89   1      }
  90          
  91          //*************************************************************
  92          //      reset nic (ne2000 compact 8019as)
  93          //*************************************************************
  94          void resetnic()
  95          {
  96   1              unsigned char c;
  97   1      
  98   1              c = EN_RESET;
  99   1              EN_RESET = c;
 100   1      //    HW_RESET = 1;           /* Hardware RESET.   when EN_RESET = 0; is Software  */
 101   1          delay_ms(10);
 102   1      //    HW_RESET = 0;
 103   1              delay_ms(10);    
 104   1      
 105   1          EN_CMD = EN_PAGE0 + EN_NODMA + EN_STOP; /* 00001010B: PS1 PS0 RD2 RD1 RD0 TXP STA STP */
 106   1          delay_ms(4);
 107   1      //    EN0_DCFG = ENDCFG_FT10 + ENDCFG_BMS + ENDCFG_BOS;   /*  ?FIFO treshold 8byte !!,normal operation, by
             -te transfer mode selection */
 108   1                                                      /* Clear the remote     byte count registers. */
 109   1          EN0_DCFG = ENDCFG_FT10 + ENDCFG_BMS;
 110   1          EN0_RCNTHI = 0x00;                  /* MSB remote byte count reg */
 111   1          EN0_RCNTLO = 0x00;                  /* LSB remote byte count reg */
 112   1      
 113   1          EN0_RXCR = E8390_RXOFF;     /* RX configuration reg    Monitor mode (no packet receive) */
 114   1          EN0_TXCR = E8390_TXOFF;     /* TX configuration reg    set internal loopback mode  */
 115   1          
 116   1          EN0_TPSR = NE_START_PG;
C51 COMPILER V7.07   ETHERNET                                                              06/30/2006 16:21:46 PAGE 3   

 117   1          EN0_STARTPG = RX_START_PG ; /* DMA START PAGE 46h */ 
 118   1                                      /* Starting page of ring buffer. First page of Rx ring buffer 46h*/
 119   1          EN0_STOPPG = NE_STOP_PG;    /* Ending page +1 of ring buffer */
 120   1          EN0_BOUNDARY = RX_START_PG; /* Boundary page of ring buffer */
 121   1          EN0_ISR = 0xff;                     /* INTerrupt stauts reg */
 122   1          EN0_IMR = 0;                                /* INTerrupt mask reg = Disable all Interrupt */
 123   1          
 124   1          
 125   1          EN_CMD = EN_PAGE1 + EN_NODMA+EN_STOP;
 126   1          delay_ms(4); 
 127   1          EN1_PAR0 = mymac[0];
 128   1          EN1_PAR1 = mymac[1];
 129   1          EN1_PAR2 = mymac[2];
 130   1          EN1_PAR3 = mymac[3];
 131   1          EN1_PAR4 = mymac[4];
 132   1          EN1_PAR5 = mymac[5];
 133   1          /* Initialize the multicast list to accept-all.  If we enable multicast
 134   1                 the higher levels can do the filtering. multicast filter mask array (8 bytes) */
 135   1          EN1_MAR0 = 0xff;  
 136   1          EN1_MAR1 = 0xff;
 137   1          EN1_MAR2 = 0xff;
 138   1          EN1_MAR3 = 0xff;
 139   1          EN1_MAR4 = 0xff;
 140   1          EN1_MAR5 = 0xff;

⌨️ 快捷键说明

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