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

📄 nf_drv.h

📁 ATMEL MP3 源代码
💻 H
字号:
/*H**************************************************************************
* NAME:         nf_drv.h         
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-refd-nf-3_2_1      
* REVISION:     1.2     
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the NF driver definitions
*****************************************************************************/

#ifndef _NF_DRV_H_
#define _NF_DRV_H_


/*_____ I N C L U D E S ____________________________________________________*/

#include "board.h"                /* board definition */


/*_____ M A C R O S ________________________________________________________*/

/************************** Read Command ************************************/
#define NF_READ_CMD                   0x00
#define NF_READ_CMD2                  0x30
#define NF_RANDOM_READ_CMD_C1         0x05
#define NF_RANDOM_READ_CMD_C2         0xE0
/************************** Read ID Command *********************************/
#define NF_READ_ID_CMD                0x90
#define NF_RESET_CMD                  0xff
/************************** Program / Copy Back command *********************/
#define NF_SEQUENTIAL_DATA_INPUT_CMD  0x80
#define NF_RANDOM_DATA_INPUT_CMD      0x85
#define NF_COPY_BACK_CMD              0x35
#define NF_PAGE_PROGRAM_CMD           0x10
#define NF_CACHE_PROGRAM_CMD          0x15
/************************** Erase command ***********************************/
#define NF_BLOCK_ERASE_CMD            0x60
#define NF_BLOCK_ERASE_CONFIRM_CMD    0xD0
/************************** Read Status command *****************************/
#define NF_READ_STATUS_CMD            0x70

#define NF_BUFFER_SIZE                (Byte)(133)

#define Nf_wait_busy()                { while (!NF_RD_BUSY); }


/* Page address */
#define NF_PAGE_0                     0x00
#define NF_PAGE_1                     0x02
#define NF_PAGE_2                     0x04
#define NF_PAGE_3                     0x06
#define NF_SPARE_PAGE                 0x08

/* block address <-> sector address conversion */
/* 64 sectors in one block -> 6 bits shift     */
#define NF_SHIFT_SECTOR_BLOCK          6   
/* block address <-> zone address conversion   */
/* 1024 block in one zone -> 10 bits shift     */
#define NF_SHIFT_BLOCK_ZONE           10
/* sector address <-> zone address conversion   */
/* 65536 sectors in one zone -> 16 bits shift   */
#define NF_SHIFT_SECTOR_ZONE          16

/*_____ D E F I N I T I O N ________________________________________________*/

/* Structure to store the correspondance between logical and physical block */
typedef struct 
{
  Byte   zone;
  Uint16 logical_block;
  Uint16 physical_block;
} t_reassign_block;


/* Nand Flash CARD DEFINITION */
/* This value are only 128Mb and 256Mbytes Nand Flash with 2048 bytes page size */
#define NF_PAGE_PER_BLOCK (64)      /* pages_block value: pages in a block   */ 
#define NF_DATA_SIZE      (2048)    /* data_size   value: data_size in bytes */
#define NF_SPARE_SIZE     (64)      /* spare_size  value: spare_size in bytes*/
#define NF_BLOCK_PER_ZONE (1024)    /* 1024 block per size                   */

#if (NF_CAPACITY_AUTO_DETECT == TRUE)
  #define NF_ZONE_MAX             (Byte)(2)
  #define NF_5_CYCLE_ADDRESS_BIT  nf_5_cycle_address  
  #define NF_TYPE                 nf_device_type
  #define NF_ZONE_MAX_CPT         nf_zone_max
  #define NF_SECTOR_SIZE          (Uint32)(nf_mem_size)

  #define NF_SIZE_128MB           (Byte)(0)
  #define NF_SIZE_256MB           (Byte)(1)
  
  #define NF_SECTOR_SIZE_128MB    (Uint32)(63999)
  #define NF_SECTOR_SIZE_256MB    (Uint32)(127999)


  #define NF_K9F1G08U0M           0xF1
  #define NF_K9F1K08Q0M           0xA1

  #define NF_K9K2G08Q0M           0xAA
  #define NF_K9K2G08U0M           0xDA


#else
  #ifdef NF_128
  #define NF_TYPE               (Byte)(0)
  #define NF_SIZE               (Byte)(128)
  #define NF_ZONE_MAX           (Byte)(1)
  #define NF_SECTOR_SIZE        (Uint32)(63999)
  #define NF_5_CYCLE_ADDRESS    (0)
  #endif
  
  #ifdef NF_256
  #define NF_TYPE               (Byte)(1)
  #define NF_SIZE               (Byte)(256)
  #define NF_ZONE_MAX           (Byte)(2)
  #define NF_SECTOR_SIZE        (Uint32)(127999)
  #define NF_5_CYCLE_ADDRESS    (1)
  #endif

  #ifndef NF_TYPE
    #error NF capacity must be defined in board.h
  #endif

  #define NF_ZONE_MAX_CPT         NF_ZONE_MAX
  #define NF_5_CYCLE_ADDRESS_BIT  NF_5_CYCLE_ADDRESS  

#endif

/* SCSI DEFINITION FOR SMARTMEDIA */
#define NF_BLOCK_SIZE     ((Uint32)(2048))
#define NF_DISK_SIZE      ((Uint32)(NF_SECTOR_SIZE))

