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

📄 rtl8019.lst

📁 51 单片机TCP_IP 协议栈ZLIP源码 单片机上网技术
💻 LST
📖 第 1 页 / 共 2 页
字号:
 174   1              WriteReg(CR,((PrePage&0xC0) | CR_ABORT_COMPLETE_DMA | CR_START_COMMAND));
 175   1      }
 176          /* call this function to send a packet by RTL8019. packet store in ram
 177          starts at 'buffer' and its size is 'size'. 'size' should not large than
C51 COMPILER V7.07   RTL8019                                                               01/14/2009 14:46:42 PAGE 4   

 178          MAX_PACKET_SIZE or the excess data will be discard. */
 179          BOOL RTLSendPacket(BYTE DT_XDATA * buffer,WORD size) REENTRANT_SIG
 180          {
 181   1              BYTE StartPage;
 182   1              BYTE PrePage;
 183   1              
 184   1              /* if send is already running */
 185   1              if(InSending == TRUE)
 186   1                      return FALSE;
 187   1              else
 188   1                      InSending = TRUE;
 189   1              /* store page */
 190   1              PrePage = ReadReg(CR);
 191   1              
 192   1              /* check pakcet size */
 193   1              if(size < MIN_PACKET_SIZE)
 194   1              {
 195   2                      size = MIN_PACKET_SIZE;
 196   2              }
 197   1              else
 198   1              {
 199   2                      if(size > MAX_PACKET_SIZE)
 200   2                              size = MAX_PACKET_SIZE;
 201   2              }
 202   1      
 203   1              /* write packet to ram */
 204   1              if(LastSendStartPage == SEND_START_PAGE0)
 205   1              {
 206   2                      StartPage = SEND_START_PAGE1;
 207   2                      LastSendStartPage = SEND_START_PAGE1;
 208   2              }
 209   1              else
 210   1              {
 211   2                      StartPage = SEND_START_PAGE0;
 212   2                      LastSendStartPage = SEND_START_PAGE0;
 213   2              }
 214   1              RTLWriteRam((WORD)(((WORD)StartPage)<<8),size,buffer);
 215   1              
 216   1              /* wait for last time trasmition to complete */
 217   1              while((ReadReg(CR) & CR_TXP) == CR_TXP);
 218   1      
 219   1              /* write trasmit start page and size */
 220   1              RTLPage(0);
 221   1              WriteReg(TPSR_WPAGE0,StartPage);        /* TPSR */                              
 222   1              WriteReg(TBCRL_WPAGE0,(BYTE)size);/*low */                                      
 223   1              WriteReg(TBCRH_WPAGE0,(BYTE)((size>>8)&0x00ff));        /*high*/
 224   1              WriteReg(CR,((PrePage&0xC0) | CR_ABORT_COMPLETE_DMA | CR_TXP | CR_START_COMMAND));              
 225   1              
 226   1              InSending = FALSE;
 227   1              return TRUE;
 228   1      }
 229          
 230          /* call this function to receive a ethernet packet from RTL8019. 
 231          return value: 
 232                  NULL: no packet can receive yet. 
 233                  not NULL: 
 234                          a address point to MemHead. This Head contain merory 
 235                          Imformation(memory start address, memory end address ...) of 
 236                          received packet. Memory is allocated by function 'MemAllocate(WORD size)'.
 237                          a example of struct SMemHead is:
 238          
 239                          struct SMemHead
C51 COMPILER V7.07   RTL8019                                                               01/14/2009 14:46:42 PAGE 5   

 240                          {
 241                                  BOOL used;                                              // if in using 
 242                                  BYTE DT_XDATA *pStart;                  // the start address of memory 
 243                                  BYTE DT_XDATA *pEnd;
 244                          };
 245                          
 246                          You can use your own struct SMemHead and MemAllocat function in your project.           
 247          */
 248          struct SMemHead DT_XDATA * RTLReceivePacket() REENTRANT_SIG
 249          {
 250   1              BYTE curr,bnry;
 251   1              WORD address;
 252   1              WORD PacketSize;
 253   1              struct SMemHead DT_XDATA *MemHead;
 254   1      
 255   1              /* if send is running don't crrupt RTL register*/
 256   1              if(InSending == TRUE)
 257   1                      return NULL;
 258   1      
 259   1              MemHead = NULL;
 260   1      
 261   1              RTLPage(1);
 262   1              curr = ReadReg(CURR_RPAGE1);
 263   1              RTLPage(0);
 264   1      
 265   1              /* check if startpage exceed range becasue of unknow error */
 266   1              if(StartPageOfPacket >= RECEIVE_STOP_PAGE || StartPageOfPacket < RECEIVE_START_PAGE)
 267   1              {
 268   2                      /* use curr as the StartPageOfPacket in this case */
 269   2                      StartPageOfPacket = curr;
 270   2                      return NULL;
 271   2              }
 272   1              
 273   1              /* check if there is packets to read */
 274   1              if(StartPageOfPacket == curr)
 275   1                      return NULL;
 276   1      
 277   1              /* 
 278   1               * read a packet 
 279   1               */
 280   1      
 281   1              /* read packet head imformation */
 282   1              address = ((WORD)StartPageOfPacket)<<8;
 283   1              RTLReadRam(address,4,Head);
 284   1      
 285   1              /* check rsr, if isn't a good packet no read */
 286   1              if(Head[0] & RSR_RECEIVE_NO_ERROR)
 287   1              {
 288   2                      /* this is a good packet */
 289   2      
 290   2                      /* packet size, sub 4 bytes, this 4 byte is MAC checksum */
 291   2                      PacketSize = ((WORD)Head[3])*256 + Head[2] - 4; 
 292   2      
 293   2                      /* allocate buffer and read packet into buffer */
 294   2                      if((MemHead = MemAllocate(PacketSize)) != NULL)
 295   2                      {       
 296   3                              /* if packet is put from bnry+1 to receive_stop_page and receive
 297   3                                 start page to next packet startpage, that is if bnry+1 > next
 298   3                                 packet start page and next start page != receive_start_page, 
 299   3                                 we need read by two times. the first time from bnry+1 to receive
 300   3                                 _stop_page, the second time from receive start page to next packet
 301   3                                 startpage.
C51 COMPILER V7.07   RTL8019                                                               01/14/2009 14:46:42 PAGE 6   

 302   3                              */
 303   3                              address += 4;
 304   3                              if(StartPageOfPacket > Head[1] && Head[1] != RECEIVE_START_PAGE)
 305   3                              {
 306   4                                      RTLReadRam(address,(WORD)((((WORD)RECEIVE_STOP_PAGE)<<8) - address),MemHead->pStart);   /* read from rtl
             - */
 307   4                                      RTLReadRam((WORD)(((WORD)RECEIVE_START_PAGE)<<8),(WORD)(PacketSize - ((((WORD)RECEIVE_STOP_PAGE)<<8) -
             - address)),
 308   4                                              MemHead->pStart + ((((WORD)RECEIVE_STOP_PAGE)<<8) - address));  /* read from rtl */
 309   4                              }
 310   3                              else
 311   3                              {
 312   4                                      RTLReadRam(address,PacketSize,MemHead->pStart); /* read from rtl */
 313   4                              }
 314   3                              
 315   3                      }
 316   2              }
 317   1              
 318   1              /* get next packet start page */
 319   1              StartPageOfPacket = Head[1];
 320   1      
 321   1              /* reset bnry */
 322   1              bnry = StartPageOfPacket - 1;
 323   1              if(bnry < RECEIVE_START_PAGE)
 324   1                      bnry = RECEIVE_STOP_PAGE - 1;
 325   1              WriteReg(BNRY_WPAGE0,bnry);
 326   1      
 327   1              return MemHead;
 328   1      }
 329          
 330          /*void Start8019()
 331          {
 332                  WriteReg(CR,CR_ABORT_COMPLETE_DMA | CR_START_COMMAND);
 333          }
 334          
 335          void Stop8019()
 336          {
 337                  WriteReg(CR,CR_ABORT_COMPLETE_DMA | CR_STOP_COMMAND);
 338          }*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1099    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      7    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       4
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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