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

📄 nf_drv.lst

📁 通过车载终端采集GPS数据
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.09   NF_DRV                                                                09/25/2008 11:56:14 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE NF_DRV
OBJECT MODULE PLACED IN .\output\bin\nf_drv.obj
COMPILER INVOKED BY: C:\Keil709\C51\BIN\C51.EXE flash\nf_drv.c LARGE BROWSE INCDIR(audio\;eeprom\;extendUART\;flash\;gps
                    -\;inter\;key\;mcu\;menu\;usb\;gprs\;main\;1wire\) DEBUG OBJECTEXTEND PRINT(.\output\nf_drv.lst) OBJECT(.\output\bin\nf_d
                    -rv.obj)

line level    source

   1          /*C**************************************************************************
   2          * NAME:         nf_drv.c        
   3          *----------------------------------------------------------------------------
   4          * Copyright (c) 
   5          *----------------------------------------------------------------------------
   6          * RELEASE:            
   7          * REVISION:       
   8          *----------------------------------------------------------------------------
   9          * PURPOSE:
  10          * This file contains the NF driver definitions
  11          *****************************************************************************/
  12          #include "typedef.h"
  13          #include "16c554.h"
  14          #include "nf_drv.h"
  15          #include <intrins.h>
  16          
  17          #define SIZEBYTE_PERLINE 20     /*bit size per bus line*/
  18          #define SIZEPAGE_PERLINE 4096
  19          #define SIZEBLOCK_PERLINE 6
  20          
  21          extern Uchar volatile xdata D12_Y0;//原来的xCONTROLBYTE8K
  22          extern idata Uchar D17CS;//D12_Y0的寄存器,原来的xConByte8KValue
  23          extern Uchar volatile xdata D12_Y3;//原来的xFLASHCS
  24          extern Uchar volatile xdata D12_Y2;//原来的xCONTROLBYTE82
  25          
  26          unsigned long volatile xdata xCurErasedBlock;//Uint32 xdata xCurErasedBlock;
  27          volatile Byte xEraseStatus;//Byte xdata xEraseStatus;
  28          volatile bit halfpage;
  29          #if (NF_CAPACITY_AUTO_DETECT == TRUE)           /* If autodetect capacity nand flash is active */
  30            Byte    nf_zone_max; //xdata Byte    nf_zone_max;                    /* nf_zone_max definition   */
  31            Byte    nf_device_type;//xdata Byte    nf_device_type;                 /* nf_device_type definition */
  32            bdata bit     nf_4_cycle_address;             /* nf_4_cycle_address definition */
  33          #endif
  34          
  35          /*_____ M A C R O S ________________________________________________________*/
  36          
  37          #ifndef NF_CAPACITY_AUTO_DETECT
                #error  NF_CAPACITY_AUTO_DETECT must be defined in board.h
              #endif
  40          
  41          void Test_nf_send_command(Byte command) 
  42          {
  43   1              D17CS &= 0xdf;
  44   1          D12_Y0 = D17CS;//ALE=0;
  45   1              D17CS |= 0x10;
  46   1          D12_Y0 = D17CS;//CLE=1;
  47   1          D12_Y3 = command;
  48   1              D17CS &= 0xcf;
  49   1          D12_Y0 = D17CS;//ALE=0=CLE
  50   1      }
  51          
  52          void Test_nf_send_address(Byte address) 
  53          {
C51 COMPILER V7.09   NF_DRV                                                                09/25/2008 11:56:14 PAGE 2   

  54   1              D17CS |= 0x20;
  55   1          D12_Y0 = D17CS;//ALE=1
  56   1          D12_Y3 = address;
  57   1          D17CS &= 0xcf;
  58   1          D12_Y0 = D17CS;//ALE=0=CLE
  59   1      }
  60          
  61          void Test_nf_write_open_B_area(Uint32 nRow, Byte nCol)  
  62          {
  63   1          Test_nf_send_command(NF_READ_B_AREA_CMD);
  64   1          Test_nf_send_command(NF_SEQUENTIAL_DATA_INPUT_CMD);
  65   1          Test_nf_send_address(nCol);
  66   1          Test_nf_send_address(((Byte*)&nRow)[3]);
  67   1          Test_nf_send_address(((Byte*)&nRow)[2]);
  68   1      }
  69          
  70          void Test_nf_write_open_A_area(Uint32 nRow, Byte nCol)  
  71          {
  72   1          Test_nf_send_command(NF_READ_A_AREA_CMD);
  73   1          Test_nf_send_command(NF_SEQUENTIAL_DATA_INPUT_CMD);
  74   1          Test_nf_send_address(nCol);
  75   1          Test_nf_send_address(((Byte*)&nRow)[3]);
  76   1          Test_nf_send_address(((Byte*)&nRow)[2]);
  77   1      }
  78          
  79          void Test_nf_write_open_C_area(Uint32 nRow, Byte nCol)  
  80          {
  81   1          Test_nf_send_command(NF_READ_C_AREA_CMD);
  82   1          Test_nf_send_command(NF_SEQUENTIAL_DATA_INPUT_CMD);
  83   1          Test_nf_send_address(nCol);
  84   1          Test_nf_send_address(((Byte*)&nRow)[3]);
  85   1          Test_nf_send_address(((Byte*)&nRow)[2]);
  86   1      }
  87          
  88          void Test_nf_read_open_A_area(Uint32 nRow, Byte nCol)  
  89          {
  90   1          Test_nf_send_command(NF_READ_A_AREA_CMD);
  91   1          Test_nf_send_address(nCol);
  92   1          Test_nf_send_address(((Byte*)&nRow)[3]);
  93   1          Test_nf_send_address(((Byte*)&nRow)[2]);
  94   1          Nf_wait_busy();
  95   1      }
  96          
  97          void Test_nf_read_open_B_area(Uint32 nRow, Byte nCol)  
  98          {
  99   1          Test_nf_send_command(NF_READ_B_AREA_CMD);
 100   1          Test_nf_send_address(nCol);
 101   1          Test_nf_send_address(((Byte*)&nRow)[3]);
 102   1          Test_nf_send_address(((Byte*)&nRow)[2]);
 103   1          Nf_wait_busy();
 104   1      }
 105          
 106          void Test_nf_read_open_C_area(Uint32 nRow, Byte nCol)  
 107          {
 108   1          Test_nf_send_command(NF_READ_C_AREA_CMD);
 109   1          Test_nf_send_address(nCol);
 110   1          Test_nf_send_address(((Byte*)&nRow)[3]);
 111   1          Test_nf_send_address(((Byte*)&nRow)[2]);
 112   1          Nf_wait_busy();
 113   1      }
 114          
 115          #define Test_nf_rd_byte(buf) ((buf) = D12_Y3)
