📄 cp220x_core.lst
字号:
317 2
318 2 // Enable Link LED and Activity LED
319 2 IOPWR = 0x0C;
320 2
321 2 #if(UART_ENABLED)
322 2 puts("Auto-Negotiation Passed\n");
323 2 #endif
324 2
325 2 } else
326 1
327 1 // Timeout Occured.
328 1 {
329 2 // Timeout
330 2 retval = LINK_ERROR;
331 2
332 2 #if(UART_ENABLED)
333 2 printf("*** TIMEOUT \n");
334 2 #endif
335 2 }
336 1
337 1 return retval;
338 1
339 1 }
340
341
342 //-----------------------------------------------------------------------------
343 // MAC_Init
344 //-----------------------------------------------------------------------------
345 //
346 // Return Value : None
347 // Parameters : None
348 //
349 // Initializes the MAC and programs the MAC address using the MAC address
350 // stored at address 0x1FFA in CP220x Flash.
351 //-----------------------------------------------------------------------------
352 void MAC_Init(void)
353 {
354 1
355 1 // Check the duplex mode and perform duplex-mode specific initializations
356 1 if(PHYCN & 0x10){
357 2
358 2 // The device is in full-duplex mode, configure MAC registers
359 2 // Padding is turned on.
360 2 MAC_Write(MACCF, 0x40B3);
361 2 MAC_Write(IPGT, 0x0015);
362 2
363 2 } else {
364 2
365 2 // The device is in half-duplex mode, configure MAC registers
C51 COMPILER V8.08 CP220X_CORE 11/04/2008 18:45:33 PAGE 7
366 2 // Padding is turned off.
367 2 MAC_Write(MACCF, 0x4012);
368 2 MAC_Write(IPGT, 0x0012);
369 2
370 2 }
371 1
372 1 // Configure the IPGR register
373 1 MAC_Write(IPGR, 0x0C12);
374 1
375 1 // Configure the MAXLEN register to 1518 bytes
376 1 MAC_Write(MAXLEN, 0x05EE);
377 1
378 1 // Copy MAC Address Stored in Flash to MYMAC
379 1 FLASHADDRH = 0x1F;
380 1 FLASHADDRL = 0xFA;
381 1
382 1 MYMAC.Char[0] = FLASHAUTORD;
383 1 MYMAC.Char[1] = FLASHAUTORD;
384 1 MYMAC.Char[2] = FLASHAUTORD;
385 1 MYMAC.Char[3] = FLASHAUTORD;
386 1 MYMAC.Char[4] = FLASHAUTORD;
387 1 MYMAC.Char[5] = FLASHAUTORD;
388 1
389 1 // Program the MAC address
390 1 MAC_SetAddress(&MYMAC);
391 1
392 1 // Enable Reception and configure Loopback mode
393 1 MAC_Write(MACCN, 0x0001); // Enable Reception without loopback
394 1
395 1 }
396
397 //-----------------------------------------------------------------------------
398 // Indirect MAC Register Access
399 //-----------------------------------------------------------------------------
400
401 //-----------------------------------------------------------------------------
402 // MAC_Write
403 //-----------------------------------------------------------------------------
404 //
405 // Return Value : None
406 // Parameters :
407 // 1) unsigned char mac_reg_offset - indirect register address
408 // 2) unsigned int mac_reg_data - the data to write to mac_reg_offset.
409 //
410 // Writes the value <mac_reg_data> to the indirect MAC register located at
411 // <mac_reg_offset>.
412 //-----------------------------------------------------------------------------
413 void MAC_Write(unsigned char mac_reg_offset, unsigned int mac_reg_data)
414 {
415 1
416 1 // Step 1: Write the address of the indirect register to MACADDR.
417 1 MACADDR = mac_reg_offset;
418 1
419 1 // Step 2: Copy the contents of <mac_reg_data> to MACDATAH:MACDATAL
420 1 MACDATAH = (mac_reg_data >> 8); // Copy High Byte
421 1 MACDATAL = (mac_reg_data & 0xFF); // Copy Low Byte
422 1
423 1 // Step 3: Perform a write on MACRW to transfer the contents of MACDATAH:MACDATAL
424 1 // to the indirect MAC register.
425 1 MACRW = 0;
426 1
427 1 return;
C51 COMPILER V8.08 CP220X_CORE 11/04/2008 18:45:33 PAGE 8
428 1 }
429
430
431 //-----------------------------------------------------------------------------
432 // MAC_SetAddress
433 //-----------------------------------------------------------------------------
434 //
435 // Return Value : None
436 // Parameters :
437 // 1) MACADDRESS* pMAC - pointer to a 6-byte MAC address structure.
438 //
439 // Sets the current MAC address to the MAC address pointed to by <pMAC>.
440 //-----------------------------------------------------------------------------
441 void MAC_SetAddress(MACADDRESS* pMAC)
442 {
443 1 UINT_struct temp_int;
444 1
445 1 temp_int.Char[0] = pMAC->Char[5];
446 1 temp_int.Char[1] = pMAC->Char[4];
447 1 MAC_Write(MACAD0, temp_int.Int);
448 1
449 1 temp_int.Char[0] = pMAC->Char[3];
450 1 temp_int.Char[1] = pMAC->Char[2];
451 1 MAC_Write(MACAD1, temp_int.Int);
452 1
453 1 temp_int.Char[0] = pMAC->Char[1];
454 1 temp_int.Char[1] = pMAC->Char[0];
455 1 MAC_Write(MACAD2, temp_int.Int);
456 1
457 1 return;
458 1 }
459
460 //-----------------------------------------------------------------------------
461 // CP220x Flash Routines
462 //-----------------------------------------------------------------------------
463 /* Not used. Commented to save code space.
464 //-----------------------------------------------------------------------------
465 // CPFLASH_ByteRead
466 //-----------------------------------------------------------------------------
467 //
468 // Return Value :
469 // unsigned char - the value of the Flash byte.
470 //
471 // Parameters :
472 // 1) unsigned int addr - the address in CP220x Flash.
473 //
474 // Reads a Flash byte and returns its value.
475 //-----------------------------------------------------------------------------
476 unsigned char CPFLASH_ByteRead (unsigned int addr)
477 {
478
479 // Set the Flash Address Pointer to <addr>
480 FLASHADDRH = (addr >> 8); // Copy High Byte
481 FLASHADDRL = (addr & 0xFF); // Copy Low Byte
482
483 // Read and Return the value in the Flash Data Register
484 return FLASHDATA;
485 }
486 //-----------------------------------------------------------------------------
487 // poll_flash_busy
488 //-----------------------------------------------------------------------------
489 //
C51 COMPILER V8.08 CP220X_CORE 11/04/2008 18:45:33 PAGE 9
490 // Return Value :
491 // unsigned char - Returns '0' on success or FLASH_ERROR if a problem
492 // is encountered.
493 //
494 // Parameters : None
495 //
496 // Waits for a Flash operation to start and complete
497 //
498 // Return Values:
499 //
500 //-----------------------------------------------------------------------------
501 unsigned char poll_flash_busy (void)
502 {
503
504 // Start Millisecond Timer and set timeout
505 reset_timeout(DEFAULT_TIMEOUT);
506
507 // Wait for operation to end
508 while((FLASHSTA & 0x08)){
509
510 if(!AB4_RST_State()){
511 #if(UART_ENABLED)
512 puts("Reset Pin Driven Low. Could indicate power failure.");
513 #endif
514 return FLASH_ERROR;
515 }
516
517 if(timeout_expired()){
518 #if(UART_ENABLED)
519 puts("Timeout: Flash operation has not ended.");
520 #endif
521 return FLASH_ERROR;
522 }
523
524 }
525
526 return 0;
527 }
528 //-----------------------------------------------------------------------------
529 // CPFLASH_ByteWrite
530 //-----------------------------------------------------------------------------
531 //
532 // Return Value :
533 // unsigned char - Returns '0' on success or FLASH_ERROR if a problem
534 // is encountered.
535 //
536 // Parameters :
537 // 1) unsigned int addr - the address of the Flash byte.
538 // 2) unsigned char byte - the data to write to Flash.
539 //
540 // Writes the value <byte> to the Flash address <addr>.
541 //
542 // Note: The addresses 0x1FFA through 0x1FFF cannot be written using this
543 // function because they contain the MAC address.
544 //
545 // Note: Software calling this function must ensure that the target Flash
546 // byte has been erased (value = 0xFF).
547 //
548 // Note: The Flash must be unlocked prior to calling this function.
549 //-----------------------------------------------------------------------------
550 unsigned char CPFLASH_ByteWrite (unsigned int addr, char byte)
551 {
C51 COMPILER V8.08 CP220X_CORE 11/04/2008 18:45:33 PAGE 10
552
553
554 // Check if address is in-range
555 if(addr < 0x1FFA)
556 {
557 // Set the Flash Address Pointer to <addr>
558 FLASHADDRH = (addr >> 8); // Copy High Byte
559 FLASHADDRL = (addr & 0xFF); // Copy Low Byte
560
561 // Write the Flash unlock sequence 0xA5, 0xF1
562 FLASHKEY = 0xA5;
563 FLASHKEY = 0xF1;
564
565 // Initiate the Flash write
566 FLASHDATA = byte;
567
568
569 // Wait for the Flash operation to start and complete
570 return poll_flash_busy();
571
572 }
573
574 return FLASH_ERROR;
575 }
576
577
578 //-----------------------------------------------------------------------------
579 // CPFLASH_PageErase
580 //-----------------------------------------------------------------------------
581 //
582 // Return Value :
583 // unsigned char - Returns '0' on success or FLASH_ERROR if a problem
584 // is encountered.
585 //
586 // Parameters :
587 // 1) unsigned int addr - the address of the Flash Page.
588 //
589 // Erases the Flash page containing address <addr>.
590 //
591 // Note: The last Flash page (0x1E00 - 0x1FFF) cannot be erased using this
592 // function because it contains the MAC address.
593 //
594 // Note: All data stored on a Flash page will be lost once the page is erased.
595 //
596 // Note: The Flash must be unlocked prior to calling this function.
597 //-----------------------------------------------------------------------------
598 unsigned char CPFLASH_PageErase (unsigned int addr)
599 {
600 // Check if address is in-range
601 if(addr < 0x1E00)
602 {
603 // Set the Flash Address Pointer to <addr>
604 FLASHADDRH = (addr >> 8); // Copy High Byte
605 FLASHADDRL = (addr & 0xFF); // Copy Low Byte
606
607 // Write the Flash unlock sequence 0xA5, 0xF1
608 FLASHKEY = 0xA5;
609 FLASHKEY = 0xF1;
610
611 // Initiate the Flash erase
612 FLASHERASE = 0x01;
613
C51 COMPILER V8.08 CP220X_CORE 11/04/2008 18:45:33 PAGE 11
614 // Wait for the Flash operation to start and complete
615 return poll_flash_busy();
616
617 }
618
619 return FLASH_ERROR;
620 }
621
622 */
623 //-----------------------------------------------------------------------------
624 // End Of File
625 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 531 ----
CONSTANT SIZE = 266 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 5
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -