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

📄 nf_drv.lst

📁 通过车载终端采集GPS数据
💻 LST
📖 第 1 页 / 共 3 页
字号:
 550   4                      nBlockAddr = ((nBlockAddr>>14)+1) << 14;
 551   4                  }
 552   3                  else
 553   3                  {
 554   4                      Test_nf_read_open_A_area(pos>>9, 0x00);
 555   4                  }   
 556   3                              nPageAddr = ((nPageAddr>>9)+1) << 9;
 557   3                              Nf_wait_busy();
 558   3                      }
 559   2              }
 560   1              return OK;
 561   1      }
 562          
 563          
 564          data Uint32 nopenPage;
 565          //函数假定一次读操作内不会跨过两页
 566          /*bit nf_read_tobuf2(Uint32 pos, Byte* pbuf, Uint8 nlen)  
 567          {
 568              static bit bInitFlag = 0;
 569              data Uint32 nPageAddr;
 570              data Byte i;
 571              nPageAddr = pos>>9;
 572              Nf_wait_busy();
 573              if (0 == bInitFlag)
 574              {
 575                  bInitFlag = 1;
 576                  nopenPage = nPageAddr;
 577                  i = (Byte)pos;
 578                  Test_nf_read_open_A_area(nPageAddr, i);
 579                  Nf_wait_busy();
 580                  for (i=0; i<nlen; i++)
 581                      pbuf[i] = D12_Y3;
 582              }
 583              else
 584              {
 585                  if (nopenPage == nPageAddr)
 586                  {
 587                      //不需要重新打开页
 588                      for (i=0; i<nlen; i++)
 589                          pbuf[i] = D12_Y3;
 590                  }
 591                  else
 592                  {
 593                      nopenPage = nPageAddr;
 594                      i = (Byte)pos;
 595                      Test_nf_read_open_A_area(nPageAddr, i);
 596                      Nf_wait_busy();
 597                      for (i=0; i<nlen; i++)
 598                          pbuf[i] = D12_Y3;
 599                  }
 600              }
 601                  return OK;
 602          }*/
 603          
 604          //函数支持一次读两页
 605          bit nf_read_tobuf3(Uint32 pos, Byte* pbuf, Uint8 nlen)  
 606          {
 607   1          static bit bInit = 0;
 608   1          data Uint32 nPageAddr, nNextPage, nCurAddr;
 609   1          data Byte i;
 610   1          nPageAddr = pos>>9;
 611   1          nCurAddr = pos;
C51 COMPILER V8.02   NF_DRV                                                                09/25/2008 19:29:37 PAGE 11  

 612   1          Nf_wait_busy();
 613   1          if (0 == bInit)
 614   1          {
 615   2              bInit = 1;
 616   2              nopenPage = nPageAddr;
 617   2              i = (Byte)pos;
 618   2              Test_nf_read_open_A_area(nPageAddr, i);
 619   2              Nf_wait_busy();
 620   2              nPageAddr++;
 621   2              nNextPage = nPageAddr<<9;
 622   2              for (i=0; i<nlen; i++)
 623   2              {
 624   3                  pbuf[i] = D12_Y3;
 625   3                  nCurAddr++;
 626   3                  if (nCurAddr >= nNextPage)
 627   3                  {
 628   4                      Test_nf_read_open_A_area(nPageAddr, 0);
 629   4                      nopenPage = nPageAddr;
 630   4                      nNextPage += 512;
 631   4                  }
 632   3              }
 633   2          }
 634   1          else
 635   1          {        
 636   2              if (nopenPage == nPageAddr)
 637   2              {
 638   3                  nPageAddr++;
 639   3                  nNextPage = nPageAddr<<9;
 640   3                  //不需要重新打开页
 641   3                  for (i=0; i<nlen; i++)
 642   3                  {
 643   4                      pbuf[i] = D12_Y3;
 644   4                      nCurAddr++;
 645   4                      if (nCurAddr >= nNextPage)
 646   4                      {
 647   5                          Test_nf_read_open_A_area(nPageAddr, 0);
 648   5                          nopenPage = nPageAddr;
 649   5                          nNextPage += 512;
 650   5                      }
 651   4                  }
 652   3              }
 653   2              else
 654   2              {
 655   3                  nopenPage = nPageAddr;
 656   3                  i = (Byte)pos;
 657   3                  //Test_nf_read_open_A_area(nPageAddr, i);old
 658   3                  /**原有程序存在一定的bug,但是不会有影响**/
 659   3                  if (0 == (pos & 0x00000100))
 660   3                      {
 661   4                      Test_nf_read_open_A_area(nPageAddr, i);
 662   4                      
 663   4                      }
 664   3                      else
 665   3                      {
 666   4                      Test_nf_read_open_B_area(nPageAddr, i);
 667   4                      }
 668   3                  /***结束,原有的最多只会影响256个字节***/
 669   3                  Nf_wait_busy();
 670   3                  nPageAddr++;
 671   3                  nNextPage = nPageAddr<<9;
 672   3                  for (i=0; i<nlen; i++)
 673   3                  {
C51 COMPILER V8.02   NF_DRV                                                                09/25/2008 19:29:37 PAGE 12  

 674   4                      pbuf[i] = D12_Y3;
 675   4                      nCurAddr++;
 676   4                      if (nCurAddr >= nNextPage)
 677   4                      {
 678   5                          Test_nf_read_open_A_area(nPageAddr, 0);
 679   5                          nopenPage = nPageAddr;
 680   5                          nNextPage += 512;
 681   5                      }
 682   4                  }
 683   3              }
 684   2          }
 685   1              return OK;
 686   1      }
 687          
 688          
 689          /*F**************************************************************************
 690          * NAME: nf_init
 691          *----------------------------------------------------------------------------
 692          * PARAMS:
 693          *
 694          * return:
 695          *   OK : init complete
 696          *   KO : - NF not supported or not recognise
 697          *----------------------------------------------------------------------------
 698          * PURPOSE:
 699          *   NF initialisation
 700          *----------------------------------------------------------------------------
 701          * EXAMPLE:
 702          *----------------------------------------------------------------------------
 703          * NOTE:
 704          *----------------------------------------------------------------------------
 705          * REQUIREMENTS:
 706          *****************************************************************************/
 707          bit nf_init (void)
 708          {
 709   1          Uint8 volatile test;
 710   1              D17CS = 0xff;
 711   1              D17CS &= 0x7f;
 712   1              D12_Y0 = D17CS;
 713   1          xCurErasedBlock = 0;
 714   1              xEraseStatus = FALSE;
 715   1              halfpage = 0;
 716   1      
 717   1          nf_wp_on();
 718   1          Test_nf_send_command(NF_RESET_CMD);
 719   1      
 720   1      
 721   1      
 722   1      #if (NF_CAPACITY_AUTO_DETECT == TRUE)               /* Auto Detect the type of nand-flash  */
 723   1              //test here
 724   1              test = 0;
 725   1                      
 726   1              Test_nf_send_command(NF_READ_ID_CMD);
 727   1      
 728   1      
 729   1              Test_nf_send_address(0x00);
 730   1      
 731   1              
 732   1              Nf_wait_busy();
 733   1              delay();
 734   1              test = D12_Y3;
 735   1              test = D12_Y3;                                     /* Maker  code */
C51 COMPILER V8.02   NF_DRV                                                                09/25/2008 19:29:37 PAGE 13  

 736   1              switch (test)                             /* Device code */
 737   1              {
 738   2                    /***************************************************************************/
 739   2                    case 0x73 :                                     /*------- 16 Mbyte --------*/
 740   2                      nf_device_type = NF_SIZE_16MB;
 741   2                      nf_zone_max = 1;                              /* 1 zone : 1024 blocks    */
 742   2                      nf_4_cycle_address = 0;                       /* 3 address cycles        */
 743   2                      break;
 744   2                    /***************************************************************************/
 745   2                    case 0x75 :                                     /*------- 32 Mbyte --------*/
 746   2                      nf_device_type = NF_SIZE_32MB;
 747   2                      nf_zone_max = 2;                              /* 2 zones : 2048 blocks   */
 748   2                      nf_4_cycle_address = 0;                       /* 3 address cycles        */
 749   2                      break;
 750   2                    /***************************************************************************/
 751   2                    case 0x76 :                                     /*------- 64 Mbyte --------*/
 752   2                      nf_device_type = NF_SIZE_64MB;
 753   2                      nf_zone_max = 4;                              /* 4 zones : 4096 blocks   */
 754   2                      nf_4_cycle_address = 1;                       /* 4 address cycles        */
 755   2                      break;
 756   2                    /***************************************************************************/
 757   2                    case 0x79 :                                     /*------ 128 Mbyte --------*/
 758   2                      nf_device_type = NF_SIZE_128MB;
 759   2                      nf_zone_max = 8;                              /* 8 zones : 8192 blocks   */
 760   2                      nf_4_cycle_address = 1;                       /* 4 address cycles        */
 761   2                      break;
 762   2                    default:
 763   2                      return KO;
 764   2                  }                   
 765   1      #endif
 766   1              nf_check_status();
 767   1              
 768   1      //      nf_testchip();
 769   1              return OK;
 770   1      }
 771          
 772          bit nf_testchip()
 773          {
 774   1          Uint16 nBlockNum;
 775   1          Uint16 i;
 776   1          Uint32 nTestBlock;
 777   1          Uint8 nValidFlag;
 778   1          switch (nf_device_type)
 779   1          {
 780   2              case NF_SIZE_32MB:
 781   2                  nBlockNum = 2048;
 782   2                  break;
 783   2                      case NF_SIZE_16MB:
 784   2                              nBlockNum = 1024;
 785   2                  break;
 786   2          }
 787   1          
 788   1          nTestBlock = 0;
 789   1          for (i=0; i<nBlockNum; i++)
 790   1          {
 791   2              Test_nf_read_open_C_area(nTestBlock, 0x05);
 792   2                      nValidFlag = D12_Y3;
 793   2      //        Test_nf_rd_byte(nValidFlag);
 794   2              if (0xff != nValidFlag)
 795   2              {
 796   3                  return KO;
 797   3              }
C51 COMPILER V8.02   NF_DRV                                                                09/25/2008 19:29:37 PAGE 14  

 798   2              else
 799   2              {
 800   3                  nValidFlag = 0;
 801   3              }
 802   2          }
 803   1      
 804   1          return OK;
 805   1      }
 806          
 807          void delay()
 808          {
 809   1          idata unsigned int temp;
 810   1          for (temp=0; temp<3000;temp++)
 811   1          {
 812   2              temp += 1;
 813   2              temp -= 1;
 814   2          }
 815   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2753    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      7     106
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      4      21
   IDATA SIZE       =   ----       2
   BIT SIZE         =      3    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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