📄 nf_drv.lst
字号:
271 xCurErasedBlock = nTmp;
272 }
273
274 Nf_wait_busy();
275 Test_nf_write_open_A_area(pos, 0);
276
277 for (nTmp=0; nTmp<512; nTmp++)
278 Nf_wr_byte(pBuf[nTmp]);
279
280
281 Nf_wait_busy();
282 Test_nf_send_command(NF_PAGE_PROGRAM_CMD);
283
284
285
286 Nf_wait_busy();
287
288
289 return OK;
290 }*/
291
292 /************************************
293 *pos:值为页地址,而非实际地址!!!!!
294 ************************************/
295 bit nf_write_onepage2(Uint32 pos, Byte* pBuf1, Byte* pBuf2, Byte* pBuf3, Byte* pBuf4)
296 {
297 1 /*first check to see whether to erase block*/
298 1 Uint8 status = 0;
299 1 data Uint32 nTmp;
300 1 data Uint8 tmpCount;
301 1
C51 COMPILER V8.02 NF_DRV 09/25/2008 19:29:37 PAGE 6
302 1 nTmp = pos >> 5;/*row address*/
303 1 if ((FALSE == xEraseStatus) || (xCurErasedBlock != nTmp))
304 1 {
305 2 nf_block_erase(pos<<8);
306 2 /*debug: test R/B*/
307 2
308 2 nf_check_status();
309 2
310 2 xEraseStatus = TRUE;
311 2 xCurErasedBlock = nTmp;
312 2 }
313 1
314 1 /*write routine*/
315 1 Nf_wait_busy();
316 1 Test_nf_write_open_A_area(pos, 0);
317 1
318 1 for (tmpCount=0; tmpCount<128; tmpCount++)
319 1 D12_Y3 = pBuf1[tmpCount];
320 1 for (tmpCount=0; tmpCount<128; tmpCount++)
321 1 D12_Y3 = pBuf2[tmpCount];
322 1 for (tmpCount=0; tmpCount<128; tmpCount++)
323 1 D12_Y3 = pBuf3[tmpCount];
324 1 for (tmpCount=0; tmpCount<128; tmpCount++)
325 1 D12_Y3 = pBuf4[tmpCount];
326 1
327 1
328 1 //需要等待
329 1 // delay();//不需要等待,06.04.11日测试的结果
330 1 Nf_wait_busy();
331 1 Test_nf_send_command(NF_PAGE_PROGRAM_CMD);
332 1
333 1 Nf_wait_busy();
334 1
335 1 return OK;
336 1 }
337
338 /********************************************
339 *写任意长度到flash中,这里要求一次不能跨越两页
340 *一旦跨越两页,由外部处理函数处理
341 *pos:为需要写的实际地址,包括行地址和列地址
342 *********************************************/
343 bit nf_write_onebuf(Uint32 pos, Byte* pBuf, Uint16 nLen)
344 {
345 1 /*first check to see whether to erase block*/
346 1 Uint8 status = 0;
347 1 // data Uint32 nTmp;
348 1 data Uint16 tmpCount;
349 1 // Uint8 c;
350 1 // Nf_CS_ON();
351 1 // nTmp = pos >> (5+9);/*row address*/
352 1 if((pos&0x00003fff)==0)
353 1 {
354 2 nf_block_erase(pos>>1);//nTmp<<(5+8));
355 2
356 2 nf_check_status();
357 2
358 2 }
359 1 /*
360 1 if ((FALSE == xEraseStatus) || (xCurErasedBlock != nTmp))
361 1 {
362 1 nf_block_erase(pos>>1);//nTmp<<(5+8));
363 1 c=(unsigned char)(pos>>9);
C51 COMPILER V8.02 NF_DRV 09/25/2008 19:29:37 PAGE 7
364 1 siob_send(&c,1);
365 1 c=(unsigned char)(pos>>17);
366 1 siob_send(&c,1);
367 1
368 1 nf_check_status();
369 1
370 1 xEraseStatus = TRUE;
371 1 xCurErasedBlock = nTmp;
372 1 }
373 1 */
374 1 /*write routine*/
375 1 Nf_wait_busy();
376 1
377 1 if (0 == (pos & 0x00000100))
378 1 {
379 2 Test_nf_write_open_A_area(pos>>9, (Byte)pos);
380 2 }
381 1 else
382 1 {
383 2 Test_nf_write_open_B_area(pos>>9, (Byte)pos);
384 2 }
385 1
386 1 for (tmpCount=0; tmpCount<nLen; tmpCount++)
387 1 D12_Y3 = pBuf[tmpCount];
388 1 Nf_wait_busy();
389 1 Test_nf_send_command(NF_PAGE_PROGRAM_CMD);
390 1
391 1 Nf_wait_busy();
392 1 return OK;
393 1 }
394 /********************************************
395 *调用该函数前,需要由调用者自己调用擦除函数
396 *写任意长度到flash中,这里要求一次不能跨越两页
397 *一旦跨越两页,由外部处理函数处理
398 *pos:为需要写的实际地址,包括行地址和列地址
399 *********************************************/
400 bit nf_write_onebuf_withouterase(Uint32 pos, Byte* pBuf, Uint8 nLen)
401 {
402 1 /*first check to see whether to erase block*/
403 1 Uint8 status = 0;
404 1 data Uint8 tmpCount;
405 1 Nf_wait_busy();
406 1 if (0 == (pos & 0x00000100))
407 1 {
408 2 Test_nf_write_open_A_area(pos>>9, (Byte)pos);
409 2 }
410 1 else
411 1 {
412 2 Test_nf_write_open_B_area(pos>>9, (Byte)pos);
413 2 }
414 1
415 1 for (tmpCount=0; tmpCount<nLen; tmpCount++)
416 1 D12_Y3 = pBuf[tmpCount];
417 1
418 1 Nf_wait_busy();
419 1 Test_nf_send_command(NF_PAGE_PROGRAM_CMD);
420 1
421 1 Nf_wait_busy();
422 1 return OK;
423 1 }
424
425
C51 COMPILER V8.02 NF_DRV 09/25/2008 19:29:37 PAGE 8
426 /*F**************************************************************************
427 * NAME: nf_write_quarterpage
428 *----------------------------------------------------------------------------
429 * PARAMS:
430 * pos: the start row address
431 * pbuf: the content to write
432 * return:
433 * OK : write done
434 * KO : write not done
435 *----------------------------------------------------------------------------
436 * PURPOSE: write one on Nand Flash Media. It is only permitted to write 128 Bytes
437 * when writting on flash(our assume).
438 *----------------------------------------------------------------------------
439 * EXAMPLE:
440 *----------------------------------------------------------------------------
441 * NOTE:
442 * This function use the global variable Uint32 address
443 *----------------------------------------------------------------------------
444 * REQUIREMENTS:
445 * ram/xram:
446 * cycle:
447 * stack:
448 * code:
449 *****************************************************************************/
450 /*bit nf_write_quarterpage(Uint32 pos, Byte* pBuf)
451 {
452 Uint8 status = 0;
453 Uint32 nTmp;
454 Byte nCol;
455
456 nTmp = pos >> 13;
457 if ((FALSE == xEraseStatus) || (xCurErasedBlock != nTmp))
458 {
459 nf_block_erase(pos);
460
461 nf_check_status();
462
463 xEraseStatus = TRUE;
464 xCurErasedBlock = nTmp;
465 }
466
467 Nf_wait_busy();
468 nTmp = (pos >> 8);
469 nCol = pos;
470 if (0 == halfpage)
471 {
472 Test_nf_write_open_A_area(nTmp, nCol);
473 }
474 else
475 {
476 Test_nf_write_open_B_area(nTmp, nCol);
477 }
478 for (nTmp=0; nTmp<256; nTmp++)
479 Nf_wr_byte(pBuf[nTmp]);
480
481
482 Nf_wait_busy();
483 Test_nf_send_command(NF_PAGE_PROGRAM_CMD);
484
485
486 Nf_wait_busy();
487
C51 COMPILER V8.02 NF_DRV 09/25/2008 19:29:37 PAGE 9
488 return OK;
489 }*/
490
491 /*F**************************************************************************
492 * NAME: nf_read_tobuf
493 *----------------------------------------------------------------------------
494 * PARAMS:
495 *
496 * return:
497 * OK : write done
498 * KO : write not done
499 *----------------------------------------------------------------------------
500 * PURPOSE: read flash and copy to flash
501 *----------------------------------------------------------------------------
502 * EXAMPLE:
503 *----------------------------------------------------------------------------
504 * NOTE:
505 * This function use the global variable Uint32 address
506 *----------------------------------------------------------------------------
507 * REQUIREMENTS:
508 * ram/xram:
509 * cycle:
510 * stack:
511 * code:
512 *****************************************************************************/
513 bit nf_read_tobuf(Uint32 pos, Byte* pbuf, Uint8 nlen)
514 {
515 1 /*first check whether start A zone or B zone*/
516 1 Uint32 nPageAddr;
517 1 Uint32 nBlockAddr;
518 1 Uint32 nTmp;
519 1 Uint8 i;
520 1 nPageAddr = pos>>9;
521 1 nBlockAddr = nPageAddr>>5;
522 1 i = (Byte)pos;
523 1 Nf_wait_busy();
524 1
525 1 if (0 == (pos & 0x00000100))
526 1 {
527 2 Test_nf_read_open_A_area(nPageAddr, i);
528 2
529 2 }
530 1 else
531 1 {
532 2 Test_nf_read_open_B_area(nPageAddr, i);
533 2 }
534 1
535 1 nBlockAddr = ((pos>>14)+1) << 14;
536 1 nPageAddr = (nPageAddr+1)<<9;
537 1 Nf_wait_busy();
538 1 for (i=0; i<nlen; i++)
539 1 {
540 2 Test_nf_rd_byte(pbuf[i]);
541 2
542 2 pos++;
543 2 if (pos >= nPageAddr)
544 2 {
545 3 /*new block*/
546 3 if (pos >= nBlockAddr)
547 3 {
548 4 nTmp = nBlockAddr>>9;
549 4 Test_nf_read_open_A_area(nTmp, 0x00);
C51 COMPILER V8.02 NF_DRV 09/25/2008 19:29:37 PAGE 10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -