📄 nf_drv.lst
字号:
250 * block : physical block number
251 * nb_sector : number of sector to be copied
252 *
253 * return:
254 *----------------------------------------------------------------------------
255 * PURPOSE:
256 * Copy the first part of a block that is not modified during a write
257 * operation
258 *----------------------------------------------------------------------------
259 * EXAMPLE:
260 *----------------------------------------------------------------------------
261 * NOTE:
262 *----------------------------------------------------------------------------
263 * REQUIREMENTS:
264 * ram/xram:
265 * cycle:
266 * stack:
267 * code:
268 *****************************************************************************/
269 void nf_copy_block_head (void)
270 {
271 1 Byte j;
272 1 gl_address = (Uint32)(nf_block_to_be_deleted) << NF_SHIFT_SECTOR_BLOCK; /* address of the source phys
-ical block */
273 1
274 1 for (j = (((Byte*)&gl_ptr_mem)[3] & 0x3F); j != 0; j--)
275 1 {
276 2 Nf_wait_busy();
277 2 Nf_send_command (NF_READ_CMD);
278 2 Nf_send_address (0x00);
279 2 Nf_send_address (0x00);
280 2 Nf_send_address ( ((Byte*)&gl_address)[3] ); /* Row address Byte 0 */
281 2 Nf_send_address ( ((Byte*)&gl_address)[2] ); /* Row address Byte 1 */
282 2 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
283 2 Nf_send_address ( ((Byte*)&gl_address)[1] ); /* Row address Byte 2 */
284 2
285 2 Nf_send_command (NF_COPY_BACK_CMD); /* Send copy back command */
286 2 Nf_wait_busy();
287 2 Nf_send_command (NF_RANDOM_DATA_INPUT_CMD);
288 2 Nf_send_address (0x00);
289 2 Nf_send_address (0x00);
290 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[3] ); /* Row address Byte 0 */
291 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[2] ); /* Row address Byte 1 */
292 2 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ?*/
293 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[1] ); /* Row address Byte 2 */
294 2
295 2 Nf_send_command (NF_PAGE_PROGRAM_CMD);
296 2 ((Byte*)&nf_current_physical_sector_addr)[3]++; /* increase addresses */
297 2 ((Byte*)&gl_address)[3]++;
298 2 }
299 1
300 1 if (gl_cpt_page != 0)
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 6
301 1 {
302 2 nf_init_buffer();
303 2 Nf_wait_busy();
304 2 Nf_send_command (NF_READ_CMD);
305 2 Nf_send_address (0x00);
306 2 Nf_send_address (0x00);
307 2 Nf_send_address ( ((Byte*)&gl_address)[3] ); /* Row address Byte 0 */
308 2 Nf_send_address ( ((Byte*)&gl_address)[2] ); /* Row address Byte 1 */
309 2 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
310 2 Nf_send_address ( ((Byte*)&gl_address)[1] ); /* Row address Byte 2 */
311 2
312 2 Nf_send_command (NF_COPY_BACK_CMD);
313 2 Nf_wait_busy();
314 2 Nf_send_command (NF_RANDOM_DATA_INPUT_CMD);
315 2 Nf_send_address ( ((Byte*)&gl_cpt_page)[1] );
316 2 Nf_send_address ( ((Byte*)&gl_cpt_page)[0] );
317 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[3] ); /* Row address Byte 0
-*/
318 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[2] ); /* Row address Byte 1
-*/
319 2 if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ?
-*/
320 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[1] ); /* Row address Byte 2
-*/
321 2
322 2 for (j = (gl_cpt_page / 512); j < 4; j++)
323 2 {
324 3 nf_download_buffer();
325 3 nf_download_buffer();
326 3 }
327 2 nf_update_spare_data();
328 2 Nf_send_command (NF_PAGE_PROGRAM_CMD);
329 2 }
330 1 }
331
332
333 /*F**************************************************************************
334 * NAME: nf_copy_block_tail
335 *----------------------------------------------------------------------------
336 * PARAMS:
337 * block : physical block number
338 *
339 * return:
340 *----------------------------------------------------------------------------
341 * PURPOSE:
342 * Copy the last part of a block that is not modifiedd uring a write
343 * operation
344 *----------------------------------------------------------------------------
345 * EXAMPLE:
346 *----------------------------------------------------------------------------
347 * NOTE:
348 *----------------------------------------------------------------------------
349 * REQUIREMENTS:
350 * ram/xram:
351 * cycle:
352 * stack:
353 * code:
354 *****************************************************************************/
355 void nf_copy_block_tail (void)
356 {
357 1 Byte j;
358 1
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 7
359 1 /* address of the source block */
360 1 gl_address = ((Uint32)(nf_block_to_be_deleted) << NF_SHIFT_SECTOR_BLOCK) +
361 1 (((Byte*)&gl_ptr_mem)[3] & 0x3F);
362 1
363 1 if (gl_cpt_page != 0)
364 1 {
365 2 nf_init_buffer();
366 2 Nf_wait_busy();
367 2 Nf_send_command (NF_READ_CMD);
368 2 Nf_send_address (0x00);
369 2 Nf_send_address (0x00);
370 2 Nf_send_address ( ((Byte*)&gl_address)[3] ); /* row address Byte 0 */
371 2 Nf_send_address ( ((Byte*)&gl_address)[2] ); /* row address Byte 1 */
372 2 if (NF_5_CYCLE_ADDRESS_BIT) /* size of nf > 128Mbytes ? */
373 2 Nf_send_address ( ((Byte*)&gl_address)[1] ); /* row address Byte 2 */
374 2
375 2 Nf_send_command (NF_COPY_BACK_CMD); /* send copy back command */
376 2 Nf_wait_busy();
377 2 Nf_send_command (NF_RANDOM_DATA_INPUT_CMD);
378 2 Nf_send_address (0x00);
379 2 Nf_send_address (0x00);
380 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[3] ); /* row address Byte 0 */
381 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[2] ); /* row address Byte 1 */
382 2 if (NF_5_CYCLE_ADDRESS_BIT) /* size of nf > 128Mbytes ? */
383 2 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[1] ); /* row address Byte 2 */
384 2
385 2 for (j = ((Byte*)&gl_cpt_page)[0] >> 1; j != 0; j--)
386 2 {
387 3 nf_download_buffer();
388 3 nf_download_buffer();
389 3 }
390 2 Nf_send_command (NF_RANDOM_DATA_INPUT_CMD); /* spare area */
391 2 ((Byte*)&gl_cpt_page)[0] = 0x08;
392 2 Nf_send_address(0x00);
393 2 Nf_send_address(0x08);
394 2 nf_update_spare_data(); /* update spare data */
395 2 Nf_send_command (NF_PAGE_PROGRAM_CMD);
396 2
397 2 gl_cpt_page = 0;
398 2 gl_ptr_mem++;
399 2 ((Byte*)&nf_current_physical_sector_addr)[3]++;
400 2 ((Byte*)&gl_address)[3]++;
401 2 }
402 1
403 1 if (((Byte*)&gl_ptr_mem)[3] & 0x3F)
404 1 {
405 2 for (j = (((Byte*)&gl_ptr_mem)[3] & 0x3F); j < 0x40; j++)
406 2 {
407 3 Nf_wait_busy();
408 3 Nf_send_command (NF_READ_CMD);
409 3 Nf_send_address (0x00);
410 3 Nf_send_address (0x00);
411 3 Nf_send_address ( ((Byte*)&gl_address)[3] ); /* row address Byte 0 */
412 3 Nf_send_address ( ((Byte*)&gl_address)[2] ); /* row address Byte 1 */
413 3 if (NF_5_CYCLE_ADDRESS_BIT) /* size of nf > 128Mbytes ? */
414 3 Nf_send_address ( ((Byte*)&gl_address)[1] ); /* row address Byte 2 */
415 3 Nf_send_command (NF_COPY_BACK_CMD);
416 3 Nf_wait_busy();
417 3
418 3 Nf_send_command (NF_RANDOM_DATA_INPUT_CMD);
419 3 Nf_send_address (0x00);
420 3 Nf_send_address (0x00);
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 8
421 3 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[3] ); /* row address Byte 0 */
422 3 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[2] ); /* row address Byte 1 */
423 3 if (NF_5_CYCLE_ADDRESS_BIT) /* size of nf > 128Mbytes ? */
424 3 Nf_send_address ( ((Byte*)&nf_current_physical_sector_addr)[1] ); /* row address Byte 2 */
425 3 Nf_send_command (NF_PAGE_PROGRAM_CMD);
426 3 nf_current_physical_sector_addr++;
427 3 gl_address++;
428 3 }
429 2 }
430 1 }
431
432
433 /*F**************************************************************************
434 * NAME: nf_reassign_block
435 *----------------------------------------------------------------------------
436 * PARAMS:
437 *
438 * return:
439 *----------------------------------------------------------------------------
440 * PURPOSE:
441 * Reassign the block value in LUT (copy of LUT)
442 *----------------------------------------------------------------------------
443 * EXAMPLE:
444 *----------------------------------------------------------------------------
445 * NOTE:
446 *----------------------------------------------------------------------------
447 * REQUIREMENTS:
448 * ram/xram:
449 * cycle:
450 * stack:
451 * code:
452 *****************************************************************************/
453 void nf_reassign_block (void)
454 {
455 1 Byte i; /* Counter */
456 1 Uint16 start;
457 1 Uint32 address2; /* LUT source address */
458 1
459 1 if (nf_lut_index[nf_zone] == 63)
460 1 {
461 2 if ((nf_buf_free[gl_buf_free_idx] & 0x7FFF) == nf_look_up_table_block)
462 2 {
463 3 gl_buf_free_idx++;
464 3 if (gl_buf_free_idx > nf_spare_block)
465 3 {
466 4 gl_buf_free_idx = 0;
467 4 }
468 3 }
469 2
470 2 /* source address */
471 2 address2 = ((Uint32)(nf_look_up_table_block)<<NF_SHIFT_SECTOR_BLOCK) + 63;
472 2
473 2 nf_look_up_table_block = nf_buf_free[gl_buf_free_idx] & 0x7FFF;
474 2
475 2 gl_buf_free_idx++;
476 2 if (gl_buf_free_idx > nf_spare_block)
477 2 {
478 3 gl_buf_free_idx = 0;
479 3 }
480 2
481 2 /* target addres */
482 2 gl_address = ((Uint32)(nf_look_up_table_block) << NF_SHIFT_SECTOR_BLOCK);
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 9
483 2
484 2 nf_lut_index[nf_zone] = 0;
485 2
486 2 }
487 1 else
488 1 {
489 2 /* source address */
490 2 address2 = ((Uint32)(nf_look_up_table_block)<<NF_SHIFT_SECTOR_BLOCK) + nf_lut_index[nf_zone];
491 2 nf_lut_index[nf_zone]++;
492 2 /* target address */
493 2 gl_address = address2 + 1;
494 2 }
495 1
496 1 /* prepare a copy back command to update the lut */
497 1 Nf_wait_busy();
498 1 Nf_send_command (NF_READ_CMD);
499 1 Nf_send_address (0x00); /* column address Byte 0 */
500 1 Nf_send_address (0x00); /* column address Byte 1 */
501 1 Nf_send_address (((Byte*)&address2)[3]); /* row address Byte 0 */
502 1 Nf_send_address (((Byte*)&address2)[2]); /* row address Byte 1 */
503 1 if (NF_5_CYCLE_ADDRESS_BIT) /* size of nf > 128Mbytes ? */
504 1 Nf_send_address ( ((Byte*)&address2)[1] ); /* row address Byte 2 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -