📄 nf.lst
字号:
445 9 /* set nf_block_used to true to force the copy tail */
446 9 nf_block_used = TRUE;
447 9 /* complete the last copy tail */
448 9 nf_force_write_close();
449 9 /* restore value for temp_address and gl_address : */
450 9 /* gl_address have been modified by nf_copy_block_tail */
451 9 /* temp_address contain the value of gl_ptr_mem */
452 9 /* block value was saved in the variable i */
453 9
454 9 /* a block was deleted so wait nf being ready */
455 9 Nf_wait_busy();
456 9 nf_close_write_session = TRUE;
457 9 }
458 8 else
459 8 { /* new affected physical block */
460 9 gl_buffer[byte_6] = ((Byte*)&block)[0];
461 9 gl_buffer[byte_6 + 1] = ((Byte*)&block)[1];
462 9 }
463 8 }
464 7 }
465 6 }
466 5
467 5 if (nf_close_write_session == TRUE)
468 5 {
469 6 temp_address = (Uint32)(nf_zone) << NF_SHIFT_SECTOR_ZONE;
470 6 block = (Uint16)(nf_zone) << NF_SHIFT_BLOCK_ZONE;
471 6 gl_address = (Uint32)(nf_lut_block[nf_zone]) << NF_SHIFT_SECTOR_BLOCK;
472 6 j = NF_BLOCK_PER_ZONE + 1;
473 6 nf_init_buffer();
474 6 nf_close_write_session = FALSE;
475 6 }
476 5 else
477 5 {
478 6 temp_address += NF_PAGE_PER_BLOCK;
479 6 block++;
480 6 }
C51 COMPILER V7.06 NF 05/05/2005 12:12:06 PAGE 9
481 5 }
482 4
483 4 /* affect to the free physical block a fictive logical block */
484 4 /* and complete free spare physical blocks */
485 4 /* free physical block => gl_buffer[x] = 0xFF */
486 4 temp_address = (Uint32)(free_bloc_pos) << NF_SHIFT_SECTOR_BLOCK;
487 4 for (i = 0; i <= 0xFE; i+=2)
488 4 {
489 5 if (gl_buffer[i] == 0xFF)
490 5 {
491 6 do /* search free physical block */
492 6 {
493 7 temp_address += NF_PAGE_PER_BLOCK;
494 7 if (temp_address >= ((Uint32)(nf_zone + 1) << NF_SHIFT_SECTOR_ZONE) )
495 7 temp_address = (Uint32)(nf_zone) << NF_SHIFT_SECTOR_ZONE;
496 7
497 7 Nf_read_open_spare_area(temp_address, 0x05);
498 7
499 7 byte_5 = Nf_rd_byte(); /* Invalid/Valid block */
500 7 byte_6 = Nf_rd_byte(); /* Used/Unused block */
501 7 }
502 6 while ( ( (byte_6 != 0xFF) && (byte_6 != 0xE8) ) || (byte_5 != 0xFF) );
503 6
504 6 free_bloc_pos = (temp_address >> NF_SHIFT_SECTOR_BLOCK);
505 6 gl_buffer[i] = ((Byte*)&free_bloc_pos)[0] | 0x80;
506 6 gl_buffer[i + 1] = ((Byte*)&free_bloc_pos)[1];
507 6 }
508 5 }
509 4
510 4 /* Update LUT */
511 4 Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);
512 4 Nf_send_address ( 0x00 ); /* Column address byte 0 */
513 4 Nf_send_address ( page ); /* Column address byte 1 */
514 4 Nf_send_address ( ((Byte*)&gl_address)[3] ); /* Row address byte 0 */
515 4 Nf_send_address ( ((Byte*)&gl_address)[2] ); /* Row address byte 1 */
516 4 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
517 4 Nf_send_address ( ((Byte*)&gl_address)[1] ); /* Row address Byte 2 */
518 4
519 4 nf_download_buffer(); /* Write 256 bytes from the buffer */
520 4 page++;
521 4 if (page == 0x08)
522 4 {
523 5 /* Write redundant data */
524 5 Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xFF);
525 5 Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xFF);
526 5 Nf_wr_byte(0xE8); Nf_wr_byte(0xFF); /* Logical block value */
527 5 Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); /* ECC area 2 */
528 5 Nf_wr_byte(0xE8); Nf_wr_byte(0xFF); /* Logical block value */
529 5 Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); Nf_wr_byte(0xFF); /* ECC area 1 */
530 5 }
531 4 Nf_send_command(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
532 4 start += 0x80; /* process next 128 logical block */
533 4 end += 0x80;
534 4
535 4 }
536 3 while (start < NF_BLOCK_PER_ZONE);
537 3 }
538 2 }
539 1 /* Global initialization */
540 1 nf_block_min = 0xFFFF; /* Starting buffer value */
541 1 nf_gl_buf_idx_max = 0; /* Max index in the buffer */
542 1 nf_lut_modified = FALSE; /* Buffer change flag */
C51 COMPILER V7.06 NF 05/05/2005 12:12:06 PAGE 10
543 1 nf_gl_buf_idx = 0; /* Main buffer index */
544 1 gl_buf_free_idx = 0; /* Free physical buffer idx */
545 1 nf_old_zone = 0xFF; /* Previous zone number */
546 1 nf_close_write_session = FALSE;
547 1 nf_write_advanced = FALSE;
548 1 #undef temp_address
549 1
550 1 return OK;
551 1 }
552
553
554 /*F**************************************************************************
555 * NAME: nf_init
556 *----------------------------------------------------------------------------
557 * PARAMS:
558 *
559 * return:
560 * OK : init complete
561 * KO : - NF not supported or not recognise
562 *----------------------------------------------------------------------------
563 * PURPOSE:
564 * NF initialisation
565 *----------------------------------------------------------------------------
566 * EXAMPLE:
567 *----------------------------------------------------------------------------
568 * NOTE:
569 *----------------------------------------------------------------------------
570 * REQUIREMENTS:
571 *****************************************************************************/
572 bit nf_init (void)
573 {
574 1 FLASH_WP=1;
575 1 P2_1=0;
576 1 P2_2=0;
577 1 Nf_CS_ON();
578 1 Nf_send_command(NF_RESET_CMD);
579 1 Nf_wait_busy();
580 1 #if (NF_CAPACITY_AUTO_DETECT == TRUE) /* Auto Detect the type of nand-flash */
581 1 Nf_send_command(NF_READ_ID_CMD);
582 1 Nf_send_address(0x00);
583 1 Nf_rd_byte(); /* Maker code */
584 1 switch (Nf_rd_byte()) /* Device code */
585 1 {
586 2 /***************************************************************************/
587 2 case NF_128_1_8V : /*------- 128 Mbyte -------*/
588 2 case NF_128_3V : /*------- 128 Mbyte -------*/
589 2 nf_device_type = NF_SIZE_128MB;
590 2 nf_zone_max = 1; /* 1 zone : 1024 blocks */
591 2 nf_mem_size = (NF_SECTOR_SIZE_128MB + 1) * 4 - 1 - MEM_RESERVED_SIZE;
592 2 nf_5_cycle_address = 0; /* 4 address cycles */
593 2 break;
594 2 /***************************************************************************/
595 2 case NF_256_1_8V : /*------- 256 Mbyte -------*/
596 2 case NF_256_3V : /*------- 256 Mbyte -------*/
597 2 nf_device_type = NF_SIZE_256MB;
598 2 nf_zone_max = 2; /* 2 zones : 2048 blocks */
599 2 nf_mem_size = (NF_SECTOR_SIZE_256MB + 1) * 4 - 1 - MEM_RESERVED_SIZE;
600 2 nf_5_cycle_address = 1; /* 5 address cycles */
601 2 break;
602 2 /***************************************************************************/
603 2 case NF_512_1_8V : /*------- 512 Mbyte -------*/
604 2 case NF_512_3V : /*------- 512 Mbyte -------*/
C51 COMPILER V7.06 NF 05/05/2005 12:12:06 PAGE 11
605 2 nf_device_type = NF_SIZE_512MB;
606 2 nf_zone_max = 4; /* 4 zones : 4096 blocks */
607 2 nf_mem_size = (NF_SECTOR_SIZE_512MB + 1) * 4 - 1 - MEM_RESERVED_SIZE;
608 2 nf_5_cycle_address = 1; /* 5 address cycles */
609 2 break;
610 2
611 2 /***************************************************************************/
612 2 case NF_1024_1_8V : /*------- 1024 Mbyte -------*/
613 2 case NF_1024_3V : /*------- 1024 Mbyte -------*/
614 2 nf_device_type = NF_SIZE_1024MB;
615 2 nf_zone_max = 8; /* 8 zones : 8192 blocks */
616 2 nf_mem_size = (NF_SECTOR_SIZE_1024MB + 1) * 4 - 1 - MEM_RESERVED_SIZE;
617 2 nf_5_cycle_address = 1; /* 5 address cycles */
618 2 break;
619 2
620 2 /***************************************************************************/
621 2 case NF_2048_1_8V : /*------- 2048 Mbyte -------*/
622 2 case NF_2048_3V : /*------- 2048 Mbyte -------*/
623 2 nf_device_type = NF_SIZE_2048MB;
624 2 nf_zone_max = 16; /* 16 zones : 16384 blocks */
625 2 nf_mem_size = (NF_SECTOR_SIZE_2048MB + 1) * 4 - 1 - MEM_RESERVED_SIZE;
626 2 nf_5_cycle_address = 1; /* 5 address cycles */
627 2 break;
628 2
629 2 default:
630 2 return KO;
631 2 }
632 1 #else
nf_mem_size = (NF_SECTOR_SIZE + 1) * 4 - 1 - MEM_RESERVED_SIZE;
#endif
635 1
636 1 nf_reserved_space_start = nf_mem_size + 1;
637 1
638 1 return OK;
639 1 }
640
641
642
643
644 /*F**************************************************************************
645 * NAME: nf_read_open
646 *----------------------------------------------------------------------------
647 * PARAMS:
648 * pos: address of the logic sector to read (size 512 bytes)
649 *
650 * return:
651 * Update memory for reading
652 *----------------------------------------------------------------------------
653 * PURPOSE:
654 * Low level memory read update
655 *----------------------------------------------------------------------------
656 * EXAMPLE:
657 *----------------------------------------------------------------------------
658 * NOTE:
659 *----------------------------------------------------------------------------
660 * REQUIREMENTS:
661 *****************************************************************************/
662 bit nf_read_open (Uint32 pos)
663 {
664 1 Uint16 physical_block;
665 1
666 1 Nf_CS_ON();
C51 COMPILER V7.06 NF 05/05/2005 12:12:06 PAGE 12
667 1
668 1 if (nf_lut_modified)
669 1 {
670 2 nf_close_write_session = FALSE;
671 2 nf_force_write_close();
672 2 nf_reassign_block();
673 2 nf_lut_modified = FALSE;
674 2 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -