⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nf.lst

📁 基于AT89C51SND1的MP3的程序设计(包括播放mp3和录音功能)
💻 LST
📖 第 1 页 / 共 5 页
字号:
 906   3            Usb_write_byte(Nf_rd_byte());
 907   3      
 908   3            if (begin_ping_pong)
 909   3            {
 910   4              begin_ping_pong = FALSE;
 911   4            }
 912   3            else
 913   3            {
C51 COMPILER V7.06   NF                                                                    05/05/2005 12:12:06 PAGE 16  

 914   4              while (!Usb_tx_complete());             /* wait end of transfer               */
 915   4              Usb_clear_TXCMPL();                     /* ack transfer                       */
 916   4            }
 917   3            Usb_set_TXRDY();                          /* start usb transfer                 */    
 918   3          }
 919   2      
 920   2          ((Byte*)&gl_cpt_page)[0] += 2;
 921   2          if ( ((Byte*)&gl_cpt_page)[0] == 0x08)      /* Detection of the end of data page  */
 922   2          {
 923   3            gl_ptr_mem++;                             /* new page                           */
 924   3            if ( !(((Byte*)&gl_ptr_mem)[3] & 0x3F) )  /* New block ?                        */
 925   3            {
 926   4              nf_read_open(gl_ptr_mem << 2);
 927   4            }
 928   3            else
 929   3            {
 930   4              ((Byte*)&nf_current_physical_sector_addr)[3]++;
 931   4              gl_cpt_page = 0;
 932   4              nf_busy = TRUE;
 933   4            }
 934   3          }
 935   2          nb_sector--;
 936   2          Nf_CS_OFF();
 937   2        }
 938   1        while (nb_sector != 0);
 939   1        while (!Usb_tx_complete());                   /* wait end of last transfer        */
 940   1        Usb_clear_TXCMPL();                           /* ack transfer                     */
 941   1        return OK;
 942   1      }
 943          
 944          
 945          /*F**************************************************************************
 946          * NAME: nf_invert_block
 947          *----------------------------------------------------------------------------
 948          * PARAMS:
 949          *   
 950          * return:
 951          *----------------------------------------------------------------------------
 952          * PURPOSE:
 953          *   invert a used physical block with a spare free block
 954          *   set block_used to TRUE or FALSE
 955          *   update the current physical sector address
 956          *----------------------------------------------------------------------------
 957          * EXAMPLE:
 958          *----------------------------------------------------------------------------
 959          * NOTE:
 960          *----------------------------------------------------------------------------
 961          * REQUIREMENTS:
 962          *****************************************************************************/
 963          void nf_invert_block(void)
 964          {
 965   1        if ( !(nf_buf[nf_gl_buf_idx].w & 0x8000))                 
 966   1        {
 967   2          if ((nf_buf_free[gl_buf_free_idx] & 0x7FFF) == nf_lut_block[nf_zone])
 968   2          {
 969   3            gl_buf_free_idx++;
 970   3            if (gl_buf_free_idx > nf_spare_block)
 971   3            {
 972   4              gl_buf_free_idx = 0;
 973   4            }      
 974   3          }        
 975   2          /* invert the block and assign the next block to be deleted */
C51 COMPILER V7.06   NF                                                                    05/05/2005 12:12:06 PAGE 17  

 976   2          nf_block_to_be_deleted = nf_buf[nf_gl_buf_idx].w;
 977   2          nf_buf[nf_gl_buf_idx].w = nf_buf_free[gl_buf_free_idx] & 0x7FFF;
 978   2          nf_buf_free[gl_buf_free_idx] = nf_block_to_be_deleted | 0x8000;
 979   2          nf_block_used = TRUE;                               /* block have to be deleted         */
 980   2          gl_buf_free_idx++;
 981   2          if (gl_buf_free_idx > nf_spare_block )         /* increase the spare buffer index  */
 982   2          {
 983   3            gl_buf_free_idx = 0;
 984   3          }
 985   2        }
 986   1        else
 987   1        {
 988   2          nf_block_used = FALSE;
 989   2          nf_buf[nf_gl_buf_idx].w &= 0x7FFF;
 990   2        }
 991   1        /* update the max index buffer */
 992   1        if (nf_gl_buf_idx > nf_gl_buf_idx_max)
 993   1          nf_gl_buf_idx_max = nf_gl_buf_idx;
 994   1        /* Update the current physical sector address */
 995   1        nf_current_physical_sector_addr = ((Uint32)(nf_buf[nf_gl_buf_idx].w) << NF_SHIFT_SECTOR_BLOCK);
 996   1      
 997   1      }
 998                 
 999          /*F**************************************************************************
1000          * NAME: nf_write_open
1001          *----------------------------------------------------------------------------
1002          *----------------------------------------------------------------------------
1003          * PARAMS:
1004          *   pos: address of the the next write data
1005          *
1006          * return:
1007          *----------------------------------------------------------------------------
1008          * PURPOSE:
1009          *   Low level memory write update
1010          *----------------------------------------------------------------------------
1011          * EXAMPLE:
1012          *----------------------------------------------------------------------------
1013          * NOTE:
1014          *----------------------------------------------------------------------------
1015          * REQUIREMENTS:
1016          *****************************************************************************/
1017          bit nf_write_open (Uint32 pos)
1018          {
1019   1      Byte i;
1020   1      bit change_zone = FALSE;
1021   1      
1022   1        if (nf_write_advanced)        /* Previous operation was a write mass storage session */
1023   1        {
1024   2          nf_write_advanced = FALSE;  /* nf_write_advanced will be set only if there is a mass storage session *
             -/
1025   2          if (pos == save_gl_ptr_mem) /* if this sector is the previous "next sector" */
1026   2          {
1027   3            nf_current_physical_sector_addr = save_physical_sector;   /* Update sector information */
1028   3            gl_ptr_mem = pos >> 2;
1029   3            gl_cpt_page = (pos & 0x03) << 9;
1030   3      
1031   3            nf_busy = FALSE;          /* clear busy flag */
1032   3            nf_wr_open = TRUE;        /* set write open flag to send write open cmd */
1033   3            return OK;
1034   3          }
1035   2        }
1036   1      
C51 COMPILER V7.06   NF                                                                    05/05/2005 12:12:06 PAGE 18  

1037   1        Nf_CS_ON();
1038   1        if (nf_close_write_session)
1039   1        {
1040   2          nf_close_write_session = FALSE;
1041   2          nf_force_write_close();
1042   2        }
1043   1      
1044   1        gl_ptr_mem = pos >> 2;
1045   1        gl_cpt_page = (pos & 0x03) << 9;
1046   1      
1047   1      
1048   1        /* Determine the logical block value and logical zone value */
1049   1        nf_logical_block = (gl_ptr_mem >> NF_SHIFT_SECTOR_BLOCK);
1050   1        nf_zone = 0;
1051   1        while (nf_logical_block > 999)
1052   1        {
1053   2          nf_logical_block -= 1000;
1054   2          nf_zone++;
1055   2        }
1056   1      
1057   1        if (nf_zone != nf_old_zone)
1058   1        {
1059   2          change_zone = TRUE;
1060   2          if (nf_lut_modified)
1061   2          { /* save old lut */
1062   3            i = nf_old_zone;
1063   3            nf_old_zone = nf_zone;
1064   3            nf_zone = i;
1065   3            nf_reassign_block();
1066   3            nf_lut_modified = FALSE;
1067   3            nf_zone = nf_old_zone;
1068   3          }
1069   2          else
1070   2          { /* update old zone value */
1071   3            nf_old_zone = nf_zone;
1072   3          }
1073   2          nf_block_min = 0xFFFF;
1074   2          gl_buf_free_idx = 0;
1075   2        }
1076   1      
1077   1        nf_calc_logical_block();
1078   1        if ( (nf_logical_block >= nf_block_min) && (nf_logical_block < (nf_block_min + NF_BUFFER_SIZE)))
1079   1        { /* we don't have to update the buffer */
1080   2          nf_gl_buf_idx = nf_logical_block - nf_block_min;
1081   2        }
1082   1        else 
1083   1        { /* we have to update the buffer */
1084   2          nf_look_up_table_block =  nf_lut_block[nf_zone];  /* get lut block address */
1085   2          if (nf_lut_modified)                              /* if lut have been modified */
1086   2          {
1087   3            nf_reassign_block();                            /* update lut */
1088   3          }
1089   2          gl_address     = ((Uint32)(nf_look_up_table_block)<<NF_SHIFT_SECTOR_BLOCK) 
1090   2                           + nf_lut_index[nf_zone];        /* calculate the address for LUT access */
1091   2          nf_spare_block = nf_spare_block_number[nf_zone]; /* initialize the number of spare block */
1092   2          nf_block_min   = nf_logical_block;               /* starting block value */
1093   2          nf_block_max   = ((nf_logical_block + NF_BUFFER_SIZE) > 999) ? (1000 - nf_logical_block) : NF_BUFFER_S
             -IZE;
1094   2      
1095   2          Nf_wait_busy();     
1096   2          Nf_send_command (NF_READ_CMD);                 /* Open the look-up table      */
1097   2          Nf_send_address (nf_logical_block << 1);       /* Column address Byte 0       */
C51 COMPILER V7.06   NF                                                                    05/05/2005 12:12:06 PAGE 19  

1098   2          Nf_send_address (nf_logical_block >> 7);       /* Column address Byte 1       */
1099   2          Nf_send_address ( ((Byte*)&gl_address)[3] );   /* Row address Byte 0          */
1100   2          Nf_send_address ( ((Byte*)&gl_address)[2] );   /* Row address Byte 1          */
1101   2          if (NF_5_CYCLE_ADDRESS_BIT)                    /* Size of card >= 128Mbytes ? */
1102   2            Nf_send_address ( ((Byte*)&gl_address)[1] ); /* Row address Byte 2          */
1103   2          Nf_send_command (NF_READ_CMD2);
1104   2          Nf_wait_busy();
1105   2        
1106   2          for (i = 0; i < nf_block_max ; i++)
1107   2          {
1108   3            nf_buf[i].b[0] = Nf_rd_byte();                /* read lut */
1109   3            nf_buf[i].b[1] = Nf_rd_byte();
1110   3          }
1111   2        
1112   2          if (change_zone)                                /* if it is a new zone, then */
1113   2          {                                               /* reload the spare buffer   */
1114   3            Nf_send_command(NF_RANDOM_READ_CMD_C1);       /* read LUT at column address */
1115   3            Nf_send_address(0xD0);                        /* 2000 -> 07D0               */
1116   3            Nf_send_address(0x07);
1117   3            Nf_send_command(NF_RANDOM_READ_CMD_C2);
1118   3            Nf_wait_busy();
1119   3            for (i = 0; i <= nf_spare_block; i++)
1120   3            {
1121   4              nf_buf_free[i]  =   (Uint16)(Nf_rd_byte()<<8);
1122   4              nf_buf_free[i] +=   Nf_rd_byte();
1123   4            }
1124   3          }
1125   2          nf_gl_buf_idx     = 0;                    /* initialize index for main buffer         */
1126   2          nf_gl_buf_idx_max = 0;                    /* initialize the max index for the buffer  */
1127   2      
1128   2        }
1129   1      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -