📄 nf_drv.lst
字号:
235 * NAME: nf_copy_block_head
236 *----------------------------------------------------------------------------
237 * PARAMS:
C51 COMPILER V7.00 NF_DRV 04/28/2004 09:31:55 PAGE 5
238 * block : physical block number
239 * nb_sector : number of sector to be copied
240 *
241 * return:
242 *----------------------------------------------------------------------------
243 * PURPOSE:
244 * Copy the first part of a block that is not modified during a write
245 * operation
246 *----------------------------------------------------------------------------
247 * EXAMPLE:
248 *----------------------------------------------------------------------------
249 * NOTE:
250 *----------------------------------------------------------------------------
251 * REQUIREMENTS:
252 * ram/xram:
253 * cycle:
254 * stack:
255 * code:
256 *****************************************************************************/
257 void nf_copy_block_head (void)
258 {
259 1 Byte j;
260 1
261 1 /* address of the source physical block */
262 1 gl_address = (Uint32)(nf_block_to_be_deleted) << 5;
263 1
264 1 for (j = (((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK); j != 0; j--)
265 1 {
266 2 /* 1st half page */
267 2 Nf_wait_busy();/* Read Open */
268 2 Nf_read_open_A_area(gl_address, 0x00);
269 2 nf_upload_buffer();
270 2 Nf_write_open_A_area(nf_current_physical_sector_addr, 0x00); /* Write open */
271 2 nf_download_buffer();
272 2 Nf_send_command (NF_PAGE_PROGRAM_CMD);
273 2 Nf_wait_busy();
274 2
275 2 /* 2nd half page */
276 2 Nf_read_open_B_area(gl_address, 0x00); /* Read Open */
277 2 nf_upload_buffer();
278 2 Nf_write_open_B_area(nf_current_physical_sector_addr, 0x00); /* Write open */
279 2 nf_download_buffer();
280 2 /* Update spare data */
281 2 nf_update_spare_data();
282 2
283 2 Nf_send_command (NF_PAGE_PROGRAM_CMD);
284 2
285 2 /* increase counter */
286 2 ((Byte*)&nf_current_physical_sector_addr)[3]++;
287 2 ((Byte*)&gl_address)[3]++;
288 2 }
289 1 }
290
291
292 /*F**************************************************************************
293 * NAME: nf_copy_block_tail
294 *----------------------------------------------------------------------------
295 * PARAMS:
296 * block : physical block number
297 *
298 * return:
299 *----------------------------------------------------------------------------
C51 COMPILER V7.00 NF_DRV 04/28/2004 09:31:55 PAGE 6
300 * PURPOSE:
301 * Copy the last part of a block that is not modifiedd uring a write
302 * operation
303 *----------------------------------------------------------------------------
304 * EXAMPLE:
305 *----------------------------------------------------------------------------
306 * NOTE:
307 *----------------------------------------------------------------------------
308 * REQUIREMENTS:
309 * ram/xram:
310 * cycle:
311 * stack:
312 * code:
313 *****************************************************************************/
314 void nf_copy_block_tail (void)
315 {
316 1 Byte j;
317 1
318 1 /* Address of the source block */
319 1 gl_address = ((Uint32)(nf_block_to_be_deleted) << 5) + (((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK);
320 1
321 1 for (j = (((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK); j < NF_PAGE_PER_BLOCK; j++)
322 1 {
323 2 /* 1st half page */
324 2 Nf_wait_busy();
325 2 Nf_read_open_A_area(gl_address, 0x00); /* Read Open */
326 2 nf_upload_buffer();
327 2 Nf_write_open_A_area(nf_current_physical_sector_addr, 0x00); /* Write open */
328 2 nf_download_buffer();
329 2
330 2 Nf_send_command (NF_PAGE_PROGRAM_CMD);
331 2 Nf_wait_busy();
332 2
333 2 /* 2nd half page */
334 2 Nf_read_open_B_area(gl_address, 0x00); /* Read Open */
335 2 nf_upload_buffer();
336 2 Nf_write_open_B_area(nf_current_physical_sector_addr, 0x00); /* Write open */
337 2 nf_download_buffer();
338 2
339 2 nf_update_spare_data(); /* Update spare data */
340 2
341 2 Nf_send_command (NF_PAGE_PROGRAM_CMD);
342 2
343 2 ((Byte*)&nf_current_physical_sector_addr)[3]++;
344 2 ((Byte*)&gl_address)[3]++;
345 2 }
346 1 }
347
348
349 /*F**************************************************************************
350 * NAME: nf_reassign_block
351 *----------------------------------------------------------------------------
352 * PARAMS:
353 *
354 * return:
355 *----------------------------------------------------------------------------
356 * PURPOSE:
357 * Reassign the block value in LUT (copy of LUT)
358 *----------------------------------------------------------------------------
359 * EXAMPLE:
360 *----------------------------------------------------------------------------
361 * NOTE:
C51 COMPILER V7.00 NF_DRV 04/28/2004 09:31:55 PAGE 7
362 *----------------------------------------------------------------------------
363 * REQUIREMENTS:
364 * ram/xram:
365 * cycle:
366 * stack:
367 * code:
368 *****************************************************************************/
369 void nf_reassign_block (void)
370 {
371 1 Byte j, k;
372 1 Uint16 start;
373 1 Uint16 block_start;
374 1 xdata Uint32 address2; /* LUT Source address */
375 1
376 1 if (nf_lut_index[nf_zone] == 7)
377 1 {
378 2 if ((nf_buf_free[gl_buf_free_idx] & 0x7FFF) == nf_look_up_table_block)
379 2 {
380 3 gl_buf_free_idx++;
381 3 if (gl_buf_free_idx >= nf_spare_block)
382 3 {
383 4 gl_buf_free_idx = 0;
384 4 }
385 3 }
386 2
387 2 /* Source address */
388 2 address2 = ((Uint32)(nf_look_up_table_block)<<5) + 28;
389 2
390 2 nf_look_up_table_block = nf_buf_free[gl_buf_free_idx] & 0x7FFF;
391 2
392 2 gl_buf_free_idx++;
393 2 if (gl_buf_free_idx >= nf_spare_block)
394 2 {
395 3 gl_buf_free_idx = 0;
396 3 }
397 2
398 2 /* Target address : recopy the last 2Kb */
399 2 gl_address = ((Uint32)(nf_look_up_table_block) << 5);
400 2
401 2 nf_lut_index[nf_zone] = 0;
402 2
403 2 }
404 1 else
405 1 {
406 2 /* Source address */
407 2 address2 = ((Uint32)(nf_look_up_table_block)<<5) + ((Uint32)(nf_lut_index[nf_zone])<<2);
408 2
409 2 nf_lut_index[nf_zone]++;
410 2
411 2 /* Target address */
412 2 gl_address = address2 + 4;
413 2 }
414 1
415 1 j = 0;
416 1 k = 0;
417 1 start = 0;
418 1 block_start = nf_block_min;
419 1
420 1 do
421 1 {
422 2 Nf_wait_busy();
423 2 Nf_read_open_A_area(address2, 0x00); /* Open look-up table in read mode */
C51 COMPILER V7.00 NF_DRV 04/28/2004 09:31:55 PAGE 8
424 2 nf_upload_buffer();
425 2
426 2 while ((k <= nf_gl_buf_idx_max) && (start <= block_start) && ((start + 128) > block_start))
427 2 {
428 3 gl_buffer[(2 * (block_start & 0x7F))] = nf_buf[k].b[0];
429 3 gl_buffer[(2 * (block_start & 0x7F))+1] = nf_buf[k].b[1];
430 3 k++;
431 3 block_start++;
432 3 }
433 2
434 2 Nf_write_open_A_area(gl_address, 0x00);
435 2 nf_download_buffer(); /* Write 256 bytes from the buffer */
436 2
437 2 Nf_send_command(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
438 2
439 2 start += 128;
440 2
441 2 Nf_wait_busy(); /* Wait for R/B signal */
442 2 Nf_read_open_B_area(address2, 0x00); /* Open look-up table in read mode */
443 2 nf_upload_buffer();
444 2
445 2 while ((k <= nf_gl_buf_idx_max) && (start <= block_start) && ((start + 128) > block_start))
446 2 {
447 3 gl_buffer[(2 * (block_start & 0x7F))] = nf_buf[k].b[0];
448 3 gl_buffer[(2 * (block_start & 0x7F))+1] = nf_buf[k].b[1];
449 3 k++;
450 3 block_start++;
451 3 }
452 2
453 2 if (start >= 896) /* This part update the free physical block table */
454 2 {
455 3 k = 208;
456 3 for (j = 0; j <= 23; j++)
457 3 {
458 4 gl_buffer[k] = nf_buf_free[j]>>8;
459 4 gl_buffer[k+1] = nf_buf_free[j];
460 4 k += 2;
461 4 }
462 3 }
463 2
464 2 Nf_write_open_B_area(gl_address, 0x00);
465 2 nf_download_buffer(); /* Write 256 bytes from the buffer */
466 2
467 2 Nf_wr_byte(0xFF);
468 2 Nf_wr_byte(0xFF);
469 2 Nf_wr_byte(0xFF);
470 2 Nf_wr_byte(0xFF);
471 2 Nf_wr_byte(0xFF);
472 2 Nf_wr_byte(0xFF);
473 2 Nf_wr_byte(0xE8);
474 2 Nf_wr_byte(0xFF);
475 2 Nf_wr_byte(0xFF);
476 2 Nf_wr_byte(0xFF);
477 2 Nf_wr_byte(0xFF);
478 2 Nf_wr_byte(0xE8);
479 2 Nf_wr_byte(0xFF);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -