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

📄 rtl8019.lst.svn-base

📁 数字广播系统的开发源码
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
 248   1              chRTLInitTmp = ReadReg(0x05);
 249   1              chRTLInitTmp = ReadReg(0x04);
 250   1      
 251   1              RTLPage(1);
 252   1              //MAR0~7
 253   1              chRTLInitTmp = ReadReg(0x08);
 254   1              chRTLInitTmp = ReadReg(0x09);
 255   1              chRTLInitTmp = ReadReg(0x0a);
 256   1              chRTLInitTmp = ReadReg(0x0b);
 257   1              chRTLInitTmp = ReadReg(0x0c);
 258   1              chRTLInitTmp = ReadReg(0x0d);
 259   1              chRTLInitTmp = ReadReg(0x0e);
 260   1              chRTLInitTmp = ReadReg(0x0f);
 261   1              //for(i = 0;i < 20000;i++);
 262   1              //PAR0~5
 263   1              chRTLInitTmp = ReadReg(0x03);
 264   1              chRTLInitTmp = ReadReg(0x01);
 265   1              chRTLInitTmp = ReadReg(0x02);
 266   1              chRTLInitTmp = ReadReg(0x06);
 267   1              chRTLInitTmp = ReadReg(0x05);
 268   1              chRTLInitTmp = ReadReg(0x04); */
 269   1      
 270   1              /* transimit start page */
 271   1              LastSendStartPage = SEND_START_PAGE0;
 272   1              StartPageOfPacket = RECEIVE_START_PAGE + 1;
 273   1      
 274   1              /* in the beginning, no packet is in sending */
 275   1              InSending = FALSE;
 276   1      
 277   1              RTLPage(0);
 278   1              /* initial over, start command and receive */
 279   1              WriteReg(0x0c,0xcc);                //将芯片置于正常模式,跟外部网络连接
 280   1              WriteReg(0x0d,0xe0);
 281   1              WriteReg(0x07,0xFF);
 282   1              chRTLInitTmp = ReadReg(0x07);       //清除所有中断标志位
 283   1              //(CR_PAGE0 | CR_ABORT_COMPLETE_DMA | CR_START_COMMAND));
 284   1              WriteReg(0x00,0x22);
 285   1       }
*** WARNING C280 IN LINE 169 OF E:\NETBRO~1\TRUNK\NETBRO~1\VW\RTL8019.C: 'i': unreferenced local variable
 286          
 287          /* write buffer to rlt ram */
 288          void RTLWriteRam(unsigned int address, unsigned int size, unsigned char xdata * buff) reentrant
 289          {
 290   1              unsigned char xdata *Endp;
 291   1              unsigned char PrePage;  // store page
 292   1              PrePage = ReadReg(0x00);//CR
 293   1              RTLPage(0);
 294   1              WriteReg(RSARH_WPAGE0,(unsigned char)((address>>8)&0x00ff));
 295   1              WriteReg(RSARL_WPAGE0,(unsigned char)address);
 296   1              WriteReg(RBCRH_WPAGE0,(unsigned char)((size>>8)&0x00ff));
 297   1              WriteReg(RBCRL_WPAGE0,(unsigned char)size);
 298   1              WriteReg(CR,(0x00 | CR_REMOTE_WRITE | CR_START_COMMAND));
 299   1              for(Endp = buff + size; buff < Endp;)
 300   1              {
 301   2                      WriteReg(REMOTE_DMA_PORT,*(buff++));
C51 COMPILER V7.06   RTL8019                                                               07/24/2007 16:39:36 PAGE 6   

 302   2              }
 303   1              /* complete dma */
 304   1              WriteReg(RBCRH_WPAGE0,0);
 305   1              WriteReg(RBCRL_WPAGE0,0);
 306   1              WriteReg(0x00,((PrePage&0xC0) | CR_ABORT_COMPLETE_DMA | CR_START_COMMAND));
 307   1              //printf("RTL8019AS初始化完成!");
 308   1      }
 309          
 310          /* read rlt ram data to buffer */
 311          void RTLReadRam(unsigned int address,unsigned int size,unsigned char xdata * buff) reentrant
 312          {
 313   1              unsigned char xdata * Endp;
 314   1              unsigned char PrePage;  /* store page */
 315   1      
 316   1              PrePage = ReadReg(CR);
 317   1              RTLPage(0);
 318   1              WriteReg(RSARH_WPAGE0,(unsigned char)((address>>8)&0x00ff));
 319   1              WriteReg(RSARL_WPAGE0,(unsigned char)address);
 320   1              WriteReg(RBCRH_WPAGE0,(unsigned char)((size>>8)&0x00ff));
 321   1              WriteReg(RBCRL_WPAGE0,(unsigned char)size);
 322   1              WriteReg(CR,(0x00 | CR_REMOTE_READ | CR_START_COMMAND));
 323   1              for(Endp = buff + size; buff < Endp;)
 324   1              {
 325   2                      *(buff++) = ReadReg(REMOTE_DMA_PORT);
 326   2              }
 327   1              /* complete dma */
 328   1              WriteReg(RBCRH_WPAGE0,0);
 329   1              WriteReg(RBCRL_WPAGE0,0);
 330   1              WriteReg(CR,((PrePage&0xC0) | CR_ABORT_COMPLETE_DMA | CR_START_COMMAND));
 331   1      }
 332          /* call this function to send a packet by RTL8019. packet store in ram
 333          starts at 'buffer' and its size is 'size'. 'size' should not large than
 334          MAX_PACKET_SIZE or the excess data will be discard. */
 335          unsigned char RTLSendPacket(unsigned char xdata * buffer,unsigned int size)
 336          {
 337   1              unsigned char StartPage;
 338   1              unsigned char PrePage;
 339   1      
 340   1              /* if send is already running */
 341   1              if(InSending == TRUE)
 342   1                      return FALSE;
 343   1              else
 344   1                      InSending = TRUE;
 345   1              /* store page */
 346   1              PrePage = ReadReg(CR);
 347   1      
 348   1              /* check pakcet size */
 349   1              if(size < MIN_PACKET_SIZE)
 350   1              {
 351   2                      size = MIN_PACKET_SIZE;
 352   2              }
 353   1              else
 354   1              {
 355   2                      if(size > MAX_PACKET_SIZE)
 356   2                              size = MAX_PACKET_SIZE;
 357   2              }
 358   1      
 359   1              /* write packet to ram */
 360   1              if(LastSendStartPage == SEND_START_PAGE0)
 361   1              {
 362   2                      StartPage = SEND_START_PAGE1;
 363   2                      LastSendStartPage = SEND_START_PAGE1;
C51 COMPILER V7.06   RTL8019                                                               07/24/2007 16:39:36 PAGE 7   

 364   2              }
 365   1              else
 366   1              {
 367   2                      StartPage = SEND_START_PAGE0;
 368   2                      LastSendStartPage = SEND_START_PAGE0;
 369   2              }
 370   1              RTLWriteRam((unsigned int)(((unsigned int)StartPage)<<8),size,buffer);
 371   1      
 372   1              /* wait for last time trasmition to complete */
 373   1              while((ReadReg(CR) & CR_TXP) == CR_TXP);
 374   1      
 375   1              /* write trasmit start page and size */
 376   1              RTLPage(0);
 377   1              WriteReg(TPSR_WPAGE0,StartPage);        /* TPSR */
 378   1              WriteReg(TBCRL_WPAGE0,(unsigned char)size);/*low */
 379   1              WriteReg(TBCRH_WPAGE0,(unsigned char)((size>>8)&0x00ff));       /*high*/
 380   1              WriteReg(CR,((PrePage&0xC0) | CR_ABORT_COMPLETE_DMA | CR_TXP | CR_START_COMMAND));
 381   1      
 382   1              InSending = FALSE;
 383   1              return TRUE;
 384   1      }
 385          
 386          /* call this function to receive a ethernet packet from RTL8019.
 387          return value:
 388                  NULL: no packet can receive yet.
 389                  not NULL:
 390                          a address point to MemHead. This Head contain merory
 391                          Imformation(memory start address, memory end address ...) of
 392                          received packet. Memory is allocated by function 'MemAllocate(unsigned int size)'.
 393                          a example of struct SMemHead is:
 394          
 395                          struct SMemHead
 396                          {
 397                                  unsigned char used;                                             // if in using
 398                                  unsigned char xdata *pStart;                    // the start address of memory
 399                                  unsigned char xdata *pEnd;
 400                          };
 401          
 402                          You can use your own struct SMemHead and MemAllocat function in your project.
 403          */
 404          struct SMemHead xdata * RTLReceivePacket() reentrant
 405          {
 406   1              unsigned char curr,bnry;
 407   1              unsigned int address;
 408   1              unsigned int PacketSize;
 409   1              struct SMemHead xdata *MemHead;
 410   1      
 411   1              /* if send is running don't crrupt RTL register*/
 412   1              if(InSending == TRUE)
 413   1                      return NULL;
 414   1      
 415   1              MemHead = NULL;
 416   1      
 417   1              RTLPage(1);
 418   1              curr = ReadReg(CURR_RPAGE1);
 419   1              RTLPage(0);
 420   1      
 421   1              /* check if startpage exceed range becasue of unknow error */
 422   1              if(StartPageOfPacket >= RECEIVE_STOP_PAGE || StartPageOfPacket < RECEIVE_START_PAGE)
 423   1              {
 424   2                      /* use curr as the StartPageOfPacket in this case */
 425   2                      StartPageOfPacket = curr;
C51 COMPILER V7.06   RTL8019                                                               07/24/2007 16:39:36 PAGE 8   

 426   2                      return NULL;
 427   2              }
 428   1      
 429   1              /* check if there is packets to read */
 430   1              if(StartPageOfPacket == curr)
 431   1                      return NULL;
 432   1      
 433   1              /*
 434   1               * read a packet
 435   1               */
 436   1      
 437   1              /* read packet head imformation */
 438   1              address = ((unsigned int)StartPageOfPacket)<<8;
 439   1              RTLReadRam(address,4,Head);
 440   1      
 441   1              /* check rsr, if isn't a good packet no read */
 442   1              if(Head[0] & RSR_RECEIVE_NO_ERROR)
 443   1              {
 444   2                      /* this is a good packet */
 445   2      
 446   2                      /* packet size, sub 4 bytes, this 4 byte is MAC checksum */
 447   2                      PacketSize = ((unsigned int)Head[3])*256 + Head[2] - 4;
 448   2      
 449   2                      /* allocate buffer and read packet into buffer */
 450   2                      if((MemHead = MemAllocate(PacketSize)) != NULL)
 451   2                      {
 452   3                              /* if packet is put from bnry+1 to receive_stop_page and receive
 453   3                                 start page to next packet startpage, that is if bnry+1 > next
 454   3                                 packet start page and next start page != receive_start_page,
 455   3                                 we need read by two times. the first time from bnry+1 to receive
 456   3                                 _stop_page, the second time from receive start page to next packet
 457   3                                 startpage.
 458   3                              */
 459   3                              address += 4;
 460   3                              if(StartPageOfPacket > Head[1] && Head[1] != RECEIVE_START_PAGE)
 461   3                              {
 462   4                                      RTLReadRam(address,(unsigned int)((((unsigned int)RECEIVE_STOP_PAGE)<<8) - address),MemHead->pStart);   
             -/* read from rtl */
 463   4                                      RTLReadRam((unsigned int)(((unsigned int)RECEIVE_START_PAGE)<<8),(unsigned int)(PacketSize - ((((unsig
             -ned int)RECEIVE_STOP_PAGE)<<8) - address)),
 464   4                                              MemHead->pStart + ((((unsigned int)RECEIVE_STOP_PAGE)<<8) - address));  /* read from rtl */
 465   4                              }
 466   3                              else
 467   3                              {
 468   4                                      RTLReadRam(address,PacketSize,MemHead->pStart); /* read from rtl */
 469   4                              }
 470   3      
 471   3                      }
 472   2              }
 473   1      
 474   1              /* get next packet start page */
 475   1              StartPageOfPacket = Head[1];
 476   1      
 477   1              /* reset bnry */
 478   1              bnry = StartPageOfPacket - 1;
 479   1              if(bnry < RECEIVE_START_PAGE)
 480   1                      bnry = RECEIVE_STOP_PAGE - 1;
 481   1              WriteReg(BNRY_WPAGE0,bnry);
 482   1      
 483   1              return MemHead;
 484   1      }
 485          
C51 COMPILER V7.06   RTL8019                                                               07/24/2007 16:39:36 PAGE 9   

 486          
 487          void RTL8019SendPacketTest()
 488          {
 489   1      /* send a arp request packet, src ip = 192.168.2.13, dest ip = 192.168.2.14,
 490   1      if you config your computer's ip as 192.168.2.14, then after run this function,
 491   1      your computer will receive the packet, and when you type "arp -a" in windows
 492   1      command window(dos window) you will see a arp entry of 52 54 4c 30 2e 2f.
 493   1      this indicate a packet has been successful sent
 494   1      */
 495   1              /* this is a arp broad cast packet */
 496   1              //Dest MAC
 497   1              TestPacket[0] = 0xff;
 498   1              TestPacket[1] = 0xff;
 499   1              TestPacket[2] = 0xff;
 500   1              TestPacket[3] = 0xff;
 501   1              TestPacket[4] = 0xff;

⌨️ 快捷键说明

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