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

📄 nf.lst

📁 一个可作为mp3播放器固件的代码集,包括解码,播放,控制,任务管理等.
💻 LST
📖 第 1 页 / 共 5 页
字号:
1013   3            nf_block_erase((Uint32)(nf_block_to_be_deleted) << 5);
1014   3          }
1015   2          /* increase the main buffer index */
1016   2          nf_gl_buf_idx++;
1017   2          /* if zone change */
1018   2          if (nf_gl_buf_idx >= nf_block_max)
1019   2          {
1020   3            nf_write_open(gl_ptr_mem);
1021   3          }
1022   2          else
1023   2          {
1024   3            /* if the block in the buffer is already assign, then invert it with a spare block */
1025   3            if (!(nf_buf[nf_gl_buf_idx].w & 0x8000))                 
1026   3            {                                                 
1027   4              if ((nf_buf_free[gl_buf_free_idx] & 0x7FFF) == nf_lut_block[nf_zone])
1028   4              {
1029   5                gl_buf_free_idx++;
1030   5                if (gl_buf_free_idx >= nf_spare_block)
1031   5                {
1032   6                  gl_buf_free_idx = 0;
1033   6                }      
1034   5              }        
1035   4              /* invert the block and assign the next block to be deleted */
1036   4              nf_block_to_be_deleted       = nf_buf[nf_gl_buf_idx].w;
1037   4              nf_buf[nf_gl_buf_idx].w      = nf_buf_free[gl_buf_free_idx] & 0x7FFF;
1038   4              nf_buf_free[gl_buf_free_idx] = nf_block_to_be_deleted | 0x8000;
1039   4              /* block have to be deleted */
1040   4              nf_block_used = TRUE;
1041   4              /* increase the spare buffer index */
1042   4              if ((gl_buf_free_idx++) >= nf_spare_block)
1043   4              {
1044   5                gl_buf_free_idx = 0;
C51 COMPILER V7.50   NF                                                                    09/20/2005 21:47:45 PAGE 18  

1045   5              }
1046   4      
1047   4            }
1048   3            else /* The block is not assigned. Nothing to do */
1049   3            {
1050   4              nf_buf[nf_gl_buf_idx].w &= 0x7FFF;
1051   4              nf_block_used = FALSE;
1052   4            }
1053   3            /* update the max index buffer */
1054   3            if (nf_gl_buf_idx > nf_gl_buf_idx_max)
1055   3              nf_gl_buf_idx_max = nf_gl_buf_idx;
1056   3      
1057   3            /* Update current physical sector */
1058   3            nf_current_physical_sector_addr = (Uint32)(nf_buf[nf_gl_buf_idx].w) << 5;
1059   3            /* increase the logical block */
1060   3            nf_logical_block++;
1061   3            /* calculate the redundant block address */
1062   3            nf_calc_logical_block();
1063   3          }
1064   2        }
1065   1      
1066   1        Nf_CS_ON();
1067   1        if (!gl_cpt_page)
1068   1        {
1069   2          Nf_wait_busy();
1070   2          Nf_write_open_A_area(nf_current_physical_sector_addr, 0x00);
1071   2        }
1072   1        Nf_wr_byte(b);
1073   1        /* Increase internal page counter */
1074   1        gl_cpt_page++;                          
1075   1        if (((Byte*)&gl_cpt_page)[0] == NF_DATA_SIZE_H) /* check if end of data page */
1076   1        {
1077   2          nf_update_spare_data();
1078   2          Nf_send_command(NF_PAGE_PROGRAM_CMD);
1079   2          ((Byte*)&gl_cpt_page)[0] = 0;
1080   2          gl_ptr_mem++;
1081   2          if (!(((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK)) 
1082   2          {
1083   3            nf_busy = TRUE;
1084   3          }
1085   2          else
1086   2          {
1087   3            ((Byte*)&nf_current_physical_sector_addr)[3]++;
1088   3          }
1089   2        }
1090   1      
1091   1        return OK;
1092   1      }
1093          
1094          
1095          /*F**************************************************************************
1096          * NAME: nf_write_sector
1097          *----------------------------------------------------------------------------
1098          * PARAMS:
1099          *   global: gl_ptr_mem
1100          *
1101          * return:
1102          *   write status: OK: write done
1103          *                 KO: write not done
1104          *----------------------------------------------------------------------------
1105          * PURPOSE: 
1106          *   This function is an optimized function that writes nb-sector * 512 bytes
C51 COMPILER V7.50   NF                                                                    09/20/2005 21:47:45 PAGE 19  

1107          *   from USB controller to NF card
1108          *----------------------------------------------------------------------------
1109          * EXAMPLE:
1110          *----------------------------------------------------------------------------
1111          * NOTE:
1112          *   nb_sector always >= 1, can not be zero
1113          *----------------------------------------------------------------------------
1114          * REQUIREMENTS:
1115          *****************************************************************************/
1116          bit nf_write_sector (Uint16 nb_sector)
1117          {
1118   1      Byte j;
1119   1      
1120   1        do
1121   1        {   
1122   2          if (nf_busy)
1123   2          {
1124   3            nf_busy = FALSE;
1125   3            /* If previous block have to de deleted */
1126   3            if (nf_block_used)       
1127   3            {
1128   4              nf_block_erase((Uint32)(nf_block_to_be_deleted) << 5);
1129   4            }
1130   3            /* increase the main buffer index */
1131   3            nf_gl_buf_idx++;
1132   3            /* if zone change */
1133   3            if (nf_gl_buf_idx >= nf_block_max)
1134   3            {
1135   4              nf_write_open(gl_ptr_mem);
1136   4            }
1137   3            else
1138   3            {
1139   4              /* if the block in the buffer is already assign, then invert it with a spare block */
1140   4              if (!(nf_buf[nf_gl_buf_idx].w & 0x8000))                 
1141   4              {                                                 
1142   5                if ((nf_buf_free[gl_buf_free_idx] & 0x7FFF) == nf_lut_block[nf_zone])
1143   5                {
1144   6                  gl_buf_free_idx++;
1145   6                  if (gl_buf_free_idx >= nf_spare_block)
1146   6                  {
1147   7                    gl_buf_free_idx = 0;
1148   7                  }      
1149   6                }        
1150   5                /* invert the block and assign the next block to be deleted */
1151   5                nf_block_to_be_deleted       = nf_buf[nf_gl_buf_idx].w;
1152   5                nf_buf[nf_gl_buf_idx].w      = nf_buf_free[gl_buf_free_idx] & 0x7FFF;
1153   5                nf_buf_free[gl_buf_free_idx] = nf_block_to_be_deleted | 0x8000;
1154   5                /* block have to be deleted */
1155   5                nf_block_used = TRUE;
1156   5                /* increase the spare buffer index */
1157   5                if ((gl_buf_free_idx++) >= nf_spare_block)
1158   5                {
1159   6                  gl_buf_free_idx = 0;
1160   6                }
1161   5              }
1162   4              else /* The block is not assigned. Nothing to do */
1163   4              {
1164   5                nf_buf[nf_gl_buf_idx].w &= 0x7FFF;
1165   5                nf_block_used = FALSE;
1166   5              }
1167   4              /* update the max index buffer */
1168   4              if (nf_gl_buf_idx > nf_gl_buf_idx_max)
C51 COMPILER V7.50   NF                                                                    09/20/2005 21:47:45 PAGE 20  

1169   4                nf_gl_buf_idx_max = nf_gl_buf_idx;
1170   4        
1171   4              /* Update current physical sector */
1172   4              nf_current_physical_sector_addr = (Uint32)(nf_buf[nf_gl_buf_idx].w) << 5;
1173   4              /* increase the logical block */
1174   4              nf_logical_block++;
1175   4              /* calculate the redundant block address */
1176   4              nf_calc_logical_block();
1177   4            }
1178   3          }
1179   2      
1180   2          Nf_CS_ON();
1181   2        
1182   2          Nf_wait_busy();
1183   2          Nf_write_open_A_area(nf_current_physical_sector_addr, 0x00);
1184   2      
1185   2          for (j = 8; j != 0; j--)
1186   2          {
1187   3            while (!Usb_rx_complete());             /* wait end of reception */
1188   3            Nf_wr_byte(Usb_read_byte());            /* write 64 bytes to card */
1189   3            Nf_wr_byte(Usb_read_byte());
1190   3            Nf_wr_byte(Usb_read_byte());
1191   3            Nf_wr_byte(Usb_read_byte());
1192   3            Nf_wr_byte(Usb_read_byte());
1193   3            Nf_wr_byte(Usb_read_byte());
1194   3            Nf_wr_byte(Usb_read_byte());
1195   3            Nf_wr_byte(Usb_read_byte());
1196   3            Nf_wr_byte(Usb_read_byte());
1197   3            Nf_wr_byte(Usb_read_byte());
1198   3            Nf_wr_byte(Usb_read_byte());
1199   3            Nf_wr_byte(Usb_read_byte());
1200   3            Nf_wr_byte(Usb_read_byte());
1201   3            Nf_wr_byte(Usb_read_byte());
1202   3            Nf_wr_byte(Usb_read_byte());
1203   3            Nf_wr_byte(Usb_read_byte());
1204   3            Nf_wr_byte(Usb_read_byte());
1205   3            Nf_wr_byte(Usb_read_byte());
1206   3            Nf_wr_byte(Usb_read_byte());
1207   3            Nf_wr_byte(Usb_read_byte());
1208   3            Nf_wr_byte(Usb_read_byte());
1209   3            Nf_wr_byte(Usb_read_byte());
1210   3            Nf_wr_byte(Usb_read_byte());
1211   3            Nf_wr_byte(Usb_read_byte());
1212   3            Nf_wr_byte(Usb_read_byte());
1213   3            Nf_wr_byte(Usb_read_byte());
1214   3            Nf_wr_byte(Usb_read_byte());
1215   3            Nf_wr_byte(Usb_read_byte());
1216   3            Nf_wr_byte(Usb_read_byte());
1217   3            Nf_wr_byte(Usb_read_byte());
1218   3            Nf_wr_byte(Usb_read_byte());
1219   3            Nf_wr_byte(Usb_read_byte());
1220   3            Nf_wr_byte(Usb_read_byte());
1221   3            Nf_wr_byte(Usb_read_byte());
1222   3            Nf_wr_byte(Usb_read_byte());
1223   3            Nf_wr_byte(Usb_read_byte());
1224   3            Nf_wr_byte(Usb_read_byte());
1225   3            Nf_wr_byte(Usb_read_byte());
1226   3            Nf_wr_byte(Usb_read_byte());
1227   3            Nf_wr_byte(Usb_read_byte());
1228   3            Nf_wr_byte(Usb_read_byte());
1229   3            Nf_wr_byte(Usb_read_byte());
1230   3            Nf_wr_byte(Usb_read_byte());
C51 COMPILER V7.50   NF                                                                    09/20/2005 21:47:45 PAGE 21  

1231   3            Nf_wr_byte(Usb_read_byte());
1232   3            Nf_wr_byte(Usb_read_byte());
1233   3            Nf_wr_byte(Usb_read_byte());
1234   3            Nf_wr_byte(Usb_read_byte());
1235   3            Nf_wr_byte(Usb_read_byte());
1236   3            Nf_wr_byte(Usb_read_byte());
1237   3            Nf_wr_byte(Usb_read_byte());
1238   3            Nf_wr_byte(Usb_read_byte());
1239   3            Nf_wr_byte(Usb_read_byte());
1240   3            Nf_wr_byte(Usb_read_byte());
1241   3            Nf_wr_byte(Usb_read_byte());
1242   3            Nf_wr_byte(Usb_read_byte());
1243   3            Nf_wr_byte(Usb_read_byte());
1244   3            Nf_wr_byte(Usb_read_byte());
1245   3            Nf_wr_byte(Usb_read_byte());
1246   3            Nf_wr_byte(Usb_read_byte());
1247   3            Nf_wr_byte(Usb_read_byte());
1248   3            Nf_wr_byte(Usb_read_byte());
1249   3            Nf_wr_byte(Usb_read_byte());
1250   3            Nf_wr_byte(Usb_read_byte());
1251   3            Nf_wr_byte(Usb_read_byte());
1252   3            Usb_clear_RXOUT_PP();                      /* usb read acknowledgement */
1253   3          }
1254   2        
1255   2          /* Update spare data */
1256   2          Nf_wr_byte(0xFF);
1257   2          Nf_wr_byte(0xFF);
1258   2          Nf_wr_byte(0xFF);
1259   2          Nf_wr_byte(0xFF);
1260   2          Nf_wr_byte(0xFF);
1261   2          Nf_wr_byte(0xFF);
1262   2          Nf_wr_byte(((Byte*)&nf_redundant_logical_block_value)[0]);
1263   2          Nf_wr_byte(((Byte*)&nf_redundant_logical_block_value)[1]);
1264   2          Nf_wr_byte(0xFF);
1265   2          Nf_wr_byte(0xFF);
1266   2          Nf_wr_byte(0xFF);
1267   2          Nf_wr_byte(

⌨️ 快捷键说明

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