📄 nf.lst
字号:
504 1 {
505 2 Nf_send_command(NF_READ_B_AREA_CMD); /* 2nd half page */
506 2 Nf_send_address((nf_logical_block << 1) - 256);
507 2 }
508 1 else
509 1 {
510 2 Nf_send_command(NF_READ_A_AREA_CMD); /* first half page */
511 2 Nf_send_address(nf_logical_block << 1);
512 2 }
513 1
514 1 Nf_send_address (((Byte*)&gl_address)[3]); /* 2nd address cycle */
515 1 Nf_send_address (((Byte*)&gl_address)[2]); /* 3rd address cycle */
516 1 if (NF_4_CYCLE_ADDRESS_BIT) /* Size of card >= 64Mbytes ?*/
517 1 Nf_send_address (((Byte*)&gl_address)[1]); /* 4th address cycle */
518 1
519 1 Nf_wait_busy();
520 1
521 1 /* Read the physical block number */
522 1 ((Byte*)&physical_block)[0] = Nf_rd_byte();
523 1 ((Byte*)&physical_block)[1] = Nf_rd_byte();
524 1
525 1 /* Calculate the physical sector address */
526 1 nf_current_physical_sector_addr = ((Uint32)(physical_block) << 5) + (gl_ptr_mem & NF_BLOCK_MASK);
527 1 Nf_CS_OFF();
528 1 return OK;
529 1 }
530
531
532 /*F**************************************************************************
533 * NAME: nf_read_close
534 *----------------------------------------------------------------------------
535 * PARAMS:
536 *
537 * return:
538 *----------------------------------------------------------------------------
539 * PURPOSE:
540 * Low level memory read close
541 *----------------------------------------------------------------------------
542 * EXAMPLE:
543 *----------------------------------------------------------------------------
544 * NOTE:
545 *----------------------------------------------------------------------------
546 * REQUIREMENTS:
547 *****************************************************************************/
548 void nf_read_close (void)
549 {
C51 COMPILER V7.02a NF 09/13/2007 11:53:06 PAGE 10
550 1 Nf_CS_OFF();
551 1 }
552
553
554 /*F*************************************************************************
555 * NAME: nf_read_byte
556 *---------------------------------------------------------------------------
557 * PARAMS:
558 *
559 * return:
560 * Data read from memory
561 *---------------------------------------------------------------------------
562 * PURPOSE:
563 * Low level memory read function
564 *----------------------------------------------------------------------------
565 * EXAMPLE:
566 *----------------------------------------------------------------------------
567 * NOTE:
568 *----------------------------------------------------------------------------
569 * REQUIREMENTS:
570 ****************************************************************************/
571 Byte nf_read_byte (void)
572 {
573 1 Byte b;
574 1
575 1 if (!gl_cpt_page)
576 1 {
577 2 Nf_CS_ON();
578 2 Nf_wait_busy();
579 2 Nf_read_open_A_area(nf_current_physical_sector_addr, 0x00);
580 2 b = Nf_rd_byte();
581 2 Nf_CS_OFF();
582 2 }
583 1 else
584 1 {
585 2 b = Nf_rd_byte();
586 2 }
587 1
588 1 gl_cpt_page++;
589 1
590 1 /* Detection of the end of data page */
591 1 if (((Byte*)&gl_cpt_page)[0] == NF_DATA_SIZE_H)
592 1 {
593 2 /* read spare data bytes */
594 2 Nf_rd_byte();
595 2 Nf_rd_byte();
596 2 Nf_rd_byte();
597 2 Nf_rd_byte();
598 2 Nf_rd_byte();
599 2 Nf_rd_byte();
600 2 Nf_rd_byte();
601 2 Nf_rd_byte();
602 2 Nf_rd_byte();
603 2 Nf_rd_byte();
604 2 Nf_rd_byte();
605 2 Nf_rd_byte();
606 2 Nf_rd_byte();
607 2 Nf_rd_byte();
608 2 Nf_rd_byte();
609 2 Nf_rd_byte();
610 2
611 2 gl_ptr_mem++; /* new page */
C51 COMPILER V7.02a NF 09/13/2007 11:53:06 PAGE 11
612 2 gl_cpt_page=0; /* start at column 0 */
613 2
614 2 if (!(((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK)) /* New block ? */
615 2 {
616 3 nf_read_open(gl_ptr_mem);
617 3 }
618 2 else
619 2 {
620 3 nf_current_physical_sector_addr++;
621 3 }
622 2 }
623 1 return b;
624 1 }
625
626
627 /*F**************************************************************************
628 * NAME: nf_read_sector
629 *----------------------------------------------------------------------------
630 * PARAMS:
631 * nb_sector: number of contiguous sector to read
632 * global: gl_ptr_mem
633 *
634 * return: OK read done
635 * KO read failure
636 *----------------------------------------------------------------------------
637 * PURPOSE:
638 * This function is an optimized function that writes nb-sector * 512 bytes
639 * from NF card to USB controller
640 *----------------------------------------------------------------------------
641 * EXAMPLE:
642 *----------------------------------------------------------------------------
643 * NOTE:
644 * nb_sector always >= 1, can not be zero
645 *----------------------------------------------------------------------------
646 * REQUIREMENTS:
647 *****************************************************************************/
648 bit nf_read_sector(Uint16 nb_sector)
649 {
650 1 Byte i;
651 1 bit begin_ping_pong;
652 1
653 1 begin_ping_pong = TRUE;
654 1
655 1 do
656 1 {
657 2 Nf_CS_ON();
658 2 Nf_wait_busy();
659 2 Nf_read_open_A_area(nf_current_physical_sector_addr, 0x00);
660 2
661 2 for (i = 8; i != 0; i--)
662 2 {
663 3 Usb_write_byte(Nf_rd_byte()); /* read 64 bytes from card */
664 3 Usb_write_byte(Nf_rd_byte());
665 3 Usb_write_byte(Nf_rd_byte());
666 3 Usb_write_byte(Nf_rd_byte());
667 3 Usb_write_byte(Nf_rd_byte());
668 3 Usb_write_byte(Nf_rd_byte());
669 3 Usb_write_byte(Nf_rd_byte());
670 3 Usb_write_byte(Nf_rd_byte());
671 3 Usb_write_byte(Nf_rd_byte());
672 3 Usb_write_byte(Nf_rd_byte());
673 3 Usb_write_byte(Nf_rd_byte());
C51 COMPILER V7.02a NF 09/13/2007 11:53:06 PAGE 12
674 3 Usb_write_byte(Nf_rd_byte());
675 3 Usb_write_byte(Nf_rd_byte());
676 3 Usb_write_byte(Nf_rd_byte());
677 3 Usb_write_byte(Nf_rd_byte());
678 3 Usb_write_byte(Nf_rd_byte());
679 3 Usb_write_byte(Nf_rd_byte());
680 3 Usb_write_byte(Nf_rd_byte());
681 3 Usb_write_byte(Nf_rd_byte());
682 3 Usb_write_byte(Nf_rd_byte());
683 3 Usb_write_byte(Nf_rd_byte());
684 3 Usb_write_byte(Nf_rd_byte());
685 3 Usb_write_byte(Nf_rd_byte());
686 3 Usb_write_byte(Nf_rd_byte());
687 3 Usb_write_byte(Nf_rd_byte());
688 3 Usb_write_byte(Nf_rd_byte());
689 3 Usb_write_byte(Nf_rd_byte());
690 3 Usb_write_byte(Nf_rd_byte());
691 3 Usb_write_byte(Nf_rd_byte());
692 3 Usb_write_byte(Nf_rd_byte());
693 3 Usb_write_byte(Nf_rd_byte());
694 3 Usb_write_byte(Nf_rd_byte());
695 3 Usb_write_byte(Nf_rd_byte());
696 3 Usb_write_byte(Nf_rd_byte());
697 3 Usb_write_byte(Nf_rd_byte());
698 3 Usb_write_byte(Nf_rd_byte());
699 3 Usb_write_byte(Nf_rd_byte());
700 3 Usb_write_byte(Nf_rd_byte());
701 3 Usb_write_byte(Nf_rd_byte());
702 3 Usb_write_byte(Nf_rd_byte());
703 3 Usb_write_byte(Nf_rd_byte());
704 3 Usb_write_byte(Nf_rd_byte());
705 3 Usb_write_byte(Nf_rd_byte());
706 3 Usb_write_byte(Nf_rd_byte());
707 3 Usb_write_byte(Nf_rd_byte());
708 3 Usb_write_byte(Nf_rd_byte());
709 3 Usb_write_byte(Nf_rd_byte());
710 3 Usb_write_byte(Nf_rd_byte());
711 3 Usb_write_byte(Nf_rd_byte());
712 3 Usb_write_byte(Nf_rd_byte());
713 3 Usb_write_byte(Nf_rd_byte());
714 3 Usb_write_byte(Nf_rd_byte());
715 3 Usb_write_byte(Nf_rd_byte());
716 3 Usb_write_byte(Nf_rd_byte());
717 3 Usb_write_byte(Nf_rd_byte());
718 3 Usb_write_byte(Nf_rd_byte());
719 3 Usb_write_byte(Nf_rd_byte());
720 3 Usb_write_byte(Nf_rd_byte());
721 3 Usb_write_byte(Nf_rd_byte());
722 3 Usb_write_byte(Nf_rd_byte());
723 3 Usb_write_byte(Nf_rd_byte());
724 3 Usb_write_byte(Nf_rd_byte());
725 3 Usb_write_byte(Nf_rd_byte());
726 3 Usb_write_byte(Nf_rd_byte());
727 3
728 3 if (begin_ping_pong)
729 3 {
730 4 begin_ping_pong = FALSE;
731 4 }
732 3 else
733 3 {
734 4 while (!Usb_tx_complete()); /* wait end of transfer */
735 4 Usb_clear_TXCMPL(); /* ack transfer */
C51 COMPILER V7.02a NF 09/13/2007 11:53:06 PAGE 13
736 4 }
737 3 Usb_set_TXRDY(); /* start usb transfer */
738 3 }
739 2
740 2 gl_ptr_mem++; /* new page */
741 2 Nf_CS_OFF();
742 2 if (! ( ((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK ) ) /* New block ? */
743 2 {
744 3 nf_read_open(gl_ptr_mem);
745 3 }
746 2 else
747 2 {
748 3 nf_current_physical_sector_addr++;
749 3 }
750 2 nb_sector--;
751 2 }
752 1 while (nb_sector != 0);
753 1
754 1 while (!Usb_tx_complete()); /* wait end of last transfer */
755 1 Usb_clear_TXCMPL(); /* ack transfer */
756 1
757 1 return OK;
758 1 }
759
760
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -