📄 nf.lst
字号:
675 1
676 1 gl_ptr_mem = pos >> 2;
677 1 gl_cpt_page = (pos & 0x03) << 9 ;
678 1
679 1
680 1 nf_logical_block = (gl_ptr_mem >> NF_SHIFT_SECTOR_BLOCK);
681 1 nf_zone = nf_logical_block / 1000; /* Determinate logical zone */
682 1 nf_logical_block = nf_logical_block - (1000 * (Uint16)(nf_zone)); /* Logical block value */
683 1
684 1 gl_address = ((Uint32)(nf_lut_block[nf_zone])<<NF_SHIFT_SECTOR_BLOCK)+ /* lut address calculation
- */
685 1 ((Uint32)(nf_lut_index[nf_zone]));
686 1
687 1 Nf_wait_busy();
688 1 Nf_send_command(NF_READ_CMD); /* open the look-up table */
689 1 Nf_send_address (nf_logical_block << 1); /* column address Byte 0 */
690 1 Nf_send_address (nf_logical_block >> 7); /* column address Byte 1 */
691 1 Nf_send_address ( ((Byte*)&gl_address)[3] ); /* row address Byte 0 */
692 1 Nf_send_address ( ((Byte*)&gl_address)[2] ); /* row address Byte 1 */
693 1 if (NF_5_CYCLE_ADDRESS_BIT) /* size of nf > 128Mbytes ? */
694 1 Nf_send_address ( ((Byte*)&gl_address)[1] ); /* row address Byte 2 */
695 1 Nf_send_command(NF_READ_CMD2);
696 1 nf_busy = TRUE; /* set busy flag */
697 1 nf_write_advanced = FALSE; /* desactive write optimization */
698 1
699 1 Nf_wait_busy();
700 1
701 1 ((Byte*)&physical_block)[0] = Nf_rd_byte(); /* read the physical block number */
702 1 ((Byte*)&physical_block)[1] = Nf_rd_byte();
703 1
704 1 /* Calculate the physical sector address */
705 1 nf_current_physical_sector_addr = ((Uint32)(physical_block) << NF_SHIFT_SECTOR_BLOCK) +
706 1 (((Byte*)&gl_ptr_mem)[3] & 0x3F);
707 1 Nf_CS_OFF();
708 1 return OK;
709 1 }
710
711
712 /*F**************************************************************************
713 * NAME: nf_read_close
714 *----------------------------------------------------------------------------
715 * PARAMS:
716 *
717 * return:
718 *----------------------------------------------------------------------------
719 * PURPOSE:
720 * Low level memory read close
721 *----------------------------------------------------------------------------
722 * EXAMPLE:
723 *----------------------------------------------------------------------------
724 * NOTE:
725 *----------------------------------------------------------------------------
726 * REQUIREMENTS:
727 *****************************************************************************/
C51 COMPILER V7.06 NF 05/05/2005 12:12:06 PAGE 13
728 void nf_read_close (void)
729 {
730 1 Nf_CS_OFF();
731 1 }
732
733
734 /*F*************************************************************************
735 * NAME: nf_read_byte
736 *---------------------------------------------------------------------------
737 * PARAMS:
738 *
739 * return:
740 * Data read from memory
741 *---------------------------------------------------------------------------
742 * PURPOSE:
743 * Low level memory read function
744 *----------------------------------------------------------------------------
745 * EXAMPLE:
746 *----------------------------------------------------------------------------
747 * NOTE:
748 *----------------------------------------------------------------------------
749 * REQUIREMENTS:
750 ****************************************************************************/
751 Byte nf_read_byte (void)
752 {
753 1 Byte b;
754 1
755 1 if (nf_busy)
756 1 {
757 2 nf_busy = FALSE;
758 2 Nf_CS_ON();
759 2 Nf_wait_busy();
760 2 Nf_send_command(NF_READ_CMD);
761 2 Nf_send_address( 0x00);
762 2 Nf_send_address( ((Byte*)&gl_cpt_page)[0]);
763 2 Nf_send_address( ((Byte*)&nf_current_physical_sector_addr)[3]);
764 2 Nf_send_address( ((Byte*)&nf_current_physical_sector_addr)[2]);
765 2 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of nf >= 128Mbytes ? */
766 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[1] ); /* Row address Byte 2 */
767 2 Nf_send_command(NF_READ_CMD2);
768 2 Nf_wait_busy();
769 2 b = Nf_rd_byte();
770 2 Nf_CS_OFF();
771 2 }
772 1 else
773 1 {
774 2 b = Nf_rd_byte();
775 2 }
776 1 gl_cpt_page++;
777 1
778 1 if ( ((Byte*)&gl_cpt_page)[0] == 0x08) /* Detection of the end of data page */
779 1 {
780 2 gl_ptr_mem++; /* new page */
781 2 gl_cpt_page=0; /* reset column */
782 2 if ( !(((Byte*)&gl_ptr_mem)[3] & 0x3F) )/* New block ? */
783 2 {
784 3 nf_read_open(gl_ptr_mem << 2);
785 3 }
786 2 else
787 2 {
788 3 ((Byte*)&nf_current_physical_sector_addr)[3]++;
789 3 nf_busy = TRUE; /* Force read open command */
C51 COMPILER V7.06 NF 05/05/2005 12:12:06 PAGE 14
790 3 }
791 2 }
792 1 return b;
793 1 }
794
795
796 /*F**************************************************************************
797 * NAME: nf_read_sector
798 *----------------------------------------------------------------------------
799 * PARAMS:
800 * nb_sector: number of contiguous sector to read
801 * global: gl_ptr_mem
802 *
803 * return: OK read done
804 * KO read failure
805 *----------------------------------------------------------------------------
806 * PURPOSE:
807 * This function is an optimized function that writes nb-sector * 512 bytes
808 * from NF card to USB controller
809 *----------------------------------------------------------------------------
810 * EXAMPLE:
811 *----------------------------------------------------------------------------
812 * NOTE:
813 * nb_sector always >= 1, can not be zero
814 *----------------------------------------------------------------------------
815 * REQUIREMENTS:
816 *****************************************************************************/
817 bit nf_read_sector(Uint16 nb_sector)
818 {
819 1 Byte i;
820 1 bit begin_ping_pong;
821 1
822 1 begin_ping_pong = TRUE;
823 1 /* Start a transfert of nb_sector * 512 bytes */
824 1 do
825 1 {
826 2 Nf_CS_ON();
827 2 if (nf_busy) /* send a read command */
828 2 {
829 3 Nf_send_command(NF_READ_CMD);
830 3 Nf_send_address( 0x00);
831 3 Nf_send_address( ((Byte*)&gl_cpt_page)[0]);
832 3 Nf_send_address( ((Byte*)&nf_current_physical_sector_addr)[3]);
833 3 Nf_send_address( ((Byte*)&nf_current_physical_sector_addr)[2]);
834 3 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of nf >= 128Mbytes ? */
835 3 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[1] ); /* Row address Byte 2 */
836 3 Nf_send_command(NF_READ_CMD2);
837 3 nf_busy = FALSE;
838 3 Nf_wait_busy();
839 3 }
840 2
841 2 for (i = 8; i != 0; i--) /* 8 * 64 bytes = 512 bytes */
842 2 {
843 3 Usb_write_byte(Nf_rd_byte()); /* read 64 bytes from card */
844 3 Usb_write_byte(Nf_rd_byte());
845 3 Usb_write_byte(Nf_rd_byte());
846 3 Usb_write_byte(Nf_rd_byte());
847 3 Usb_write_byte(Nf_rd_byte());
848 3 Usb_write_byte(Nf_rd_byte());
849 3 Usb_write_byte(Nf_rd_byte());
850 3 Usb_write_byte(Nf_rd_byte());
851 3 Usb_write_byte(Nf_rd_byte());
C51 COMPILER V7.06 NF 05/05/2005 12:12:06 PAGE 15
852 3 Usb_write_byte(Nf_rd_byte());
853 3 Usb_write_byte(Nf_rd_byte());
854 3 Usb_write_byte(Nf_rd_byte());
855 3 Usb_write_byte(Nf_rd_byte());
856 3 Usb_write_byte(Nf_rd_byte());
857 3 Usb_write_byte(Nf_rd_byte());
858 3 Usb_write_byte(Nf_rd_byte());
859 3 Usb_write_byte(Nf_rd_byte());
860 3 Usb_write_byte(Nf_rd_byte());
861 3 Usb_write_byte(Nf_rd_byte());
862 3 Usb_write_byte(Nf_rd_byte());
863 3 Usb_write_byte(Nf_rd_byte());
864 3 Usb_write_byte(Nf_rd_byte());
865 3 Usb_write_byte(Nf_rd_byte());
866 3 Usb_write_byte(Nf_rd_byte());
867 3 Usb_write_byte(Nf_rd_byte());
868 3 Usb_write_byte(Nf_rd_byte());
869 3 Usb_write_byte(Nf_rd_byte());
870 3 Usb_write_byte(Nf_rd_byte());
871 3 Usb_write_byte(Nf_rd_byte());
872 3 Usb_write_byte(Nf_rd_byte());
873 3 Usb_write_byte(Nf_rd_byte());
874 3 Usb_write_byte(Nf_rd_byte());
875 3 Usb_write_byte(Nf_rd_byte());
876 3 Usb_write_byte(Nf_rd_byte());
877 3 Usb_write_byte(Nf_rd_byte());
878 3 Usb_write_byte(Nf_rd_byte());
879 3 Usb_write_byte(Nf_rd_byte());
880 3 Usb_write_byte(Nf_rd_byte());
881 3 Usb_write_byte(Nf_rd_byte());
882 3 Usb_write_byte(Nf_rd_byte());
883 3 Usb_write_byte(Nf_rd_byte());
884 3 Usb_write_byte(Nf_rd_byte());
885 3 Usb_write_byte(Nf_rd_byte());
886 3 Usb_write_byte(Nf_rd_byte());
887 3 Usb_write_byte(Nf_rd_byte());
888 3 Usb_write_byte(Nf_rd_byte());
889 3 Usb_write_byte(Nf_rd_byte());
890 3 Usb_write_byte(Nf_rd_byte());
891 3 Usb_write_byte(Nf_rd_byte());
892 3 Usb_write_byte(Nf_rd_byte());
893 3 Usb_write_byte(Nf_rd_byte());
894 3 Usb_write_byte(Nf_rd_byte());
895 3 Usb_write_byte(Nf_rd_byte());
896 3 Usb_write_byte(Nf_rd_byte());
897 3 Usb_write_byte(Nf_rd_byte());
898 3 Usb_write_byte(Nf_rd_byte());
899 3 Usb_write_byte(Nf_rd_byte());
900 3 Usb_write_byte(Nf_rd_byte());
901 3 Usb_write_byte(Nf_rd_byte());
902 3 Usb_write_byte(Nf_rd_byte());
903 3 Usb_write_byte(Nf_rd_byte());
904 3 Usb_write_byte(Nf_rd_byte());
905 3 Usb_write_byte(Nf_rd_byte());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -