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

📄 main.lst

📁 cp2200网卡的tcp/ip源程序( 包含驱动),十分难得哦
💻 LST
📖 第 1 页 / 共 3 页
字号:
 272   3               event_word &= (~EVENT_ETH_ARRIVED);
 273   3               EA = 1;
 274   3               
 275   3               // Allocate a buffer and read frame from CS8900A
 276   3              //       inbuf = (UCHAR xdata *)malloc(1000);
 277   3              //       num_bytes = CP220x_Receive(inbuf, sizeof(inbuf));
 278   3               inbuf = rcve_frame();
 279   3                 if (inbuf != NULL)
 280   3               {
 281   4                  // Process the received Ethernet frame 
 282   4                  eth_rcve(inbuf); 
 283   4               
 284   4                  // If the memory allocated for the rcve message has
 285   4                  // not already been freed then free it now
 286   4                  if (rcve_buf_allocated)
 287   4                  {
 288   5      //               free(inbuf);
 289   5                     rcve_buf_allocated = FALSE;
 290   5                  }
 291   4               }
 292   3                
 293   3               
 294   3                
 295   3             
 296   3            }
 297   2            
 298   2            // See if TCP retransmit timer has expired                       
 299   2            else if (event_word_copy & EVENT_TCP_RETRANSMIT)
 300   2            {
 301   3               event_word &= (~EVENT_TCP_RETRANSMIT);
 302   3               EA = 1;
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 6   

 303   3               tcp_retransmit();
 304   3                      }
 305   2      
 306   2            // See if TCP inactivity timer has expired
 307   2            else if (event_word_copy & EVENT_TCP_INACTIVITY)
 308   2            {
 309   3               event_word &= (~EVENT_TCP_INACTIVITY);
 310   3               EA = 1;
 311   3               tcp_inactivity();
 312   3                      }
 313   2      
 314   2            // See if ARP retransmit timer has expired
 315   2                      else if (event_word_copy & EVENT_ARP_RETRANSMIT)
 316   2            {
 317   3               event_word &= (~EVENT_ARP_RETRANSMIT);
 318   3               EA = 1;
 319   3               arp_retransmit();
 320   3                      }
 321   2      
 322   2            // See if it is time to age the ARP cache
 323   2            else if (event_word_copy & EVENT_AGE_ARP_CACHE)
 324   2            {
 325   3               event_word &= (~EVENT_AGE_ARP_CACHE);
 326   3                              EA = 1;
 327   3               age_arp_cache();
 328   3                      }
 329   2      
 330   2                      // See if it is time to read the analog inputs
 331   2                      else if (event_word_copy & EVENT_READ_ANALOG)
 332   2            {
 333   3               event_word &= (~EVENT_READ_ANALOG);
 334   3               EA = 1;
 335   3                              // Read one of the 3 analog inputs each time
 336   3                              read_analog_inputs();
 337   3            }
 338   2      
 339   2                      // See if an RS232 message has arrived.  It is
 340   2            // not handled - RS232 is used for sending only
 341   2                      else if (event_word_copy & EVENT_RS232_ARRIVED)
 342   2            {
 343   3               event_word &= (~EVENT_RS232_ARRIVED);
 344   3               EA = 1;
 345   3            }
 346   2         }
 347   1      }
*** WARNING C280 IN LINE 189 OF MAIN.C: 'num_bytes': unreferenced local variable
 348          
 349          void CP220x_RST_Low(void)
 350          {
 351   1         P4 &= ~0x20;                        // Set P4.5 Low
 352   1      }
 353          
 354          void CP220x_RST_High(void)
 355          {
 356   1         P4 |= 0x20;                        // Set P4.5 High
 357   1      }
 358          
 359          unsigned char PHY_Init()
 360          {
 361   1         unsigned char temp_char;
 362   1         unsigned char retval = 0;
 363   1         
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 7   

 364   1         //--------------------------------------------------------------------------
 365   1         // Auto-Negotiation Synchronization (Section 15.2 of CP220x Datasheet)
 366   1         //--------------------------------------------------------------------------
 367   1      
 368   1         // Step 1: Disable the PHY
 369   1         PHYCN = 0x00;  
 370   1         
 371   1         // Step 2: Enable the PHY with link integrity test and auto-negotiation 
 372   1         // turned off
 373   1            
 374   1            // A. Disable the Transmitter Power Save Option and Configure Options
 375   1            TXPWR = 0x80;
 376   1            PHYCF = ( SMSQ | JABBER | ADPAUSE | AUTOPOL );
 377   1      
 378   1            // B. Enable the Physical Layer
 379   1            PHYCN = PHYEN;
 380   1      Delay1ms(200);
 381   1         Delay1ms(200);
 382   1         Delay1ms(200);
 383   1            // C. Wait for the physical layer to power up
 384   1           // wait_ms(10);
 385   1      
 386   1            // D. Enable the Transmitter and Receiver
 387   1            PHYCN = ( PHYEN | TXEN | RXEN );
 388   1         
 389   1         // Step 3: Poll the Wake-on-Lan Interrupt
 390   1            Delay1ms(200);
 391   1         Delay1ms(200);
 392   1         Delay1ms(200);
 393   1         Delay1ms(200);
 394   1         Delay1ms(200);
 395   1         Delay1ms(200);
 396   1         Delay1ms(200);
 397   1         Delay1ms(200);
 398   1         Delay1ms(200);
 399   1            // A. Clear Interrupt Flags
 400   1            temp_char = INT1;
 401   1      
 402   1            // B. Start a new timeout for 1.5 seconds
 403   1      //      reset_timeout(ONE_SECOND+ONE_SECOND/2);
 404   1            
 405   1            // C. Check for a signal
 406   1           
 407   1               // If no signal is deteced, wait 1.5s, then continue
 408   1      //         if(timeout_expired()){
 409   1      //            break;
 410   1       //        }
 411   1      
 412   1           
 413   1      
 414   1         //--------------------------------------------------------------------------
 415   1         // Physical Layer Initialization (Section 15.7 of CP220x Datasheet)
 416   1         //--------------------------------------------------------------------------
 417   1         
 418   1         // Step 1: Synchronization procedure implemented above
 419   1      
 420   1         // Step 2: Disable the physical layer
 421   1         PHYCN = 0x00; 
 422   1        
 423   1         // Step 3: Configure the desired physical layer options including 
 424   1         // auto-negotiation and link integrity
 425   1         PHYCF = ( SMSQ | LINKINTG | JABBER | AUTONEG | ADPAUSE | AUTOPOL );
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 8   

 426   1        
 427   1         // Step 4: Enable the physcial layer
 428   1            
 429   1            // A. Enable the Physical Layer
 430   1            PHYCN = PHYEN;
 431   1       Delay1ms(200);
 432   1         Delay1ms(200);
 433   1         Delay1ms(200);
 434   1            // B. Wait for the physical layer to power up
 435   1      //      wait_ms(10);
 436   1      
 437   1            // C. Enable the Transmitter and Receiver
 438   1            // Auto-negotiation begins now
 439   1            PHYCN = ( PHYEN | TXEN | RXEN );
 440   1        
 441   1      
 442   1         // Step 5: Wait for auto-negotiation to complete
 443   1      
 444   1            // Clear INT1 Interrupt Flags
 445   1            temp_char = INT1;
 446   1              Delay1ms(200);
 447   1         Delay1ms(200);
 448   1         Delay1ms(200);
 449   1          Delay1ms(200);
 450   1         Delay1ms(200);
 451   1         Delay1ms(200);
 452   1         Delay1ms(200);
 453   1         Delay1ms(200);
 454   1         Delay1ms(200); 
 455   1            // Start a six second timeout
 456   1      //      reset_timeout(6*ONE_SECOND);
 457   1        
 458   1            // Check for autonegotiation fail or complete flag
 459   1            while(1){
 460   2               // If Auto-Negotiation Completes/Fails, break
 461   2               if(INT1RD & (ANCINT | ANFINT)){
 462   3                  break;            
 463   3               }
 464   2            
 465   2             
 466   2            }
 467   1      
 468   1      
 469   1            // Mask out all bits except for auto negotiation bits 
 470   1            temp_char = INT1RD;
 471   1            temp_char &= (ANCINT | ANFINT);
 472   1      
 473   1            // Check if Auto-Negotiation has FAILED 
 474   1            if(temp_char & ANFINT){
 475   2            
 476   2               // Auto-Negotiation has failed
 477   2               retval = LINK_ERROR;
 478   2      
 479   2              
 480   2         
 481   2            } else 
 482   1         
 483   1            // Check if Auto-Negotiation has PASSED   
 484   1            if(temp_char == ANCINT){
 485   2            
 486   2               // Auto-Negotiation has passed
 487   2               retval = 0;
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 9   

 488   2      
 489   2               // Enable Link LED and Activity LED                         
 490   2               IOPWR = 0x0C;   
 491   2               
 492   2                                 
 493   2      
 494   2            } else 
 495   1         
 496   1            // Timeout Occured.   
 497   1            { 
 498   2                // Timeout
 499   2               retval = LINK_ERROR;
 500   2          
 501   2              
 502   2            }
 503   1      
 504   1         return retval;
 505   1           
 506   1      }
 507          
 508          void MAC_Init(void)
 509          {  
 510   1      
 511   1         // Check the duplex mode and perform duplex-mode specific initializations
 512   1         if(PHYCN & 0x10){
 513   2            
 514   2            // The device is in full-duplex mode, configure MAC registers
 515   2            // Padding is turned on.
 516   2            MAC_Write(MACCF, 0x40B3);
 517   2            MAC_Write(IPGT, 0x0015);
 518   2            
 519   2         } else {
 520   2      
 521   2            // The device is in half-duplex mode, configure MAC registers
 522   2            // Padding is turned off.
 523   2            MAC_Write(MACCF, 0x4012);
 524   2            MAC_Write(IPGT, 0x0012);
 525   2      
 526   2         }
 527   1      
 528   1         // Configure the IPGR register
 529   1         MAC_Write(IPGR, 0x0C12);
 530   1      
 531   1         // Configure the MAXLEN register to 1518 bytes
 532   1         MAC_Write(MAXLEN, 0x05EE);
 533   1      
 534   1         // Copy MAC Address Stored in Flash to MYMAC
 535   1         FLASHADDRH = 0x1F;
 536   1         FLASHADDRL = 0xFA;
 537   1      
 538   1         MYMAC.Char[0] = FLASHAUTORD;
 539   1         MYMAC.Char[1] = FLASHAUTORD;
 540   1         MYMAC.Char[2] = FLASHAUTORD;
 541   1         MYMAC.Char[3] = FLASHAUTORD;
 542   1         MYMAC.Char[4] = FLASHAUTORD;
 543   1         MYMAC.Char[5] = FLASHAUTORD;      
 544   1         my_hwaddr[0]=MYMAC.Char[0];
 545   1         my_hwaddr[1]=MYMAC.Char[1];
 546   1         my_hwaddr[2]=MYMAC.Char[2];
 547   1         my_hwaddr[3]=MYMAC.Char[3];
 548   1         my_hwaddr[4]=MYMAC.Char[4];
 549   1         my_hwaddr[5]=MYMAC.Char[5];
C51 COMPILER V7.50   MAIN                                                                  08/03/2006 09:32:50 PAGE 10  

⌨️ 快捷键说明

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