📄 cp220x_core.lst
字号:
448 1
449 1 // Step 1: Write the address of the indirect register to MACADDR.
450 1 MACADDR = mac_reg_offset;
451 1
452 1 // Step 2: Copy the contents of <mac_reg_data> to MACDATAH:MACDATAL
453 1 MACDATAH = (mac_reg_data >> 8); // Copy High Byte
454 1 MACDATAL = (mac_reg_data & 0xFF); // Copy Low Byte
455 1
456 1 // Step 3: Perform a write on MACRW to transfer the contents of MACDATAH:MACDATAL
457 1 // to the indirect MAC register.
458 1 MACRW = 0;
459 1
460 1 return;
461 1 }
462
463
464 //-----------------------------------------------------------------------------
465 // MAC_SetAddress
466 //-----------------------------------------------------------------------------
467 //
468 // Return Value : None
469 // Parameters :
470 // 1) MACADDRESS* pMAC - pointer to a 6-byte MAC address structure.
471 //
472 // Sets the current MAC address to the MAC address pointed to by <pMAC>.
473 //-----------------------------------------------------------------------------
474 void MAC_SetAddress(MACADDRESS* pMAC)
475 {
476 1 UINT temp_int;
477 1
478 1 temp_int.Char[0] = pMAC->Char[5];
479 1 temp_int.Char[1] = pMAC->Char[4];
480 1 MAC_Write(MACAD0, temp_int.Int);
481 1
482 1 temp_int.Char[0] = pMAC->Char[3];
483 1 temp_int.Char[1] = pMAC->Char[2];
484 1 MAC_Write(MACAD1, temp_int.Int);
485 1
486 1 temp_int.Char[0] = pMAC->Char[1];
487 1 temp_int.Char[1] = pMAC->Char[0];
488 1 MAC_Write(MACAD2, temp_int.Int);
489 1
C51 COMPILER V7.09 CP220X_CORE 07/27/2007 15:11:23 PAGE 9
490 1 return;
491 1 }
492
493 //-----------------------------------------------------------------------------
494 // CP220x Flash Routines
495 //-----------------------------------------------------------------------------
496 // Not used. Commented to save code space.
497 //-----------------------------------------------------------------------------
498 // CPFLASH_ByteRead
499 //-----------------------------------------------------------------------------
500 //
501 // Return Value :
502 // unsigned char - the value of the Flash byte.
503 //
504 // Parameters :
505 // 1) unsigned int addr - the address in CP220x Flash.
506 //
507 // Reads a Flash byte and returns its value.
508 //-----------------------------------------------------------------------------
509 unsigned char CPFLASH_ByteRead (unsigned int addr)
510 {
511 1
512 1 // Set the Flash Address Pointer to <addr>
513 1 FLASHADDRH = (addr >> 8); // Copy High Byte
514 1 FLASHADDRL = (addr & 0xFF); // Copy Low Byte
515 1
516 1 // Read and Return the value in the Flash Data Register
517 1 return FLASHDATA;
518 1 }
519 //-----------------------------------------------------------------------------
520 // poll_flash_busy
521 //-----------------------------------------------------------------------------
522 //
523 // Return Value :
524 // unsigned char - Returns '0' on success or FLASH_ERROR if a problem
525 // is encountered.
526 //
527 // Parameters : None
528 //
529 // Waits for a Flash operation to start and complete
530 //
531 // Return Values:
532 //
533 //-----------------------------------------------------------------------------
534 unsigned char poll_flash_busy (void)
535 {
536 1
537 1 return 0;
538 1 // Start Millisecond Timer and set timeout
539 1 reset_timeout(DEFAULT_TIMEOUT);
540 1
541 1 // Wait for operation to end
542 1 while((FLASHSTA & 0x08)){
543 2
544 2 if(!AB4_RST_State()){
545 3 #if(UART_ENABLED)
printf("Reset Pin Driven Low. Could indicate power failure.");
#endif
548 3 return FLASH_ERROR;
549 3 }
550 2
551 2 if(timeout_expired()){
C51 COMPILER V7.09 CP220X_CORE 07/27/2007 15:11:23 PAGE 10
552 3 #if(UART_ENABLED)
printf("Timeout: Flash operation has not ended.");
#endif
555 3 return FLASH_ERROR;
556 3 }
557 2
558 2 }
559 1
560 1 return 0;
561 1 }
562 //-----------------------------------------------------------------------------
563 // CPFLASH_ByteWrite
564 //-----------------------------------------------------------------------------
565 //
566 // Return Value :
567 // unsigned char - Returns '0' on success or FLASH_ERROR if a problem
568 // is encountered.
569 //
570 // Parameters :
571 // 1) unsigned int addr - the address of the Flash byte.
572 // 2) unsigned char byte - the data to write to Flash.
573 //
574 // Writes the value <byte> to the Flash address <addr>.
575 //
576 // Note: The addresses 0x1FFA through 0x1FFF cannot be written using this
577 // function because they contain the MAC address.
578 //
579 // Note: Software calling this function must ensure that the target Flash
580 // byte has been erased (value = 0xFF).
581 //
582 // Note: The Flash must be unlocked prior to calling this function.
583 //-----------------------------------------------------------------------------
584 unsigned char CPFLASH_ByteWrite (unsigned int addr, char byte)
585 {
586 1
587 1
588 1 // Check if address is in-range
589 1 if(addr < 0x1FFA)
590 1 {
591 2 // Set the Flash Address Pointer to <addr>
592 2 FLASHADDRH = (addr >> 8); // Copy High Byte
593 2 FLASHADDRL = (addr & 0xFF); // Copy Low Byte
594 2
595 2 // Write the Flash unlock sequence 0xA5, 0xF1
596 2 FLASHKEY = 0xA5;
597 2 FLASHKEY = 0xF1;
598 2
599 2 // Initiate the Flash write
600 2 FLASHDATA = byte;
601 2
602 2
603 2 // Wait for the Flash operation to start and complete
604 2 return poll_flash_busy();
605 2
606 2 }
607 1
608 1 return FLASH_ERROR;
609 1 }
610
611
612 //-----------------------------------------------------------------------------
613 // CPFLASH_PageErase
C51 COMPILER V7.09 CP220X_CORE 07/27/2007 15:11:23 PAGE 11
614 //-----------------------------------------------------------------------------
615 //
616 // Return Value :
617 // unsigned char - Returns '0' on success or FLASH_ERROR if a problem
618 // is encountered.
619 //
620 // Parameters :
621 // 1) unsigned int addr - the address of the Flash Page.
622 //
623 // Erases the Flash page containing address <addr>.
624 //
625 // Note: The last Flash page (0x1E00 - 0x1FFF) cannot be erased using this
626 // function because it contains the MAC address.
627 //
628 // Note: All data stored on a Flash page will be lost once the page is erased.
629 //
630 // Note: The Flash must be unlocked prior to calling this function.
631 //-----------------------------------------------------------------------------
632 unsigned char CPFLASH_PageErase (unsigned int addr)
633 {
634 1 // Check if address is in-range
635 1 if(addr < 0x1E00)
636 1 {
637 2 // Set the Flash Address Pointer to <addr>
638 2 FLASHADDRH = (addr >> 8); // Copy High Byte
639 2 FLASHADDRL = (addr & 0xFF); // Copy Low Byte
640 2
641 2 // Write the Flash unlock sequence 0xA5, 0xF1
642 2 FLASHKEY = 0xA5;
643 2 FLASHKEY = 0xF1;
644 2
645 2 // Initiate the Flash erase
646 2 FLASHERASE = 0x01;
647 2
648 2 // Wait for the Flash operation to start and complete
649 2 return poll_flash_busy();
650 2
651 2 }
652 1
653 1 return FLASH_ERROR;
654 1 }
655
656
657 //-----------------------------------------------------------------------------
658 // End Of File
659 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 665 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 5
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
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 + -