📄 main.lst
字号:
157 int establish_network_connection()
158 {
159 1 int retval;
160 1
161 1 do
162 1 {
163 2 // mn_ether_init() initializes the Ethernet controller.
164 2 // AUTO_NEG indicates that the controller will auto-negotiate.
165 2 retval = mn_ether_init(AUTO_NEG, 0, 0);
166 2
167 2 // If there is no link, poll link_status until it sets or the
168 2 // CP2200 resets and then call mn_ether_init() again.
169 2 if (retval == LINK_FAIL)
170 2 {
171 3 while(!link_status && !ether_reset);
172 3 }
173 2
174 2 // If retval is less than zero and is not LINK_FAIL, there is a
175 2 // hardware error.
176 2 else if (retval < 0)
177 2 {
178 3 // Verify that the Ethernet controller is connected and powered properly.
179 3 // Verity that the EMIF has been configured at a speed compatible with the
C51 COMPILER V8.08 MAIN 04/01/2008 13:01:13 PAGE 4
180 3 // Ethernet controller.
181 3 while(1);
182 3 }
183 2
184 2 }while(retval < 0);
185 1
186 1 return (1);
187 1
188 1 }
189
190
191 //-----------------------------------------------------------------------------
192 // Initialization Routines
193 //-----------------------------------------------------------------------------
194
195 //-----------------------------------------------------------------------------
196 // PORT_Init
197 //-----------------------------------------------------------------------------
198 //
199 // Configure the Interrupts, Crossbar and GPIO ports
200 //
201 void PORT_Init (void)
202 {
203 1
204 1 IT01CF = 0x03; // Enable Interrupt 0 on P0.3
205 1 TCON &= ~0x01; // Make /INT0 level triggered
206 1
207 1 XBR0 = 0x01; // Enable UART on P0.4(TX) and P0.5(RX)
208 1 XBR1 = 0x40; // Enable crossbar and enable
209 1 // weak pull-ups
210 1
211 1 P0MDOUT |= 0x10; // enable UTX as push-pull output
212 1 P1MDOUT |= 0xD8; // /WR and /RD are push-pull
213 1 // AB4 LEDs are push-pull
214 1 P2MDOUT |= 0xFF;
215 1 P3MDOUT |= 0xFF;
216 1 P4MDOUT |= 0xFF;
217 1
218 1 }
219
220 //-----------------------------------------------------------------------------
221 // EMIF_Init
222 //-----------------------------------------------------------------------------
223 //
224 // Configure the External Memory Interface for both on and off-chip access.
225 //
226 void EMIF_Init (void)
227 {
228 1
229 1 EMI0CF = 0x1B; // non-muxed mode; split mode
230 1 // with bank select
231 1
232 1 EMI0TC = EMIF_TIMING; // This constant may be modified
233 1 // according to SYSCLK to meet the
234 1 // timing requirements for the CP2200
235 1
236 1 EMI0CN = BASE_ADDRESS; // Page of XRAM accessed by EMIF
237 1
238 1 }
239
240 //-----------------------------------------------------------------------------
241 // SYSCLK_Init
C51 COMPILER V8.08 MAIN 04/01/2008 13:01:13 PAGE 5
242 //-----------------------------------------------------------------------------
243 //
244 // This routine initializes the system clock.
245 //
246 void SYSCLK_Init (void)
247 {
248 1 int i;
249 1
250 1 OSCICN |= 0x03; // Configure internal oscillator for
251 1 // its maximum frequency
252 1
253 1 CLKMUL = 0x00; // Reset Clock Multiplier and select
254 1 // internal oscillator as input source
255 1
256 1 CLKMUL |= 0x80; // Enable the Clock Multiplier
257 1
258 1 for(i = 0; i < 256; i++); // Delay at least 5us
259 1
260 1 CLKMUL |= 0xC0; // Initialize the Clock Multiplier
261 1
262 1 while(!(CLKMUL & 0x20)); // Wait for MULRDY => 1
263 1
264 1 RSTSRC = 0x06; // Enable missing clock detector
265 1 // and VDD monitor
266 1
267 1 FLSCL |= 0x10; // Set Flash Scale for 48MHz
268 1
269 1 CLKSEL |= 0x03; // Select output of clock multiplier
270 1 // as the system clock.
271 1
272 1 }
273
274 //-----------------------------------------------------------------------------
275 // ether_reset_low
276 //-----------------------------------------------------------------------------
277 //
278 // This routine drives the reset pin of the ethernet controller low.
279 //
280 void ether_reset_low()
281 {
282 1
283 1 P1 &= ~0x01; // Pull reset low
284 1
285 1 }
286
287 //-----------------------------------------------------------------------------
288 // ether_reset_high
289 //-----------------------------------------------------------------------------
290 //
291 // This routine places the reset pin in High-Z allowing it to be pulled up
292 // using the external pull-up resistor.
293 //
294 // Additionally, this routine waits for the reset pin to read high before
295 // exiting.
296 //
297 void ether_reset_high (void)
298 {
299 1
300 1 P1 |= 0x01; // Allow /RST to rise
301 1 while(!(P1 & 0x01)); // Wait for /RST to go high
302 1
303 1
C51 COMPILER V8.08 MAIN 04/01/2008 13:01:13 PAGE 6
304 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 378 ----
CONSTANT SIZE = 68 ----
XDATA SIZE = 400 55
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -