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

📄 nf.lst

📁 串口小程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
1017   1        {
1018   2          nf_busy = FALSE;
1019   2          /* If previous block have to de deleted */
1020   2          if (nf_block_used)       
1021   2          {
1022   3            nf_block_erase((Uint32)(nf_block_to_be_deleted) << 5);
1023   3          }
1024   2          /* increase the main buffer index */
1025   2          nf_gl_buf_idx++;
1026   2          /* if zone change */
1027   2          if (nf_gl_buf_idx >= nf_block_max)
1028   2          {
1029   3            nf_write_open(gl_ptr_mem);
1030   3          }
1031   2          else
1032   2          {
1033   3            /* if the block in the buffer is already assign, then invert it with a spare block */
1034   3            if (!(nf_buf[nf_gl_buf_idx].w & 0x8000))                 
1035   3            {                                                 
1036   4              if ((nf_buf_free[gl_buf_free_idx] & 0x7FFF) == nf_lut_block[nf_zone])
1037   4              {
1038   5                gl_buf_free_idx++;
1039   5                if (gl_buf_free_idx >= nf_spare_block)
1040   5                {
1041   6                  gl_buf_free_idx = 0;
1042   6                }      
1043   5              }        
1044   4              /* invert the block and assign the next block to be deleted */
C51 COMPILER V7.02a   NF                                                                   09/13/2007 11:53:06 PAGE 18  

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

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

1169   6                }
1170   5              }
1171   4              else /* The block is not assigned. Nothing to do */
1172   4              {
1173   5                nf_buf[nf_gl_buf_idx].w &= 0x7FFF;
1174   5                nf_block_used = FALSE;
1175   5              }
1176   4              /* update the max index buffer */
1177   4              if (nf_gl_buf_idx > nf_gl_buf_idx_max)
1178   4                nf_gl_buf_idx_max = nf_gl_buf_idx;
1179   4        
1180   4              /* Update current physical sector */
1181   4              nf_current_physical_sector_addr = (Uint32)(nf_buf[nf_gl_buf_idx].w) << 5;
1182   4              /* increase the logical block */
1183   4              nf_logical_block++;
1184   4              /* calculate the redundant block address */
1185   4              nf_calc_logical_block();
1186   4            }
1187   3          }
1188   2      
1189   2          Nf_CS_ON();
1190   2        
1191   2          Nf_wait_busy();
1192   2          Nf_write_open_A_area(nf_current_physical_sector_addr, 0x00);
1193   2      
1194   2          for (j = 8; j != 0; j--)
1195   2          {
1196   3            while (!Usb_rx_complete());             /* wait end of reception */
1197   3            Nf_wr_byte(Usb_read_byte());            /* write 64 bytes to card */
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.02a   NF                                                                   09/13/2007 11:53:06 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            Nf_wr_byte(Usb_read_byte());
1253   3            Nf_wr_byte(Usb_read_byte());
1254   3            Nf_wr_byte(Usb_read_byte());
1255   3            Nf_wr_byte(Usb_read_byte());
1256   3            Nf_wr_byte(Usb_read_byte());
1257   3            Nf_wr_byte(Usb_read_byte());
1258   3            Nf_wr_byte(Usb_read_byte());
1259   3            Nf_wr_byte(Usb_read_byte());
1260   3            Nf_wr_byte(Usb_read_byte());
1261   3            Usb_clear_RXOUT_PP();                      /* usb read acknowledgement */
1262   3          }
1263   2        
1264   2          /* Update spare data */
1265   2          Nf_wr_byte(0xFF);
1266   2          Nf_wr_byte(0xFF);
1267   2          Nf_wr_byte(0xFF);
1268   2          Nf_wr_byte(0xFF);
1269   2          Nf_wr_byte(0xFF);
1270   2          Nf_wr_byte(0xFF);
1271   2          Nf_wr_byte(((Byte*)&nf_redundant_logical_block_value)[0]

⌨️ 快捷键说明

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