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

📄 cp220x_core.lst

📁 用c8051f340基于51单片机上网
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   CP220X_CORE                                                           11/04/2008 18:45:33 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE CP220X_CORE
OBJECT MODULE PLACED IN CP220x_CORE.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.exe CP220x_CORE.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // CP220x_CORE.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2006 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          // 
   9          // This file contains core functions used when accessing the CP220x.
  10          // 
  11          // FID:            
  12          // Target:         Multiple
  13          // Tool chain:     Keil C51 7.20 / Keil EVAL C51
  14          //                 Silicon Laboratories IDE version 2.72 
  15          // Command Line:   See Readme.txt
  16          // Project Name:   CP220x_Ethernet_Routines
  17          //
  18          // 
  19          //
  20          // Release 1.1
  21          //    - Configures C8051F120 SYSCLK to 98 MHz
  22          //
  23          // Release 1.0
  24          //    -Initial Release (FB)
  25          //    -30 MAY 2006
  26          //
  27          
  28          
  29          //-----------------------------------------------------------------------------
  30          // Includes
  31          //-----------------------------------------------------------------------------
  32          #include "global.h"
  33          
  34          
  35          //-----------------------------------------------------------------------------
  36          // Global Variables
  37          //-----------------------------------------------------------------------------
  38          bit full_duplex = 0;
  39          
  40          //-----------------------------------------------------------------------------
  41          // Exported Function Prototypes
  42          //-----------------------------------------------------------------------------
  43          
  44          // Initialization routines
  45          unsigned char CP220x_HW_Reset(void);
  46          unsigned char PHY_Init(void);
  47          void MAC_Init(void);
  48          
  49          // MAC read/write routines
  50          void MAC_Write(unsigned char mac_reg_offset, unsigned int mac_reg_data);
  51          void MAC_GetAddress(MACADDRESS* pMAC);
  52          void MAC_SetAddress(MACADDRESS* pMAC);
  53          
  54          // FLASH read/write/erase routines
  55          unsigned char poll_flash_busy (void);
C51 COMPILER V8.08   CP220X_CORE                                                           11/04/2008 18:45:33 PAGE 2   

  56          unsigned char CPFLASH_ByteRead (unsigned int addr);
  57          unsigned char CPFLASH_ByteWrite (unsigned int addr, char byte);
  58          unsigned char CPFLASH_PageErase (unsigned int addr);
  59          
  60          //-----------------------------------------------------------------------------
  61          // Initialization Routines
  62          //-----------------------------------------------------------------------------
  63          
  64          //-----------------------------------------------------------------------------
  65          // CP220x_HW_Reset
  66          //-----------------------------------------------------------------------------
  67          //
  68          // Return Value : 
  69          //   unsigned char - '0' on success, or one of the following error codes:
  70          //       MEM_ERROR
  71          //       OSC_ERROR
  72          //       CAL_ERROR
  73          //
  74          // Parameters   : None
  75          //
  76          // Performs Steps 1 - 5 of Reset Initialization (See Section 6.2 of the CP220x
  77          // Datasheet for more details)
  78          //-----------------------------------------------------------------------------
  79          unsigned char CP220x_HW_Reset(void)
  80          {  
  81   1         unsigned char temp_char;
  82   1      
  83   1         // Reset the CP2200 by holding the /RST pin low for at least 15 us
  84   1         CP220x_RST_Low();
  85   1         wait_ms(20);
  86   1         
  87   1         //--------------------------------------------------------------------------
  88   1         // Step 1: Wait for the reset pin to rise.
  89   1         //--------------------------------------------------------------------------
  90   1         CP220x_RST_High();
  91   1         
  92   1         //--------------------------------------------------------------------------
  93   1         // Step 2 + 3: Wait for oscillator and self initializaion to complete
  94   1         //--------------------------------------------------------------------------
  95   1         
  96   1         // Start a one second timeout
  97   1         reset_timeout(ONE_SECOND*5);
  98   1      
  99   1         // Wait for the interrupt pin to go low
 100   1         // Loop will exit successfully if interrupt detected
 101   1         // The function will return error if the reset pin goes low,
 102   1         // or the one second timeout expires
 103   1         while(INT_PIN){                        
 104   2         
 105   2            // Check the state of the reset pin     
 106   2            if(!AB4_RST_State()){
 107   3               return OSC_ERROR;
 108   3            }
 109   2            
 110   2            // Check the state of the one second timeout
 111   2            if(timeout_expired()){
 112   3               return OSC_ERROR;
 113   3            }
 114   2         }
 115   1      
 116   1         // Start a new one second timeout
 117   1         reset_timeout(ONE_SECOND);
C51 COMPILER V8.08   CP220X_CORE                                                           11/04/2008 18:45:33 PAGE 3   

 118   1         
 119   1         // Wait for Oscillator Initialization and Self Initialization to complete
 120   1         // Verify that both SELFINTR and OSCINTR are set and that 
 121   1         // INT0 is not reading 0xFF;
 122   1         do {
 123   2            temp_char = INT0RD;
 124   2            
 125   2            if(timeout_expired()){
 126   3               return CAL_ERROR;
 127   3            }
 128   2            
 129   2         } while(((temp_char & 0x30) != 0x30) || (temp_char == 0xFF)) ;        
 130   1         
 131   1         //--------------------------------------------------------------------------
 132   1         // Additional Step: Verify Communication
 133   1         //--------------------------------------------------------------------------
 134   1      
 135   1         // Verify communication
 136   1         if(RXHASHH != 0x04){
 137   2            #if(UART_ENABLED)
 138   2            puts("EMIF Failure. Check EMI0CN.");
 139   2            #endif
 140   2            return MEM_ERROR;
 141   2         }   
 142   1         
 143   1         // Read and write the RAM at 0x7FF in the transmit buffer
 144   1         RAMADDRH = 0x07;
 145   1         RAMADDRL = 0xFF;
 146   1      
 147   1         RAMTXDATA = 0x00;
 148   1         if(RAMTXDATA != 0x00){
 149   2            #if(UART_ENABLED)
 150   2            puts("EMIF Failure. Cannot set data bus to 0x00.");
 151   2            #endif
 152   2            return MEM_ERROR;
 153   2         } 
 154   1         
 155   1         RAMTXDATA = 0xFF;
 156   1         if(RAMTXDATA != 0xFF){
 157   2            #if(UART_ENABLED)
 158   2            puts("EMIF Failure. Cannot set data bus to 0xFF. Please Reset Device.");
 159   2            #endif
 160   2            return MEM_ERROR;
 161   2         } 
 162   1            
 163   1      
 164   1         #if(UART_ENABLED)
 165   1            puts("Oscillator and Self Initialization Complete\n");
 166   1         #endif
 167   1       
 168   1         //--------------------------------------------------------------------------
 169   1         // Step 4: Disable Interrupts For Events that will not be monitored
 170   1         //--------------------------------------------------------------------------   
 171   1         
 172   1         // Disable All Interrupts except for the packet received interrupt
 173   1         INT0EN = 0x03;                         
 174   1         INT1EN = 0x00;
 175   1         
 176   1         // Clear all Interrupt Flags by reading the self-clearing status registers                          
 177   1         temp_char = INT0;                      
 178   1         temp_char = INT1;                      
 179   1         
C51 COMPILER V8.08   CP220X_CORE                                                           11/04/2008 18:45:33 PAGE 4   

 180   1         return 0;
 181   1      }
 182          
 183          
 184          //-----------------------------------------------------------------------------
 185          // PHY_Init
 186          //-----------------------------------------------------------------------------
 187          //
 188          // Return Value : 
 189          //   unsigned char - '0' on success, or the following error code:
 190          //       LINK_ERROR
 191          //
 192          // Parameters   : None
 193          //
 194          // Initializes the PHY using Autonegotiation
 195          //-----------------------------------------------------------------------------
 196          unsigned char PHY_Init()
 197          {
 198   1         unsigned char temp_char;
 199   1         unsigned char retval = 0;
 200   1         
 201   1         //--------------------------------------------------------------------------
 202   1         // Auto-Negotiation Synchronization (Section 15.2 of CP220x Datasheet)
 203   1         //--------------------------------------------------------------------------
 204   1      
 205   1         // Step 1: Disable the PHY
 206   1         PHYCN = 0x00;  
 207   1         
 208   1         // Step 2: Enable the PHY with link integrity test and auto-negotiation 
 209   1         // turned off
 210   1            
 211   1            // A. Disable the Transmitter Power Save Option and Configure Options
 212   1            TXPWR = 0x80;
 213   1            PHYCF = ( SMSQ | JABBER | ADPAUSE | AUTOPOL );
 214   1      
 215   1            // B. Enable the Physical Layer
 216   1            PHYCN = PHYEN;
 217   1      
 218   1            // C. Wait for the physical layer to power up
 219   1            wait_ms(10);
 220   1      
 221   1            // D. Enable the Transmitter and Receiver
 222   1            PHYCN = ( PHYEN | TXEN | RXEN );
 223   1         
 224   1         // Step 3: Poll the Wake-on-Lan Interrupt
 225   1            
 226   1            // A. Clear Interrupt Flags
 227   1            temp_char = INT1;
 228   1      
 229   1            // B. Start a new timeout for 1.5 seconds
 230   1            reset_timeout(ONE_SECOND+ONE_SECOND/2);
 231   1            
 232   1            // C. Check for a signal
 233   1            while(1)
 234   1            {
 235   2               // If a signal is detected, wait 250 ms, then continue
 236   2               if(INT1RD & WAKEINT){
 237   3                  wait_ms(250);
 238   3                  break;
 239   3               }
 240   2      
 241   2               // If no signal is deteced, wait 1.5s, then continue
C51 COMPILER V8.08   CP220X_CORE                                                           11/04/2008 18:45:33 PAGE 5   

 242   2               if(timeout_expired()){
 243   3                  break;
 244   3               }
 245   2      
 246   2            }
 247   1      
 248   1         //--------------------------------------------------------------------------
 249   1         // Physical Layer Initialization (Section 15.7 of CP220x Datasheet)
 250   1         //--------------------------------------------------------------------------
 251   1         
 252   1         // Step 1: Synchronization procedure implemented above
 253   1      
 254   1         // Step 2: Disable the physical layer
 255   1         PHYCN = 0x00; 
 256   1         
 257   1         // Step 3: Configure the desired physical layer options including 
 258   1         // auto-negotiation and link integrity
 259   1         PHYCF = ( SMSQ | LINKINTG | JABBER | AUTONEG | ADPAUSE | AUTOPOL );
 260   1        
 261   1         // Step 4: Enable the physcial layer
 262   1            
 263   1            // A. Enable the Physical Layer
 264   1            PHYCN = PHYEN;
 265   1      
 266   1            // B. Wait for the physical layer to power up
 267   1            wait_ms(10);
 268   1      
 269   1            // C. Enable the Transmitter and Receiver
 270   1            // Auto-negotiation begins now
 271   1            PHYCN = ( PHYEN | TXEN | RXEN );
 272   1        
 273   1      
 274   1         // Step 5: Wait for auto-negotiation to complete
 275   1      
 276   1            // Clear INT1 Interrupt Flags
 277   1            temp_char = INT1;
 278   1              
 279   1            // Start a six second timeout
 280   1            reset_timeout(6*ONE_SECOND);
 281   1        
 282   1            // Check for autonegotiation fail or complete flag
 283   1            while(1){
 284   2               // If Auto-Negotiation Completes/Fails, break
 285   2               if(INT1RD & (ANCINT | ANFINT)){
 286   3                  break;            
 287   3               }
 288   2            
 289   2               // If Timeout Expires, break
 290   2               if(timeout_expired()){
 291   3                  break;            
 292   3               }
 293   2            }
 294   1      
 295   1      
 296   1            // Mask out all bits except for auto negotiation bits 
 297   1            temp_char = INT1RD;
 298   1            temp_char &= (ANCINT | ANFINT);
 299   1      
 300   1            // Check if Auto-Negotiation has FAILED 
 301   1            if(temp_char & ANFINT){
 302   2            
 303   2               // Auto-Negotiation has failed
C51 COMPILER V8.08   CP220X_CORE                                                           11/04/2008 18:45:33 PAGE 6   

 304   2               retval = LINK_ERROR;
 305   2      
 306   2               #if(UART_ENABLED)
 307   2               puts("Auto-Negotiation Failed -- Check Network Cable");
 308   2               #endif 
 309   2         
 310   2            } else 
 311   1         
 312   1            // Check if Auto-Negotiation has PASSED   
 313   1            if(temp_char == ANCINT){
 314   2            
 315   2               // Auto-Negotiation has passed
 316   2               retval = 0;

⌨️ 快捷键说明

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