📄 cp2200.lst
字号:
C51 COMPILER V7.06 CP2200 12/04/2007 13:46:18 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE CP2200
OBJECT MODULE PLACED IN cp2200.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE cp2200.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*==========================================================
2 //CP220X芯片底层驱动,使用89c51芯片,数据地址总线复用
3
4 ==========================================================*/
5 #include "reg.h"
6 #include "ne2000.h"
7 #include <stdio.h>
8 #include <absacc.h>
9 #include "netcomm.h"
10 extern union NetNode xdata myNode;
11 volatile INT8U xdata Count1ms;
12 unsigned int num_bytes;
13 void Delay1ms(unsigned char T)
14 {
15 1 Count1ms=T;
16 1 while (Count1ms);
17 1 }
18
19
20
21 /*==========================================================
22 // function: write data to add
23 // Parameter: reg address
24 // data send data
25 // return: void
26 // note: datasheet page 98
27 ==========================================================*/
28 /*void WriteReg(unsigned char add,unsigned char value)
29 {
30 unsigned char xdata *xdata regpointer;
31 regpointer = (unsigned char xdata *)0x8000;
32 regpointer = regpointer + add;
33 *regpointer = value;
34 }*/
35
36 /*==========================================================
37 // function: write data to add
38 // Parameter: reg address
39 // data send data
40 // return: void
41 // note: datasheet page 98
42 ==========================================================*/
43 /*unsigned char ReadReg(unsigned char reg)
44 {
45 unsigned char xdata returnvalue;
46
47 unsigned char xdata *xdata regpointer;
48
49 regpointer =(unsigned char *)0x8000; //8000这个位置存放寄存器的值
50 regpointer = regpointer + reg;
51 returnvalue = *regpointer;
52 return returnvalue;
53 }*/
54
55 /*==========================================================
C51 COMPILER V7.06 CP2200 12/04/2007 13:46:18 PAGE 2
56 // function: Initializes the PHY using Autonegotiation
57 // Parameter: none
58 // return: unsigned char 0 on success, or the following error code
59 // note: cp220x_core.c, datasheet page 88
60 ==========================================================*/
61 unsigned char PHY_Init()
62 {
63 1 unsigned char temp_char,i;
64 1 unsigned char retval = 0;
65 1 printf ("\STATA PHYINT\n");
66 1 temp_char=INT0;
67 1 //printf ("\nINT0RD_Synchronization=%.2x \n",(unsigned int)INT0RD);
68 1 //--------------------------------------------------------------------------
69 1 // Auto-Negotiation Synchronization (Section 15.2 of CP220x Datasheet)
70 1 //--------------------------------------------------------------------------
71 1
72 1 // Step 1: Disable the PHY
73 1 PHYCN = 0x00;
74 1 // Step 2: Enable the PHY with link integrity test and auto-negotiation
75 1 // turned off
76 1
77 1 // A. Disable the Transmitter Power Save Option and Configure Options
78 1 TXPWR = 0x80;
79 1 PHYCF = ( SMSQ | JABBER | ADPAUSE | AUTOPOL );
80 1
81 1 // B. Enable the Physical Layer
82 1 PHYCN = PHYEN;
83 1
84 1 Delay1ms(20);
85 1
86 1
87 1 // C. Wait for the physical layer to power up
88 1 // wait_ms(10);
89 1
90 1 // D. Enable the Transmitter and Receiver
91 1 PHYCN = ( PHYEN | PHYTXEN | PHYRXEN );
92 1 Delay1ms(200);
93 1
94 1 // Step 3: Poll the Wake-on-Lan Interrupt
95 1
96 1 // A. Clear Interrupt Flags
97 1 temp_char = INT1;
98 1 //printf ("\nINT1RD=%.2x \n",(unsigned int)temp_char);
99 1 // B. Start a new timeout for 1.5 seconds
100 1 // reset_timeout(ONE_SECOND+ONE_SECOND/2);
101 1 // C. Check for a signal
102 1 for(i = 0; i < 150; i++)
103 1 {
104 2 Delay1ms(10);
105 2 temp_char =INT1RD;
106 2 if(temp_char & WAKEINT)
107 2 {
108 3 Delay1ms(250);
109 3 break;
110 3 }
111 2 }
112 1 // If no signal is deteced, wait 1.5s, then continue
113 1 // if(timeout_expired()){
114 1 // break;
115 1 // }
116 1
117 1
C51 COMPILER V7.06 CP2200 12/04/2007 13:46:18 PAGE 3
118 1 //printf ("\nINT0RD33=%.2x \n",(unsigned int)INT0RD);
119 1 //printf ("\nINT1RD_Negotiation=%.2x \n",(unsigned int)INT1RD);
120 1 //--------------------------------------------------------------------------
121 1 // Physical Layer Initialization (Section 15.7 of CP220x Datasheet)
122 1 //--------------------------------------------------------------------------
123 1
124 1 // Step 1: Synchronization procedure implemented above
125 1
126 1 // Step 2: Disable the physical layer
127 1 PHYCN = 0x00;
128 1
129 1 // Step 3: Configure the desired physical layer options including
130 1 // auto-negotiation and link integrity
131 1 PHYCF = ( SMSQ | LINKINTG | JABBER | AUTONEG | ADPAUSE | AUTOPOL );
132 1
133 1 // Step 4: Enable the physcial layer
134 1
135 1 // A. Enable the Physical Layer
136 1 PHYCN = PHYEN;
137 1
138 1 Delay1ms(100);
139 1
140 1 // B. Wait for the physical layer to power up
141 1 // wait_ms(10);
142 1 //printf ("\nINT1RD22=%.2x \n",(unsigned int)INT1RD);
143 1 // C. Enable the Transmitter and Receiver
144 1 // Auto-negotiation begins now
145 1 PHYCN = ( PHYEN | PHYTXEN | PHYRXEN );
146 1
147 1 // Step 5: Wait for auto-negotiation to complete
148 1
149 1 // Clear INT1 Interrupt Flags
150 1 temp_char = INT1;
151 1 // reset_timeout(6*ONE_SECOND);
152 1 // Check for autonegotiation fail or complete flag
153 1 // printf ("\nINT1RD_autonegotiation_start=%.2x \n",(unsigned int)INT1RD);
154 1
155 1
156 1 for(i = 0; i < 60; i++)
157 1 {
158 2 Delay1ms(250);
159 2 // temp_char = ReadReg(INT1RD);
160 2 // If Auto-Negotiation Completes/Fails, break
161 2 if(INT1RD & (ANCINT | ANFINT))
162 2 {
163 3 break;
164 3 }
165 2 }
166 1
167 1
168 1 // Mask out all bits except for auto negotiation bits
169 1 temp_char = INT1RD;
170 1 temp_char &= (ANCINT | ANFINT);
171 1
172 1 // Check if Auto-Negotiation has FAILED
173 1 if(temp_char & ANFINT)
174 1 {
175 2
176 2 // Auto-Negotiation has failed
177 2 retval = LINK_ERROR;
178 2
179 2 }
C51 COMPILER V7.06 CP2200 12/04/2007 13:46:18 PAGE 4
180 1 else
181 1 // Check if Auto-Negotiation has PASSED
182 1 if(temp_char == ANCINT)
183 1 {
184 2
185 2 // Auto-Negotiation has passed
186 2 retval = 0;
187 2
188 2 // Enable Link LED and Activity LED
189 2 IOPWR=0x04;
190 2
191 2 }
192 1 else
193 1
194 1 // Timeout Occured.
195 1 {
196 2 // Timeout
197 2 retval = LINK_ERROR;
198 2
199 2 }
200 1 return retval;
201 1
202 1 }
203
204 /*==========================================================
205 // function: Writes the value <mac_reg_data> to the indirect MAC register located at
206 // <mac_reg_offset>.
207 // Parameter: mac_reg_offset indirect register address
208 // mac_reg_data the data to write to mac_reg_offset
209 // return: void
210
211 // note: cp220x_core.c, datasheet page 88
212
213 ==========================================================*/
214 void MAC_Write(unsigned char mac_reg_offset, unsigned int mac_reg_data)
215 {
216 1
217 1 // Step 1: Write the address of the indirect register to MACADDR.
218 1 MACADDR=mac_reg_offset;
219 1
220 1 // Step 2: Copy the contents of <mac_reg_data> to MACDATAH:MACDATAL
221 1 MACDATAH=(mac_reg_data >> 8); // Copy High Byte
222 1 MACDATAL=(mac_reg_data & 0xFF); // Copy Low Byte
223 1
224 1 // Step 3: Perform a write on MACRW to transfer the contents of MACDATAH:MACDATAL
225 1 // to the indirect MAC register.
226 1 MACRW=0;
227 1
228 1 return;
229 1 }
230
231
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -