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

📄 cp220x_core.lst

📁 cf8020+cp2200(网络)的驱动实现
💻 LST
📖 第 1 页 / 共 3 页
字号:
 221   1         // Auto-Negotiation Synchronization (Section 15.2 of CP220x Datasheet)
 222   1         //--------------------------------------------------------------------------
 223   1      //自动协商同步
 224   1         // Step 1: Disable the PHY
 225   1         PHYCN = 0x00;  //禁止phy
 226   1         
 227   1         // Step 2: Enable the PHY with link integrity test and auto-negotiation 
 228   1         // turned off
 229   1            
 230   1            // A. Disable the Transmitter Power Save Option and Configure Options
 231   1            TXPWR = 0x80;//禁止传输电源
 232   1            PHYCF = ( SMSQ | JABBER | ADPAUSE | AUTOPOL );//配置phy工作方式
 233   1      
 234   1            // B. Enable the Physical Layer
 235   1            PHYCN = PHYEN;//允许phy
 236   1      
 237   1            // C. Wait for the physical layer to power up
 238   1            wait_ms(10);//等待phy层上电完成
 239   1      
 240   1            // D. Enable the Transmitter and Receiver
 241   1            PHYCN = ( PHYEN | TXEN | RXEN );//允许物理层开始工作
C51 COMPILER V7.09   CP220X_CORE                                                           07/27/2007 15:11:23 PAGE 5   

 242   1         
 243   1         // Step 3: Poll the Wake-on-Lan Interrupt
 244   1            
 245   1            // A. Clear Interrupt Flags
 246   1            temp_char = INT1;//清除中断标志
 247   1      
 248   1            // B. Start a new timeout for 1.5 seconds
 249   1            reset_timeout(ONE_SECOND+ONE_SECOND/2);
 250   1            
 251   1            // C. Check for a signal
 252   1            while(1)
 253   1            {
 254   2               // If a signal is detected, wait 250 ms, then continue
 255   2               if(INT1RD & WAKEINT){//如果检测到信息,再延时250ms
 256   3                  wait_ms(250);
 257   3                  break;
 258   3               }
 259   2      
 260   2               // If no signal is deteced, wait 1.5s, then continue
 261   2               if(timeout_expired()){//1.5秒超时,也继续
 262   3                  break;
 263   3               }
 264   2      
 265   2            }
 266   1      
 267   1      
 268   1              AB4_LED1 = !AB4_LED1;
 269   1         //--------------------------------------------------------------------------
 270   1         // Physical Layer Initialization (Section 15.7 of CP220x Datasheet)
 271   1         //--------------------------------------------------------------------------
 272   1         //物理层初始化
 273   1         // Step 1: Synchronization procedure implemented above
 274   1      
 275   1         // Step 2: Disable the physical layer
 276   1         PHYCN = 0x00; 
 277   1         
 278   1         // Step 3: Configure the desired physical layer options including 
 279   1         // auto-negotiation and link integrity
 280   1         PHYCF = ( SMSQ | LINKINTG | JABBER | AUTONEG | ADPAUSE | AUTOPOL );
 281   1        
 282   1         // Step 4: Enable the physcial layer
 283   1            
 284   1            // A. Enable the Physical Layer
 285   1            PHYCN = PHYEN;
 286   1      
 287   1            // B. Wait for the physical layer to power up
 288   1            wait_ms(10);
 289   1      //      for(temp_char=0; temp_char<250;temp_char++)
 290   1      //              ;
 291   1      
 292   1            // C. Enable the Transmitter and Receiver
 293   1            // Auto-negotiation begins now
 294   1            PHYCN = ( PHYEN | TXEN | RXEN );
 295   1        
 296   1      
 297   1         // Step 5: Wait for auto-negotiation to complete
 298   1      //              for(temp_char=0; temp_char<250;temp_char++)
 299   1      //              ;
 300   1            // Clear INT1 Interrupt Flags
 301   1            temp_char = INT1;
 302   1              
 303   1            // Start a six second timeout
C51 COMPILER V7.09   CP220X_CORE                                                           07/27/2007 15:11:23 PAGE 6   

 304   1            reset_timeout(6*ONE_SECOND);
 305   1        
 306   1            // Check for autonegotiation fail or complete flag
 307   1           while(1){//检查网络是否连接,返回连接状态
 308   2               // If Auto-Negotiation Completes/Fails, break
 309   2               if(INT1RD & (ANCINT | ANFINT)){
 310   3                  break;            
 311   3               }
 312   2            
 313   2               // If Timeout Expires, break
 314   2               if(timeout_expired()){
 315   3                  break;            
 316   3               }
 317   2            }
 318   1      
 319   1      
 320   1            // Mask out all bits except for auto negotiation bits 
 321   1            temp_char = INT1RD;
 322   1            temp_char &= (ANCINT | ANFINT);
 323   1      
 324   1            // Check if Auto-Negotiation has FAILED 
 325   1            if(temp_char & ANFINT){
 326   2            
 327   2               // Auto-Negotiation has failed
 328   2               retval = LINK_ERROR;
 329   2      
 330   2               #if(UART_ENABLED)
                       printf("Auto-Negotiation Failed -- Check Network Cable");
                       #endif 
 333   2         
 334   2            } else 
 335   1         
 336   1            // Check if Auto-Negotiation has PASSED   
 337   1            if(temp_char == ANCINT){
 338   2            
 339   2               // Auto-Negotiation has passed
 340   2               retval = 0;
 341   2      
 342   2               // Enable Link LED and Activity LED                         
 343   2               IOPWR = 0x0C;   
 344   2                                       AB4_LED1 = 0;
 345   2                       AB4_LED2 = 1;
 346   2               
 347   2               #if(UART_ENABLED)
                       printf("Auto-Negotiation Passed\n");
                       #endif                    
 350   2      
 351   2            } else 
 352   1         
 353   1            // Timeout Occured.   
 354   1            { 
 355   2                // Timeout
 356   2               retval = LINK_ERROR;
 357   2                 // IOPWR = 0x0C;  
 358   2               #if(UART_ENABLED)
                       printf("*** TIMEOUT \n");
                       #endif
 361   2            }
 362   1      
 363   1         return retval;
 364   1           
 365   1      }
C51 COMPILER V7.09   CP220X_CORE                                                           07/27/2007 15:11:23 PAGE 7   

 366          
 367          
 368          //-----------------------------------------------------------------------------
 369          // MAC_Init
 370          //-----------------------------------------------------------------------------
 371          //
 372          // Return Value : None
 373          // Parameters   : None
 374          //
 375          // Initializes the MAC and programs the MAC address using the MAC address
 376          // stored at address 0x1FFA in CP220x Flash.
 377          //-----------------------------------------------------------------------------
 378          void MAC_Init(void)
 379          {  
 380   1      
 381   1         // Check the duplex mode and perform duplex-mode specific initializations
 382   1         if(PHYCN & 0x10){
 383   2            
 384   2            // The device is in full-duplex mode, configure MAC registers
 385   2            // Padding is turned on.
 386   2            MAC_Write(MACCF, 0x40B3);//配置全双工模式
 387   2            MAC_Write(IPGT, 0x0015);
 388   2            
 389   2         } else {
 390   2      
 391   2            // The device is in half-duplex mode, configure MAC registers
 392   2            // Padding is turned off.
 393   2            MAC_Write(MACCF, 0x4012);//配置半双工模式
 394   2            MAC_Write(IPGT, 0x0012);
 395   2      
 396   2         }
 397   1      
 398   1         // Configure the IPGR register
 399   1         MAC_Write(IPGR, 0x0C12);
 400   1      
 401   1         // Configure the MAXLEN register to 1518 bytes
 402   1         MAC_Write(MAXLEN, 0x05EE);//配置读写最大数
 403   1      
 404   1         // Copy MAC Address Stored in Flash to MYMAC
 405   1         FLASHADDRH = 0x1F;//读出flash 中的 mac
 406   1         FLASHADDRL = 0xFA;
 407   1      
 408   1         MYMAC.Char[0] = FLASHAUTORD;
 409   1         MYMAC.Char[1] = FLASHAUTORD;
 410   1         MYMAC.Char[2] = FLASHAUTORD;
 411   1         MYMAC.Char[3] = FLASHAUTORD;
 412   1         MYMAC.Char[4] = FLASHAUTORD;
 413   1         MYMAC.Char[5] = FLASHAUTORD;      
 414   1      
 415   1         my_hwaddr[0] = MYMAC.Char[0];
 416   1         my_hwaddr[1] = MYMAC.Char[1];
 417   1         my_hwaddr[2] = MYMAC.Char[2];
 418   1         my_hwaddr[3] = MYMAC.Char[3];
 419   1         my_hwaddr[4] = MYMAC.Char[4];
 420   1         my_hwaddr[5] = MYMAC.Char[5];      
 421   1      
 422   1         // Program the MAC address
 423   1         MAC_SetAddress(&MYMAC); 
 424   1      
 425   1         // Enable Reception and configure Loopback mode
 426   1         MAC_Write(MACCN, 0x0001);           // Enable Reception without loopback//开始接收
 427   1      
C51 COMPILER V7.09   CP220X_CORE                                                           07/27/2007 15:11:23 PAGE 8   

 428   1      }
 429          
 430          //-----------------------------------------------------------------------------
 431          // Indirect MAC Register Access
 432          //-----------------------------------------------------------------------------
 433          
 434          //-----------------------------------------------------------------------------
 435          // MAC_Write
 436          //-----------------------------------------------------------------------------
 437          //
 438          // Return Value : None
 439          // Parameters   : 
 440          //   1)  unsigned char mac_reg_offset - indirect register address
 441          //   2)  unsigned int mac_reg_data - the data to write to mac_reg_offset.
 442          //
 443          // Writes the value <mac_reg_data> to the indirect MAC register located at 
 444          // <mac_reg_offset>.
 445          //-----------------------------------------------------------------------------
 446          void MAC_Write(unsigned char mac_reg_offset, unsigned int mac_reg_data)
 447          {

⌨️ 快捷键说明

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