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

📄 cl_logic.h

📁 linux下的nandflash驱动程序,这是从国外网站上下载来的
💻 H
字号:
/*	Module: CL_Logic.h
	Author: Vova Lifliand
	Description: Controls Nand flash management logic
	Notes:
*/

#ifndef __CL_LOGIC__
#define __CL_LOGIC__

#ifdef CL_SHOW_TRACE_LOGS
#if !defined (FLASH_PLATFORM_WINCE) && !defined (FLASH_PLATFORM_DOS) && !defined (FLASH_PLATFORM_WINNT)
#warning "CL_SHOW_TRACE_LOGS is defined."
#endif
#endif

/*  Nand Flash management constants  */

/*  Sector size must not be changed because this value is also used for
    page size of Nand flash  */
#define CL_FLASH_SECTOR_SIZE            512      /*  bytes  */
#define CL_FLASH_SPARE_AREA_SIZE        16       /*  bytes  */
/*  Maximum blocks number in flash - adjust according to maximum flash size  */
#define CL_MAX_BLKS_NUMBER              8192     /*  good for 128MB flash  */
/*  Number of pages in Nand flash block  */
#define CL_FLASH_PAGES_PER_NAND_BLK     32
/*  Number of sectors to make free  */
#define CL_FLASH_FREE_SECT_PER_BLK      1
/*  Usable sectors per 16 KB Nand flash block  */
#define CL_FLASH_USE_SECT_PER_BLK       (CL_FLASH_PAGES_PER_NAND_BLK - CL_FLASH_FREE_SECT_PER_BLK)
/*  Number of logical to physical sector translation tables stored in memory
    Each table size is ~40 bytes  */
#define CL_LTF_SECT_TBLS                30
/*  Always leave a number of blocks unused - just for sure  */
#define CL_EXTRA_SPARE_BLKS             10
/*  Define maximum number of different blocks with cached sectors  */
#define CL_MAX_CACHED_BLKS              4
/*  Number of erases per one launching of anti wearing procedure  */
#define CL_ERASE_PER_ANTI_WEARING       1000

/*  Type definition  */
#ifdef FLASH_PLATFORM_WINCE
#undef FAR
#endif

#ifndef FLASH_PLATFORM_DOS
#   define FAR
#else
#   define FAR	       far
#endif

#define CLBYTEPTR      unsigned char FAR*

/*  Flash mapping and accessing interface  */
typedef struct cl_nand_map_if_t
{
    /*  Destroy function must free all allocated resources (such as virtual memory)  */
    void (*init) (void);
    void (*destroy) (void);
    /*  Chip select operation. When on = 1: chip select, on = 0: disable chip select  */
    void (*chip_select) (int on);
    /*  Reading from flash (HW read access, not actual data reading)  */
    unsigned char (*readb) (unsigned char offset);
    /*  Writing to flash (HW write access, not actual data writing)  */
    void (*writeb) (unsigned char offset, unsigned char data);
    /*  Reads block from flash: reads data from address 0 while incrementing data pointer  */
    void (*blockread) (CLBYTEPTR data, int count);
    /*  Writes block to flash: writes data to address 0 while incrementing data pointer  */
    void (*blockwrite) (const CLBYTEPTR data, int count);
    /*  Turns on/off activity indication leds  */
    void (*activity_leds) (short operation, short reclaim);
    /*  Performs specified delay (parameter in microsecond units)  */
    void (*sleep) (unsigned long microseconds);
} cl_nand_map_if;

/*  Forward ADT declarations  */
typedef struct cl_logic_t FAR* cl_logic;

/*  Parameter retrive enum  */
typedef enum
{
    CL_FLASH_TOTAL_SIZE,        /*  Total size of the flash in bytes  */
    CL_FLASH_HEADS_NUM,         /*  Number of heads  */
    CL_FLASH_SECTS_NUM,         /*  Number of sectors per tracks  */
    CL_FLASH_CYLINDERS_NUM,     /*  Number of cylinders  */
    CL_FLASH_READ_SECT_CNT,     /*  Read sector operations count  */
    CL_FLASH_WRITE_SECT_CNT,    /*  Write sector operations count  */
    CL_FLASH_RECLAIM_CNT,       /*  Reclaim block count  */
    CL_FLASH_BURSTS_NUM,        /*  Bursts of length 'var' numbers  */
    CL_FLASH_ERASE_CNT,         /*  Erase cnt of block specified by 'var'  */
} cl_logic_param;

/*  Direct access type enum  */
typedef enum
{
    CL_FLASH_READ_PAGE,
    CL_FLASH_READ_SPARE_AREA,
    CL_FLASH_READ_BLK_SPARES,   /*  All spare areas of specified block  */
    CL_FLASH_WRITE_PAGE,
    CL_FLASH_WRITE_SPARE_AREA,
    CL_FLASH_ERASE_BLOCK        /*  Data ignored  */
} cl_nand_direct_access_type;

/*  Creates flash logic object and attaches it to specified HW nand flash.
    cache_size is max. number of sectors, the cache can hold.
    The flash is formatted prior initialization if format != 0.
    When formatting reseved blocks and bad are not erased.  */
cl_logic cl_logic_create (cl_nand_map_if* nand_if, long cache_size, int format);

/*  Removes flash logic object and frees all allocated resources.  */
void cl_logic_free (cl_logic flogic);

/*  Parameters retrival function.  */
long cl_logic_get_param (cl_logic flogic, cl_logic_param prm, long var);

/*  Read sector command.  */
int cl_logic_read_sector (cl_logic flogic, long fs_sectn,
                          CLBYTEPTR sect_data);

/*  Write sector command.  */
int cl_logic_write_sector (cl_logic flogic, long fs_sectn,
                           const CLBYTEPTR sect_data);

/*  Flushes too old cache. If force_one_flush is TRUE, at least one
    cached block is flushed.  */
void cl_logic_on_idle (cl_logic flogic, int force_one_flush);

/*  Flushes all cached data to disk.  */
void cl_logic_sync (cl_logic flogic);

/*  Direct accessing commands  */
int cl_logic_direct_access (cl_logic flogic, cl_nand_direct_access_type type,
                            unsigned short block, unsigned char page, CLBYTEPTR data);


/*  NOR Flash Disk Driver  */

/*  The header describes block information  */
typedef struct
{
    unsigned short Signature;       /*  0x1998 for initialized blocks  */
    unsigned short State;
    unsigned short EraseCounter;
    unsigned short SectorIndex[128];
    unsigned short Unused[10];
    unsigned short BlockReserved;	/*	0xFFFF - usable block, 0 - reserved block  */
} cl_nor_block_header;

/*  Abstract class for flash access  */
typedef struct
{
    /*  Constructor  */
    void (*Constructor)(void);
    /*  Destructor  */
    void (*Destructor)(void);
    /*  Define flash access functions  */
    /*  Returns usable size  */
    unsigned long (*GetSize)(void);
    /*  Remaps or unmaps MMS windows, allocated by flash  */
    void (*EnableFlashMap)(int EnableFlag);
    /*  Returns number of usable sectors, 512 bytes each.  */
    /*  Doesn't include first sector that is used for header - signature, state . . .  */
    int (*GetSectorsPerBlock)(void);
    /*  Header  */
    int (*ReadHeader)(unsigned short BlockN, cl_nor_block_header* Header);
    /*  The SectorNum == 0 is first data sector and not the header. Max. value of SectorNum  */
    /*  is GetBlockSize() / BytesPerSector - 1 (min. is 0)  */
    int (*ReadSector)(unsigned short BlockN, unsigned char SectorNum, CLBYTEPTR DestBuff);
    int (*SetBlockState) (unsigned short BlockN, unsigned short Signature,
			  unsigned short State, unsigned short Reserved);
    /*  Sets logical sector index to zero - invalidates sector. SectN is like in WriteSector  */
    int (*InvalidateSect)(unsigned short BlockN, unsigned char SectN);
    /*  BlockN and SectN - destination location, where SectN doesn't include header  */
    /*  information (SectN = 0 means first logical sector and it's seconds physical sector).  */
    /*  SectIndex is physical sector number for further identification (by ReadHeader)  */
    int (*WriteSector)(unsigned short BlockN, unsigned char SectN,
                       const CLBYTEPTR SectData, unsigned short SectIndex);
    int (*EraseBlock)(unsigned short BlockN);
} cl_nor_flash_access;

/*  Define flash access functions  */
int cl_nor_init_flash (void);
int cl_nor_free_mem (void);
int cl_nor_format_flash (int (*ProgressCallback)(int Percentage));
int cl_nor_write_sector (int SectorIndex, const CLBYTEPTR Data);
int cl_nor_read_sector (int SectorIndex, CLBYTEPTR Data);
int cl_nor_get_disk_param (unsigned long* TotalSect, unsigned long* BytesPerSect,
			   unsigned long* Cylinders, unsigned long* SectorsPerTrk,
			   unsigned long* Heads);

#endif      /*  __CL_LOGIC__  */

⌨️ 快捷键说明

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