📄 nf_drv.lst
字号:
505 1 Nf_send_command (NF_COPY_BACK_CMD);
506 1
507 1 start = nf_block_min << 1;
508 1
509 1 Nf_wait_busy();
510 1 Nf_send_command (NF_RANDOM_DATA_INPUT_CMD);
511 1 Nf_send_address (((Byte*)&start)[1]); /* Column address Byte 0 */
512 1 Nf_send_address (((Byte*)&start)[0]); /* Column address Byte 1 */
513 1 Nf_send_address ( ((Byte*)&gl_address)[3] ); /* Row address Byte 0 */
514 1 Nf_send_address ( ((Byte*)&gl_address)[2] ); /* Row address Byte 1 */
515 1 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of nf > 128Mbytes ? */
516 1 Nf_send_address ( ((Byte*)&gl_address)[1] ); /* Row address Byte 2 */
517 1
518 1
519 1 for (i = 0; i <= nf_gl_buf_idx_max; i++)
520 1 {
521 2 Nf_wr_byte (nf_buf[i].b[0]);
522 2 Nf_wr_byte (nf_buf[i].b[1]);
523 2 }
524 1
525 1 Nf_send_command (NF_RANDOM_DATA_INPUT_CMD); /* spare block */
526 1 Nf_send_address(0xD0); /* logical block >= 1000 */
527 1 Nf_send_address(0x07);
528 1
529 1 for (i = 0; i <= 23; i++)
530 1 {
531 2 Nf_wr_byte (nf_buf_free[i]>>8);
532 2 Nf_wr_byte (nf_buf_free[i]);
533 2 }
534 1 Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); /* spare area */
535 1 Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xE8); Nf_wr_byte(0xFF);
536 1 Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xE8);
537 1
538 1 Nf_send_command(NF_PAGE_PROGRAM_CMD); /* valid the page programmation */
539 1
540 1 nf_gl_buf_idx_max = 0; /* reset the max buff index */
541 1
542 1 if (nf_lut_index[nf_zone] == 0) /* erase old lut */
543 1 {
544 2 address2 = (Uint32)(nf_lut_block[nf_zone])<<NF_SHIFT_SECTOR_BLOCK;
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 10
545 2 nf_lut_block[nf_zone] = nf_look_up_table_block; /* update address of look up table */
546 2 Nf_wait_busy();
547 2 Nf_send_command (NF_BLOCK_ERASE_CMD); /* Auto Block Erase Setup */
548 2 Nf_send_address ( ((Byte*)&address2)[3] ); /* row address Byte 1 */
549 2 Nf_send_address ( ((Byte*)&address2)[2] ); /* row address Byte 2 */
550 2 if (NF_5_CYCLE_ADDRESS_BIT) /* size of nf > 128Mbytes ? */
551 2 Nf_send_address ( ((Byte*)&address2)[1] ); /* row address Byte 3 */
552 2 Nf_send_command(NF_BLOCK_ERASE_CONFIRM_CMD); /* erase command */
553 2 }
554 1 }
555
556
557 /*F**************************************************************************
558 * NAME: nf_mark_bad_block
559 *----------------------------------------------------------------------------
560 * PARAMS:
561 *
562 * return:
563 *----------------------------------------------------------------------------
564 * PURPOSE:
565 * Write 0x00 on block status byte (Byte 5 of spare data)
566 *----------------------------------------------------------------------------
567 * EXAMPLE:
568 *----------------------------------------------------------------------------
569 * NOTE:
570 *
571 *----------------------------------------------------------------------------
572 * REQUIREMENTS:
573 * ram/xram:
574 * cycle:
575 * stack:
576 * code:
577 *****************************************************************************/
578 void nf_mark_bad_block (void)
579 {
580 1 Nf_wait_busy();
581 1 Nf_write_open_spare_area(gl_address, 0x03);
582 1 Nf_wr_byte(0x00);
583 1 Nf_wr_byte(0x00);
584 1 Nf_wr_byte(0x00);
585 1 Nf_send_command (NF_PAGE_PROGRAM_CMD); /* Send program command */
586 1 }
587
588
589 /*F**************************************************************************
590 * NAME: nf_block_erase
591 *----------------------------------------------------------------------------
592 * PARAMS:
593 *
594 * return:
595 * OK : erase done
596 * KO : erase not done
597 *----------------------------------------------------------------------------
598 * PURPOSE: Erase a block on Nand Flash Media
599 *----------------------------------------------------------------------------
600 * EXAMPLE:
601 *----------------------------------------------------------------------------
602 * NOTE:
603 *
604 *----------------------------------------------------------------------------
605 * REQUIREMENTS:
606 * ram/xram:
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 11
607 * cycle:
608 * stack:
609 * code:
610 *****************************************************************************/
611 bit nf_block_erase (Uint32 pos)
612 {
613 1 Nf_wait_busy();
614 1 Nf_send_command (NF_BLOCK_ERASE_CMD); /* Auto Block Erase Setup */
615 1 Nf_send_address ( ((Byte*)&pos)[3] ); /* Row address Byte 0 */
616 1 Nf_send_address ( ((Byte*)&pos)[2] ); /* Row address Byte 1 */
617 1 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
618 1 Nf_send_address ( ((Byte*)&pos)[1] ); /* Row address Byte 2 */
619 1 Nf_send_command(NF_BLOCK_ERASE_CONFIRM_CMD);/* Erase command */
620 1 return OK;
621 1 }
622
623
624 /*F**************************************************************************
625 * NAME: nf_erase_all_block
626 *----------------------------------------------------------------------------
627 * PARAMS:
628 *
629 * return:
630 * OK : erase done
631 * KO : erase not done
632 *----------------------------------------------------------------------------
633 * PURPOSE:
634 * This function erase all blocks on a NF and start the lut construction
635 *----------------------------------------------------------------------------
636 * EXAMPLE:
637 *----------------------------------------------------------------------------
638 * NOTE:
639 * This function use the global variable Uint32 gl_address
640 *----------------------------------------------------------------------------
641 * REQUIREMENTS:
642 * ram/xram:
643 * cycle:
644 * stack:
645 * code:
646 *****************************************************************************/
647 bit nf_erase_all_block (void)
648 {
649 1 Byte i;
650 1 Uint16 j;
651 1 Uint16 block;
652 1 Uint16 block_reserved_space;
653 1 bit erase;
654 1
655 1 Nf_CS_ON();
656 1 /* Erase all block */
657 1 block_reserved_space = (Uint16) (((nf_reserved_space_start >> NF_SHIFT_SECTOR_BLOCK) % 1000));
658 1 gl_address = 0;
659 1 for (nf_zone = 0; nf_zone < NF_ZONE_MAX_CPT; nf_zone++)
660 1 {
661 2 for (j = 1024; j != 0; j--)
662 2 {
663 3 Nf_wait_busy();
664 3 Nf_read_open_spare_area(gl_address, 0x05); /* Read block status byte */
665 3 erase = TRUE;
666 3 if (Nf_rd_byte() != 0xFF) /* if bad block */
667 3 {
668 4 erase = FALSE; /* don't erase block */
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 12
669 4 }
670 3 else
671 3 {
672 4 ((Byte*)&block)[0] = Nf_rd_byte(); /* Read logical block address */
673 4 ((Byte*)&block)[1] = Nf_rd_byte();
674 4 if ( (MEM_RESERVED_SIZE != 0) && (nf_zone == (NF_ZONE_MAX_CPT - 1)))
675 4 {
676 5 if ((((Byte*)&block)[0] & 0xF8) == 0x10)
677 5 {
678 6 block = (block & 0x0FFF) >> 1;
679 6 if (block >= block_reserved_space) /* If it is a reserved block */
680 6 {
681 7 erase = FALSE; /* Don't erase block */
682 7 }
683 6 }
684 5 }
685 4 }
686 3
687 3 if (NF_FULL_CHIP_ERASE == FALSE)
688 3 {
689 4 if (((Byte*)&block)[0] != 0xE8)
690 4 {
691 5 erase = FALSE;
692 5 }
693 4 }
694 3 else
695 3 {
696 4 if (((Byte*)&block)[0] == 0x00)
697 4 {
698 5 erase = FALSE;
699 5 }
700 4 }
701 3
702 3 if (erase)
703 3 {
704 4 nf_block_erase(gl_address);
705 4 if (nf_check_status() == KO)
706 4 {
707 5 nf_mark_bad_block(); /* Failure on erase operation */
708 5 }
709 4 else
710 4 { /* Fill redundant area with 0x00 */
711 5 Nf_write_open_spare_area(gl_address, 0x00);
712 5 for (i = 16; i != 0; i--)
713 5 Nf_wr_byte(0x00);
714 5 Nf_send_command(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
715 5 if ( nf_check_status() == KO)
716 5 {
717 6 nf_mark_bad_block(); /* Failure on program operation */
718 6 }
719 5 else
720 5 {
721 6 Nf_read_open_spare_area(gl_address, 0x00); /* Read 16 bytes */
722 6 i = 16;
723 6 while ((i != 0) && (Nf_rd_byte() == 0x00)) i--;
724 6
725 6 if (i)
726 6 {
727 7 nf_mark_bad_block();
728 7 }
729 6 else
730 6 {
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 13
731 7 nf_block_erase(gl_address); /* Finally, erase the block */
732 7 if ( nf_check_status() == KO)
733 7 { /* Failure on erase operation */
734 8 nf_mark_bad_block();
735 8 }
736 7 }
737 6 }
738 5 }
739 4 }
740 3 gl_address += NF_PAGE_PER_BLOCK;
741 3 }
742 2 }
743 1 Nf_CS_OFF();
744 1 return (nf_read_spare_byte());
745 1 }
746
747
748
749
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1695 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 17
IDATA SIZE = 2 ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -