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

📄 cp220x_core.lst

📁 cf8020+cp2200(网络)的驱动实现
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.09   CP220X_CORE                                                           07/27/2007 15:11:23 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE CP220X_CORE
OBJECT MODULE PLACED IN CP220x_CORE.OBJ
COMPILER INVOKED BY: F:\Keil\C51\BIN\C51.EXE CP220x_CORE.c LARGE BROWSE DEBUG OBJECTEXTEND

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          //extern struct
  37          //
  38          extern unsigned char my_hwaddr[];
  39          //-----------------------------------------------------------------------------
  40          // Global Variables
  41          //-----------------------------------------------------------------------------
  42          bit full_duplex = 0;
  43          
  44          //-----------------------------------------------------------------------------
  45          // Exported Function Prototypes
  46          //-----------------------------------------------------------------------------
  47          
  48          // Initialization routines
  49          unsigned char CP220x_HW_Reset(void);
  50          unsigned char PHY_Init(void);
  51          void MAC_Init(void);
  52          
  53          // MAC read/write routines
  54          void MAC_Write(unsigned char mac_reg_offset, unsigned int mac_reg_data);
  55          void MAC_GetAddress(MACADDRESS* pMAC);
C51 COMPILER V7.09   CP220X_CORE                                                           07/27/2007 15:11:23 PAGE 2   

  56          void MAC_SetAddress(MACADDRESS* pMAC);
  57          
  58          // FLASH read/write/erase routines
  59          unsigned char poll_flash_busy (void);
  60          unsigned char CPFLASH_ByteRead (unsigned int addr);
  61          unsigned char CPFLASH_ByteWrite (unsigned int addr, char byte);
  62          unsigned char CPFLASH_PageErase (unsigned int addr);
  63          
  64          //-----------------------------------------------------------------------------
  65          // Initialization Routines
  66          //-----------------------------------------------------------------------------
  67          
  68          //-----------------------------------------------------------------------------
  69          // CP220x_HW_Reset
  70          //-----------------------------------------------------------------------------
  71          //
  72          // Return Value : 
  73          //   unsigned char - '0' on success, or one of the following error codes:
  74          //       MEM_ERROR
  75          //       OSC_ERROR
  76          //       CAL_ERROR
  77          //
  78          // Parameters   : None
  79          //
  80          // Performs Steps 1 - 5 of Reset Initialization (See Section 6.2 of the CP220x
  81          // Datasheet for more details)
  82          //-----------------------------------------------------------------------------
  83          unsigned char CP220x_HW_Reset(void)
  84          {  
  85   1         unsigned char temp_char;
  86   1      
  87   1         // Reset the CP2200 by holding the /RST pin low for at least 15 us
  88   1            #if(UART_ENABLED)
                            printf("enter CP220x_HW_Reset");
                    #endif
  91   1         CP220x_RST_Low();//将cp2200的复位脚置低
  92   1         wait_ms(20);
  93   1         
  94   1         //--------------------------------------------------------------------------
  95   1         // Step 1: Wait for the reset pin to rise.
  96   1         //--------------------------------------------------------------------------
  97   1         CP220x_RST_High();//将cp2200的复位脚置低
  98   1         
  99   1         //--------------------------------------------------------------------------
 100   1         // Step 2 + 3: Wait for oscillator and self initializaion to complete
 101   1         //--------------------------------------------------------------------------
 102   1            #if(UART_ENABLED)
                            printf("CP220x_RST_High");
                    #endif
 105   1         
 106   1         // Start a one second timeout
 107   1         reset_timeout(ONE_SECOND*5);
 108   1      
 109   1         // Wait for the interrupt pin to go low
 110   1         // Loop will exit successfully if interrupt detected
 111   1         // The function will return error if the reset pin goes low,
 112   1         // or the one second timeout expires
 113   1              while(INT_PIN){//等待中断脚变低,                        
 114   2                 #if(UART_ENABLED)
                            printf(" in INT_PIN_AB4_RST_State");
                    #endif
 117   2            // Check the state of the reset pin     
C51 COMPILER V7.09   CP220X_CORE                                                           07/27/2007 15:11:23 PAGE 3   

 118   2            if(!AB4_RST_State()){//如果等待reset信号,退出,返回错误
 119   3               return OSC_ERROR;
 120   3            }
 121   2            
 122   2            // Check the state of the one second timeout
 123   2                 #if(UART_ENABLED)
                            printf(" in INT_PIN_timeout_expired");
                    #endif
 126   2            if(timeout_expired()){//等待超时退出,返回错误
 127   3               return OSC_ERROR;
 128   3            }
 129   2         }
 130   1            #if(UART_ENABLED)
                            printf(" out INT_PIN");
                    #endif
 133   1         // Start a new one second timeout
 134   1         reset_timeout(ONE_SECOND);
 135   1         
 136   1         // Wait for Oscillator Initialization and Self Initialization to complete
 137   1         // Verify that both SELFINTR and OSCINTR are set and that 
 138   1         // INT0 is not reading 0xFF;
 139   1              do {//等待晶震初始完毕,返回INT0正常
 140   2            temp_char = INT0RD;
 141   2            
 142   2            if(timeout_expired()){//等待超时,返回错误
 143   3               return CAL_ERROR;
 144   3            }
 145   2            
 146   2         } while(((temp_char & 0x30) != 0x30) || (temp_char == 0xFF)) ;           
 147   1             #if(UART_ENABLED)
                            printf(" out ait for Oscillator Initialization");
                    #endif
 150   1         //--------------------------------------------------------------------------
 151   1         // Additional Step: Verify Communication
 152   1         //--------------------------------------------------------------------------
 153   1      
 154   1         // Verify communication
 155   1         if(RXHASHH != 0x04){//检查是否可以正常通信了
 156   2            #if(UART_ENABLED)
                    printf("EMIF Failure. Check EMI0CN.");
                    #endif
 159   2            return MEM_ERROR;
 160   2         }   
 161   1         
 162   1         // Read and write the RAM at 0x7FF in the transmit buffer
 163   1         RAMADDRH = 0x07;
 164   1         RAMADDRL = 0xFF;
 165   1      
 166   1         RAMTXDATA = 0x00;
 167   1         if(RAMTXDATA != 0x00){
 168   2            #if(UART_ENABLED)
                    printf("EMIF Failure. Cannot set data bus to 0x00.");
                    #endif
 171   2            return MEM_ERROR;
 172   2         } 
 173   1         
 174   1         RAMTXDATA = 0xFF;
 175   1         if(RAMTXDATA != 0xFF){
 176   2            #if(UART_ENABLED)
                    printf("EMIF Failure. Cannot set data bus to 0xFF. Please Reset Device.");
                    #endif
 179   2            return MEM_ERROR;
C51 COMPILER V7.09   CP220X_CORE                                                           07/27/2007 15:11:23 PAGE 4   

 180   2         } 
 181   1            
 182   1      
 183   1         #if(UART_ENABLED)
                    printf("Oscillator and Self Initialization Complete\n");
                 #endif
 186   1       
 187   1         //--------------------------------------------------------------------------
 188   1         // Step 4: Disable Interrupts For Events that will not be monitored
 189   1         //--------------------------------------------------------------------------   
 190   1         
 191   1         // Disable All Interrupts except for the packet received interrupt
 192   1         INT0EN = 0x03;     //关中断                    
 193   1         INT1EN = 0x00;
 194   1         
 195   1         // Clear all Interrupt Flags by reading the self-clearing status registers                          
 196   1         temp_char = INT0;  //清空中断寄存器                    
 197   1         temp_char = INT1;                      
 198   1         
 199   1         return 0;
 200   1      }
 201          
 202          
 203          //-----------------------------------------------------------------------------
 204          // PHY_Init
 205          //-----------------------------------------------------------------------------
 206          //
 207          // Return Value : 
 208          //   unsigned char - '0' on success, or the following error code:
 209          //       LINK_ERROR
 210          //
 211          // Parameters   : None
 212          //
 213          // Initializes the PHY using Autonegotiation
 214          //-----------------------------------------------------------------------------
 215          unsigned char PHY_Init()
 216          {
 217   1         unsigned char temp_char;
 218   1         unsigned char retval = 0;
 219   1         
 220   1         //--------------------------------------------------------------------------

⌨️ 快捷键说明

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