📄 main.lst
字号:
206 2 //
207 2 // After completion, check the return code for any of the following
208 2 // possible errors:
209 2 // LINK_ERROR - The device is not connected to a network or
210 2 // autonegotiation has failed.
211 2 //
212 2 // If an error occurs, keep re-trying until the device is able to
213 2 // complete a successful auto-negotiation or is plugged into a network.
214 2 //-----------------------------------------------------------------------
215 2
216 2 while(1){//
217 3
218 3 error_code = PHY_Init(); // 初始化cp2200物理层
219 3
220 3 if(error_code & LINK_ERROR) // Check for the possible error codes
221 3 { // On Failure:
222 4 YELLOW_LED = !YELLOW_LED; // Toggle indicator
223 4 }
224 3
225 3 else
226 3 { // On Success: //如果连接成功,进行下一步
227 4 YELLOW_LED = 1; // Turn on the indicator
228 4 break; // Exit initialization loop
229 4 }
230 3
231 3 }
232 2
233 2 //tcp init
234 2 init_main();
235 2 init_arp();
236 2 init_tcp();
237 2 //-----------------------------------------------------------------------
238 2 // Part C: MAC Initialization
239 2 //
240 2 // Initialize the media acccess controller (MAC)
241 2 //
C51 COMPILER V7.09 MAIN 07/27/2007 16:06:50 PAGE 5
242 2 // Currently, the MAC initialization routine does not return any errors.
243 2 //-----------------------------------------------------------------------
244 2
245 2 MAC_Init(); // Initialize the MAC
246 2
247 2
248 2 //-----------------------------
249 2 // Main Application Loop
250 2 //-----------------------------
251 2
252 2 // Initialize timer to time out in one second
253 2 reset_timeout(ONE_SECOND);
254 2
255 2 // Reset receive buffer and enable interrupts
256 2 RXCN = RXCLEAR;//清空接收buffer
257 2 EA = 1;
258 2
259 2 while(1){
260 3
261 3 //--------------------------------------------------------------------
262 3 // Task #1
263 3 // Exit application loop if device is removed from network
264 3 //--------------------------------------------------------------------
265 3 if(!(PHYCN & LINKSTA)) // Check the link status bit检查连接灯
266 3 { // On detection of bad link:
267 4 YELLOW_LED = 0; // Turn off the indicator
268 4 break; // Exit application loop
269 4 }
270 3
271 3 //--------------------------------------------------------------------
272 3 // Task #2
273 3 // Check if a packet has been received
274 3 //--------------------------------------------------------------------
275 3 if(CPINFOH & RXVALID) // Check if the current packet is valid检查是否有数据到达
276 3 { // On detection of a valid packet:
277 4
278 4 // Unload packet from the receive buffer and store in <RX_BUFF>
279 4 num_bytes = CP220x_Receive(RX_BUFF, sizeof(RX_BUFF));
280 4
281 4 eth_rcve(num_bytes, RX_BUFF);
282 4
283 4 //-----------------------------------------------------------------
284 4 // Application-Specific Code:
285 4 // If UART is enabled, print packet statistics to the terminal.
286 4 //-----------------------------------------------------------------
287 4 #if(UART_ENABLED)
// Print the number of bytes received.
printf("Received Packet bytes)\n");
// printf("Received Packet (%i bytes)\n", num_bytes);
// Print each byte to the UART terminal
/* for(i = 0; i < num_bytes; i++)
{
// Create a new row every 16 bytes
if((i & 0x000F) == 0x0000)
{
// Print the row address in the left column
printf("\n%04X ", i);
}
C51 COMPILER V7.09 MAIN 07/27/2007 16:06:50 PAGE 6
// Print the byte
printf("%02bX ", RX_BUFF[i]);
}
// Print two new-line characters for clarity (whitespace).
printf("\n\n");
*/
#endif
313 4
314 4 }
315 3 //else
316 3 // LED = 0;
317 3
318 3 //--------------------------------------------------------------------
319 3 // Task #3
320 3 // Check if timer has expired. Send one packet every second.
321 3 //--------------------------------------------------------------------
322 3 if(timeout_expired()){
323 4
324 4 // Reset timer to time out again after another second.
325 4 reset_timeout(ONE_SECOND);
326 4
327 4 // Send one packet.
328 4 // CP220x_Send(&DESTMAC, TX_BUFF, sizeof(TX_BUFF), IP_PACKET);
329 4 }
330 3
331 3 //-----------------------------
332 3 // End Main Application Loop
333 3 //-----------------------------
334 3 }
335 2
336 2
337 2
338 2 // Main do-while initialization loop -- code execution will now restart
339 2 } while(1);
340 1 }
341
342 //-----------------------------------------------------------------------------
343 // Ethernet_ISR
344 //-----------------------------------------------------------------------------
345 //
346 // This Interrupt Service Routine checks the number of packets in the receive
347 // buffer after each packet is received. If the buffer has 7 or more packets,
348 // then packet reception is disabled. Packet reception is re-enabled in the
349 // CP220x_Receive() routine after all packets have been unloaded.
350 //
351 // Allowed Latency: This interrupt service routine should be serviced within
352 // 51.2 us of the interrupt flag. This is the amount of time
353 // it takes to receive a minimum-sized 64-byte packet. To
354 // allow for greater latency (51.2us/packet), the maximum
355 // number of packets allowed in the receive buffer can be
356 // decreased.
357 //-----------------------------------------------------------------------------
358 void Ethernet_ISR(void)
359 {
360 1 unsigned char interrupt_read;
361 1 unsigned char valid_bits;
362 1 unsigned char num_packets;
363 1
364 1 // Clear interrupt flags.
365 1 interrupt_read = INT1;
C51 COMPILER V7.09 MAIN 07/27/2007 16:06:50 PAGE 7
366 1 interrupt_read = INT0;
367 1
368 1 // Check for packet received interrupt
369 1 if( interrupt_read & RXINT)
370 1 {
371 2 // Count the number of packets in the receive buffer
372 2 // This is equal to the number of bits set to 1 in TLBVALID
373 2 valid_bits = TLBVALID;
374 2
375 2 // Loop accumulates the number of bits set in Valid_Bits and
376 2 // stores this value in i. Uses the Brian Kernighan method
377 2 // for counting bits
378 2 for(num_packets = 0; valid_bits; num_packets++)
379 2 {
380 3 valid_bits &= valid_bits - 1;
381 3 }
382 2
383 2 // If the receive buffer has 7 packets, then disable reception.
384 2 if( num_packets >= 7)
385 2 {
386 3 RXCN = RXINH; // Inhibit New Packet Reception
387 3 }
388 2 }
389 1
390 1 // Check for the FIFO Full Interrupt
391 1 else if (interrupt_read & RXFINT)
392 1 {
393 2 // This interrupt could mean a few large packets were received,
394 2 // or a large number of small packets were received.
395 2 }
396 1
397 1 }
398
399
400
401
402 //-----------------------------------------------------------------------------
403 // End Of File
404 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 253 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 2370 ----
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 + -