C51 COMPILER V7.09   NF_DRV                                                                09/25/2008 11:56:14 PAGE 3   

 116          
 117          #define Test_nf_wr_byte(buf) (D12_Y3 = (buf))
 118          
 119          
 120          void nf_wp_on()
 121          {
 122   1          D17CS &= 0xbf;
 123   1          D12_Y0 = D17CS;
 124   1      }
 125          
 126          void nf_wp_off()
 127          {
 128   1          D17CS |= 0x40;
 129   1          D12_Y0 = D17CS;
 130   1      }
 131          /*******************************************
 132          nlinenum: 值从0开始
 133          *********************************************/
 134          bit nf_check_linevalid(Uint8 nlinenum/*in*/)
 135          {
 136   1              Byte value1, value2;
 137   1              Uint32 nAddr;
 138   1              nAddr = nlinenum*SIZEPAGE_PERLINE;
 139   1              
 140   1              Nf_wait_busy();
 141   1              Test_nf_read_open_A_area(nAddr, 0x00);
 142   1              Nf_wait_busy();
 143   1              Test_nf_rd_byte(value1);
 144   1              Test_nf_rd_byte(value2);
 145   1              if ((0x55 == value1) && (0xaa == value2))
 146   1                      return OK;
 147   1              else
 148   1                      return KO;
 149   1      }
 150          
 151          /*F**************************************************************************
 152          * NAME: nf_check_status
 153          *----------------------------------------------------------------------------
 154          * PARAMS:
 155          *
 156          * return:
 157          *   NF status
 158          *----------------------------------------------------------------------------
 159          * PURPOSE:
 160          *   Check the status of the device after a program or an erase operation
 161          *----------------------------------------------------------------------------
 162          * EXAMPLE:
 163          *----------------------------------------------------------------------------
 164          * NOTE:
 165          *----------------------------------------------------------------------------
 166          * REQUIREMENTS: 
 167          * ram/xram:
 168          * cycle:
 169          * stack: 
 170          * code:
 171          
 172          *****************************************************************************/
 173          bit nf_check_status (void)
 174          {
 175   1          Uint8 status;
 176   1          Nf_wait_busy();
 177   1          
C51 COMPILER V7.09   NF_DRV                                                                09/25/2008 11:56:14 PAGE 4   

 178   1          Test_nf_send_command(NF_READ_STATUS_CMD);
 179   1      
 180   1          Test_nf_rd_byte(status);
 181   1      
 182   1      
 183   1          if (0x00 == (status & 0x01))
 184   1          {  
 185   2              return OK;
 186   2          }
 187   1          else
 188   1          {
 189   2              return KO;
 190   2          }
 191   1      }  
 192          
 193          /*F**************************************************************************
 194          * NAME: nf_block_erase
 195          *----------------------------------------------------------------------------
 196          * PARAMS:   
 197          *
 198          * return:
 199          *   OK : erase done
 200          *   KO : erase not done
 201          *----------------------------------------------------------------------------
 202          * PURPOSE: Erase a block on Nand Flash Media
 203          *----------------------------------------------------------------------------
 204          * EXAMPLE:
 205          *----------------------------------------------------------------------------
 206          * NOTE:
 207          *   This function use the global variable Uint32 address
 208          *----------------------------------------------------------------------------
 209          * REQUIREMENTS: 
 210          * ram/xram:
 211          * cycle:
 212          * stack: 
 213          * code:
 214          *****************************************************************************/
 215          bit nf_block_erase (Uint32 pos)
 216          {
 217   1          Nf_wait_busy();
 218   1          Test_nf_send_command(NF_READ_A_AREA_CMD);
 219   1          
 220   1          Test_nf_send_command(NF_BLOCK_ERASE_CMD);
 221   1      
 222   1      
 223   1      
 224   1          Test_nf_send_address(((Byte*)&pos)[2]);//[3]);
 225   1          Test_nf_send_address(((Byte*)&pos)[1]);//[2]);    
 226   1      
 227   1          Test_nf_send_command(NF_BLOCK_ERASE_CONFIRM_CMD);
 228   1      
 229   1          nf_check_status();
 230   1          return OK;
 231   1      }
 232          
 233          
 234          /*F**************************************************************************
 235          * NAME: nf_write_onepage
 236          *----------------------------------------------------------------------------
 237          * PARAMS:   
 238          *       pos: the page number ,the start num is 0;//the start row address
 239          *   pbuf: the content to write, whose size is 512 bytes
C51 COMPILER V7.09   NF_DRV                                                                09/25/2008 11:56:14 PAGE 5   

 240          * return:
 241          *   OK : write done
 242          *   KO : write not done
 243          *----------------------------------------------------------------------------
 244          * PURPOSE: write one on Nand Flash Media. It is only permitted to write 512 Bytes
 245          * when writting on flash(our assume).
 246          *----------------------------------------------------------------------------
 247          * EXAMPLE:
 248          *----------------------------------------------------------------------------
 249          * NOTE:
 250          *   This function use the global variable Uint32 address
 251          *----------------------------------------------------------------------------
 252          * REQUIREMENTS: 
 253          * ram/xram:
 254          * cycle:
 255          * stack: 
 256          * code:
 257          *****************************************************************************/
 258          /*bit nf_write_onepage(Uint32 pos, Byte* pBuf)
 259          {
 260                  Uint8 status = 0;
 261                  data Uint16 nTmp;
 262          
 263                  nTmp = pos >> 5;
 264                  if ((FALSE == xEraseStatus) || (xCurErasedBlock != nTmp))
 265                  {
 266                          nf_block_erase(pos<<8);
 267          
 268                  nf_check_status();
 269          
 270                          xEraseStatus = TRUE;

⌨️ 快捷键说明

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