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

📄 rtl8019.lst

📁 运行环境是keil。这是一个实现嵌入式TCP/IP的程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 246          {
 247   1              unsigned char i;
 248   1              unsigned char bnry;
 249   1              
 250   1              unsigned char pageheader[4];
 251   1              unsigned int rxlen;
 252   1              
 253   1              // check for and handle an overflow
 254   1              processRTL8019Interrupt();
 255   1              
 256   1              // read CURR from page 1
 257   1              writeRTL(CR,0x62);
 258   1              i = readRTL(CURR);
 259   1              
 260   1              // return to page 0
 261   1              writeRTL(CR,0x22);
 262   1              
 263   1              // read the boundary register - pointing to the beginning of the packet
 264   1              bnry = readRTL(BNRY) ;
 265   1              
 266   1              // return if there is no packet in the buffer
 267   1              if( bnry == i )
 268   1                      return 0;
 269   1              
 270   1      
 271   1              // clear the packet received interrupt flag
 272   1              writeRTL(ISR, (1<<ISR_PRX));
 273   1              
 274   1              // the boundary pointer is invalid, reset the contents of the buffer and exit
 275   1              if( (bnry >= RXSTOP_INIT) || (bnry < RXSTART_INIT) )
 276   1              {
 277   2                      writeRTL(BNRY, RXSTART_INIT);
 278   2                      writeRTL(CR, 0x62);
 279   2                      writeRTL(CURR, RXSTART_INIT);
 280   2                      writeRTL(CR, 0x22);
 281   2                      
 282   2                      return 0;
 283   2              }
 284   1      
 285   1              // initiate DMA to transfer the RTL8019 packet header
 286   1          writeRTL(RBCR0, 4);
 287   1          writeRTL(RBCR1, 0);
 288   1          writeRTL(RSAR0, 0);
 289   1          writeRTL(RSAR1, bnry);
 290   1          writeRTL(CR, 0x0A);
 291   1              for(i=0;i<4;i++)
 292   1                      pageheader[i] = readRTL(RDMAPORT);
 293   1              
 294   1              // end the DMA operation
 295   1          writeRTL(CR, 0x22);
 296   1          for(i = 0; i <= 20; i++)
 297   1              if(readRTL(ISR) & 1<<6)
 298   1                  break;
 299   1          writeRTL(ISR, 1<<6);
 300   1      
 301   1              
 302   1              rxlen = (pageheader[enetpacketLenH]<<8) + pageheader[enetpacketLenL];
C51 COMPILER V7.06   RTL8019                                                               04/05/2006 12:13:02 PAGE 6   

 303   1              nextPage = pageheader[nextblock_ptr] ;
 304   1              
 305   1              currentRetreiveAddress = (bnry<<8) + 4;
 306   1              
 307   1              // if the nextPage pointer is invalid, the packet is not ready yet - exit
 308   1              if( (nextPage >= RXSTOP_INIT) || (nextPage < RXSTART_INIT) )
 309   1                      return 0;
 310   1          
 311   1          return rxlen-4;
 312   1      }
 313          
 314          
 315          void RTL8019retreivePacketData(unsigned char * localBuffer, unsigned int length)
 316          {
 317   1              unsigned int i;
 318   1              
 319   1              // initiate DMA to transfer the data
 320   1          writeRTL(RBCR0, (unsigned char)length);
 321   1          writeRTL(RBCR1, (unsigned char)(length>>8));
 322   1          writeRTL(RSAR0, (unsigned char)currentRetreiveAddress);
 323   1          writeRTL(RSAR1, (unsigned char)(currentRetreiveAddress>>8));
 324   1          writeRTL(CR, 0x0A);
 325   1              for(i=0;i<length;i++)
 326   1                      localBuffer[i] = readRTL(RDMAPORT);
 327   1      
 328   1              // end the DMA operation
 329   1          writeRTL(CR, 0x22);
 330   1          for(i = 0; i <= 20; i++)
 331   1              if(readRTL(ISR) & 1<<6)
 332   1                  break;
 333   1          writeRTL(ISR, 1<<6);
 334   1          
 335   1          currentRetreiveAddress += length;
 336   1          if( currentRetreiveAddress >= 0x6000 )
 337   1              currentRetreiveAddress = currentRetreiveAddress - (0x6000-0x4600) ;
 338   1      }
 339          
 340          
 341          
 342          void RTL8019endPacketRetreive(void)
 343          {
 344   1              unsigned char i;
 345   1      
 346   1              // end the DMA operation
 347   1          writeRTL(CR, 0x22);
 348   1          for(i = 0; i <= 20; i++)
 349   1              if(readRTL(ISR) & 1<<6)
 350   1                  break;
 351   1          writeRTL(ISR, 1<<6);
 352   1      
 353   1              // set the boundary register to point to the start of the next packet
 354   1          writeRTL(BNRY, nextPage);
 355   1      }
 356          //-----------------------------------------
 357          void overrun(void)
 358          {
 359   1              unsigned char data_L, resend;   
 360   1          INT16U count;
 361   1      
 362   1              data_L = readRTL(CR);
 363   1              writeRTL(CR, 0x21);
 364   1      //      Delay_1ms(2);
C51 COMPILER V7.06   RTL8019                                                               04/05/2006 12:13:02 PAGE 7   

 365   1          for(count=0;count<20000;count++);
 366   1              writeRTL(RBCR0, 0x00);
 367   1              writeRTL(RBCR1, 0x00);
 368   1              if(!(data_L & 0x04))
 369   1                      resend = 0;
 370   1              else if(data_L & 0x04)
 371   1              {
 372   2                      data_L = readRTL(ISR);
 373   2                      if((data_L & 0x02) || (data_L & 0x08))
 374   2                      resend = 0;
 375   2                  else
 376   2                      resend = 1;
 377   2              }
 378   1              
 379   1              writeRTL(TCR, 0x02);
 380   1              writeRTL(CR, 0x22);
 381   1              writeRTL(BNRY, RXSTART_INIT);
 382   1              writeRTL(CR, 0x62);
 383   1              writeRTL(CURR, RXSTART_INIT);
 384   1              writeRTL(CR, 0x22);
 385   1              writeRTL(ISR, 0x10);
 386   1              writeRTL(TCR, TCR_INIT);
 387   1              
 388   1              writeRTL(ISR, 0xFF);
 389   1      }
 390          
 391          
 392          
 393          
 394          
 395          
 396          void initRTL8019(void)
 397          {
 398   1      //    INT8U  temp;
 399   1          INT16U COUNT;
 400   1              RTL8019setupPorts();
 401   1              
 402   1              HARD_RESET_RTL8019();
 403   1              
 404   1              // do soft reset
 405   1              writeRTL( ISR, readRTL(ISR) ) ;
 406   1      //      Delay_10ms(5);
 407   1      
 408   1          for(COUNT=0;COUNT<15000;COUNT++);
 409   1      
 410   1              writeRTL(CR,0x21);       // stop the NIC, abort DMA, page 0
 411   1      //      Delay_1ms(2);               // make sure nothing is coming in or going out
 412   1          for(COUNT=0;COUNT<2000;COUNT++);
 413   1      
 414   1              writeRTL(DCR, DCR_INIT);    // 0x58
 415   1              writeRTL(RBCR0,0x00);
 416   1              writeRTL(RBCR1,0x00);
 417   1              writeRTL(RCR,0x04);
 418   1              writeRTL(TPSR, TXSTART_INIT);
 419   1              writeRTL(TCR,0x02);
 420   1              writeRTL(PSTART, RXSTART_INIT);
 421   1              writeRTL(BNRY, RXSTART_INIT);
 422   1              writeRTL(PSTOP, RXSTOP_INIT);
 423   1              writeRTL(CR, 0x61);
 424   1      //      Delay_1ms(2);
 425   1          for(COUNT=0;COUNT<2000;COUNT++);
 426   1              writeRTL(CURR, RXSTART_INIT);
C51 COMPILER V7.06   RTL8019                                                               04/05/2006 12:13:02 PAGE 8   

 427   1              
 428   1              writeRTL(PAR0+0, MYMAC_0);
 429   1              writeRTL(PAR0+1, MYMAC_1);
 430   1              writeRTL(PAR0+2, MYMAC_2);
 431   1              writeRTL(PAR0+3, MYMAC_3);
 432   1              writeRTL(PAR0+4, MYMAC_4);
 433   1              writeRTL(PAR0+5, MYMAC_5);
 434   1      /*
 435   1      temp=readRTL(CR+0);
 436   1      Uart0_printR(&temp,1);
 437   1      temp=readRTL(PAR0+0);
 438   1      Uart0_printR(&temp,1);
 439   1      temp=readRTL(PAR0+1);
 440   1      Uart0_printR(&temp,1);*/
 441   1                
 442   1              writeRTL(CR,0x21);
 443   1              writeRTL(DCR, DCR_INIT);
 444   1              writeRTL(CR,0x22);
 445   1              writeRTL(ISR,0xFF);
 446   1              writeRTL(IMR, IMR_INIT);
 447   1              writeRTL(TCR, TCR_INIT);
 448   1              
 449   1              writeRTL(CR, 0x22);     // start the NIC
 450   1      
 451   1      }
 452          
 453          
 454          void processRTL8019Interrupt(void)
 455          {
 456   1              unsigned char byte = readRTL(ISR);
 457   1              
 458   1              if( byte & (1<<ISR_OVW) )
 459   1                      overrun();
 460   1      
 461   1      }
 462          
 463          /*
 464          unsigned char RTL8019ReceiveEmpty(void)
 465          {
 466                  unsigned char temp;
 467          
 468                  // read CURR from page 1
 469                  writeRTL(CR,0x62);
 470                  temp = readRTL(CURR);
 471                  
 472                  // return to page 0
 473                  writeRTL(CR,0x22);
 474                  
 475                  return ( readRTL(BNRY) == temp );
 476                  
 477          }*/
 478          
 479          void RTl8019_int(void) interrupt 0
 480          { // Uart0_print("pack in\n");
 481   1         OSSemPost(Sem_RecPackage);
 482   1      }
 483          
 484          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1266    ----
C51 COMPILER V7.06   RTL8019                                                               04/05/2006 12:13:02 PAGE 9   

   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      3      20
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   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 + -