/* Low Level routine */
#define Nf_rd_byte()                (nf_data)
#define Nf_wr_byte(b)               (nf_data = b)
#define Nf_send_command(command)    (nf_send_cmd = command)
#define Nf_send_address(address)    (nf_send_add = address)


#if NF_CAPACITY_AUTO_DETECT
  #define Nf_write_open(address_sector)                                           \
          Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);                       \
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( 0x00 );                                             \
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          if (NF_5_CYCLE_ADDRESS_BIT)                                           \
            Nf_send_address ( ((Byte*)&address_sector)[1] )
    
    #define Nf_read_open(address_sector)                                        \
          Nf_send_command (NF_READ_CMD);                                        \
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          if (NF_5_CYCLE_ADDRESS_BIT)                                           \
            Nf_send_address ( ((Byte*)&address_sector)[1] );                    \
          Nf_send_command (NF_READ_CMD2);                                       \
          Nf_wait_busy()
    
    #define Nf_read_open_spare_area(address_sector, nb_byte)                    \
          Nf_send_command (NF_READ_CMD);                                        \
          Nf_send_address ( nb_byte );                                          \
          Nf_send_address ( NF_SPARE_PAGE );                                    \
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          if (NF_5_CYCLE_ADDRESS_BIT)                                           \
            Nf_send_address ( ((Byte*)&address_sector)[1] );                    \
          Nf_send_command (NF_READ_CMD2);                                       \
          Nf_wait_busy()
    
    #define Nf_write_open_spare_area(address_sector, nb_byte)                   \
          Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);                       \
          Nf_send_address ( nb_byte );                                          \
          Nf_send_address ( NF_SPARE_PAGE );                                    \ 
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          if (NF_5_CYCLE_ADDRESS_BIT)                                           \
            Nf_send_address ( ((Byte*)&address_sector)[1] )
#else

  #if NF_5_CYCLE_ADDRESS == 0
  
    #define Nf_write_open(address_sector)                                       \
          Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);                       \
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( 0x00 );                                             \
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] )
    
    #define Nf_read_open(address_sector)                                        \
          Nf_send_command (NF_READ_CMD);                                        \
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          Nf_send_command (NF_READ_CMD2);                                       \
          Nf_wait_busy()
    
    #define Nf_read_open_spare_area(address_sector, nb_byte)                    \
          Nf_send_command (NF_READ_CMD);                                        \
          Nf_send_address ( nb_byte );                                          \
          Nf_send_address ( NF_SPARE_PAGE );                                    \
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          Nf_send_command (NF_READ_CMD2);                                       \
          Nf_wait_busy()
    
    #define Nf_write_open_spare_area(address_sector, nb_byte)                   \
          Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);                       \
          Nf_send_address ( nb_byte );                                          \
          Nf_send_address ( NF_SPARE_PAGE );                                    \ 
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] )
  
  #else
  
    #define Nf_write_open(address_sector)                                       \
          Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);                       \
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( 0x00 );                                             \
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[1] )
    
    #define Nf_read_open(address_sector)                                        \
          Nf_send_command (NF_READ_CMD);                                        \
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( 0x00 );                                             \        
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[1] );                      \
          Nf_send_command (NF_READ_CMD2);                                       \
          Nf_wait_busy()
    
    #define Nf_read_open_spare_area(address_sector, nb_byte)                    \
          Nf_send_command (NF_READ_CMD);                                        \
          Nf_send_address ( nb_byte );                                          \
          Nf_send_address ( NF_SPARE_PAGE );                                    \
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[1] );                      \
          Nf_send_command (NF_READ_CMD2);                                       \
          Nf_wait_busy()
    
    #define Nf_write_open_spare_area(address_sector, nb_byte)                   \
          Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);                       \
          Nf_send_address ( nb_byte );                                          \
          Nf_send_address ( NF_SPARE_PAGE );                                    \ 
          Nf_send_address ( ((Byte*)&address_sector)[3] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[2] );                      \
          Nf_send_address ( ((Byte*)&address_sector)[1] )
  #endif
#endif

/*_____ D E C L A R A T I O N ______________________________________________*/
extern  void  nf_init_buffer(void);                 /* Initialize the buffer gl_buffer with 0xFF */
extern  void  nf_download_buffer(void);     /* Copy the content of gl_buffer on the card */
extern  void  nf_upload_buffer(void);       /* Load the content of the card on gl_buffer */

void  nf_copy_block_head(void);             /* Copy the first sectors of a block */
void  nf_copy_block_tail(void);             /* Copy the last sectors of a block */
void  nf_reassign_block(void);              /* reassign the physical block on the look up table */
bit   nf_block_erase (Uint32);              /* Erase one block */
bit   nf_erase_all_block(void);             /* Erase all block */
void  nf_init_spare(void);                  /* Init the first redundant data of a block */
void  nf_calc_logical_block();              /* Calulate the value of logical block in spare area */
void  nf_update_spare_data(void);           /* Write only the redundant information */
bit   read_spare_byte(void);


#endif /* _NF_DRV_H_ */

⌨️ 快捷键说明

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