📄 nandflash.h
字号:
/**
*这组宏和数据结构来自于3221的nandflash驱动模块与实际nandflash特点的结合,
还要就是为了加速常见nandflash驱动设置的宏。
* @file nand_drv_3223.h
* @brief nandflash driver, define nandflash APIs.
* This file provides nandflash APIs: nandflash initialization, write ,read data from
* nandflash.
* Copyright (C) 2004 Anyka (GuangZhou) Software Technology Co., Ltd.
* @author Miaobaoli
* @date 2005-08-08
* @version 1.0
* @ref AK3220 technical manual. HY27UF1G2M series nandflash datasheet.
*/
#ifndef __NANDFLASH_H_
#define __NANDFLASH_H_
#include "akdefine.h"
/** @{@name Error Code of nandflash
* define the error code of nandflash
*/
#define NF_SUCCESS (1)
#define NF_FAIL (0)
#define NF_ERR_ECC (0)
#define NF_ERR_PROGRAM (-2)
#define NF_ERR_ERASE (-3)
#define NF_ERR_INIT (-4)
#define NF_ERR_DEV (-5)
#define NF_ERR_LAST (-6)
/** @{@name Command and Status define
* Define command set and status of HY27UF1G2M nandflash
* and also used by other comman nandflash in the list.
*
*/
#define NFLASH_READ1 0x00
#define NFLASH_READ2 0x30
#define NFLASH_COPY_BACK_READ 0x35
#define NFLASH_COPY_BACK_WRITE 0x85
#define NFLASH_COPY_BACK_CONFIRM 0x10
#define NFLASH_RESET 0xff
#define NFLASH_FRAME_PROGRAM0 0x80
#define NFLASH_FRAME_PROGRAM1 0x10
#define NFLASH_BLOCK_ERASE0 0x60
#define NFLASH_BLOCK_ERASE1 0xD0
#define NFLASH_STATUS_READ 0x70
#define NFLASH_READ_ID 0x90
//status register bit
#define NFLASH_PROGRAM_SUCCESS 0x01 //bit 0
#define NFLASH_HANDLE_READY 0x40 //bit 6
/** @} */
//force write and force read flag
#define AVAILABLE_FLAG 0xff
#define AVAILABLE_FLAG_OFFSET 2
#define BLOCK_INDEX_OFFSET 0
#define LAST_BLOCK_FLAG 0xFFEE
//
typedef struct Nand_log_info{
T_U8 Nand_LogPerPhy;//1 phy page = ? log page
T_U8 log_spare_size;//logic spare size,3223 always is 16
T_U8 Fs_Info_size;//logic spare size,3223 always is 6
T_U16 log_page_size; //logic page size, 3223 always is 512
T_U32 log_page_per_blk; //1 blk = ? log page( for mtd)
T_U16 log_page_per_blk_shift;
T_U32 total_blk_num;//chip_cnt*chip_blk_num, if 1 block = 128k, 0xFFFF block = 8G
T_U16 total_group_num; //total group num in all chips
T_U32 chip_logpage_num;//one chip have ? logic page
T_U32 total_logpage_num;//total have ? logic chip
T_U32 total_phypage_num; //total phypage num
T_U32 phypage_per_chip; //Physical Page Per Chip
T_U16 phypage_shift_num;
}T_NAND_LOG_INFO;
/**
定义一个结构体用于存储安装了的flash的片位信息
*/
typedef struct NANDCHIP_INFO{
T_U16 count;
T_U8 pos[NFC_SUPPORT_CHIPNUM];
T_U32 id; //chip id
T_U8 col_cycle;//column address cycle
T_U8 lst_col_mask;//last column addr mask bit
T_U8 row_cycle;//row address cycle
T_U8 last_row_mask;//last row address mask bit
T_U16 phy_page_size; //physic page size
T_U16 phy_page_per_blk; //1 blk = ? phy page( for mtd)
T_U16 chip_blk_num; //1 chip have ? block
T_U16 group_blk_num; //group block number
T_U16 plane_blk_num; //plane block number, equal to group block number usually
}T_NANDCHIP_INFO;
extern T_NAND_LOG_INFO Nand_SysInfo;
extern T_NANDCHIP_INFO chipInfo;
/**
* @brief init current nandflash
* @author dengjian
* @date 2006-01-05
* @return T_S16
* @retval refer to error code of nandflash
*/
T_S16 nf_init();
/**
* @brief reset nandflash
* @return T_VOID
*/
T_VOID nf_reset();
/**
* @brief erase one block of nandflash
* @author dengjian
* @date 2006-01-05
* @param[in] T_U16 block: index of the block to be erased
* @return T_S16
* @retval refer to error code of nandflash
*/
T_S16 nf_erase_block(T_U16 block );
/**
* @brief read one logic page from nandflash with ECC.
* total 518B valid data: incude 512Byte data and 6Byte file system information.
* @author dengjian
* @date 2006-01-05
* @param[in] T_U32 frame: index of the log page to be read
* @param[out] T_U8* data: point to the data buf, can be NULL
* @param[out] T_U8* spare: point to the spare buf, can be NULL
* @return T_S16
* @retval refer to error code of nandflash
*/
T_S16 nf_read_frame(T_U32 frame,T_U8 *data,T_U8 *fs_info);
/**
* @brief write one logic page to nandflash with ECC.
* total 518B valid data: incude 512Byte data and 6Byte file system information.
* @author dengjian
* @date 2006-01-05
* @param[in] T_U32 frame: index of the log page to be written
* @param[in] T_U8* data: point to the data buf, can be NULL
* @param[in] T_U8* spare: point to the spare buf, can be NULL
* @return T_S16
* @retval refer to error code of nandflash
*/
T_S16 nf_write_frame(T_U32 frame,T_U8 *data,T_U8 *fs_info);
/**
* @brief copy back physical page from one to another
* @author dengjian
* @date 2006-01-05
* @param[in] T_U32 src: index of the source page
* @param[in] T_U32 dst: index of the destination page
* @return T_S16
* @retval refer to error code of nandflash
*/
T_S16 nf_copyback(T_U32 src, T_U32 dst);
/**
* @brief read several pages directly
* @author qinxiaojun
* @date 2006-01-05
* @param[in] T_U32 StartNo: index of the start page
* @param[in] T_U32 EndNo: index of the end page
* @param[in] T_U8 *pData: data address
* @param[in] T_U32 len: data length
* @return T_S16
* @retval refer to error code of nandflash
*/
T_BOOL nf_force_read(T_U32 *StartAddress, T_U32 EndAddress, T_U8 *pData, T_U32 ReadLength, T_U32 BackupMapAddress);
/**
* @brief write several pages directly
* @author qinxiaojun
* @date 2006-01-05
* @param[in] T_U32 StartNo: index of the start page
* @param[in] T_U32 EndNo: index of the end page
* @param[in] T_U8 *pData: data address
* @param[in] T_U32 len: data length
* @return T_S16
* @retval refer to error code of nandflash
*/
T_BOOL nf_force_write(T_U32 *StartAddress, T_U32 EndAddress,
T_U32 *BackupStartAddress, T_U32 BackupEndAddress,
T_U32 BackupMapAddress,
T_U8 *pData, T_U32 DataLength,
T_BOOL LastWrite);
/**
* @brief check block error
* @author dengjian
* @date 2006-01-05
* @param[in] T_U32 StartNo: index of the start page
* @param[in] T_U32 EndNo: index of the end page
* @param[in] T_U8 *pData: data address
* @param[in] T_U32 len: data length
* @return T_S16
* @retval refer to error code of nandflash
*/
T_S16 nf_check_blk(T_U16 block);
/**
* @brief print block info
* @author dengjian
* @date 2006-01-05
* @param[in] T_U32 StartNo: index of the start page
* @param[in] T_U32 EndNo: index of the end page
* @param[in] T_U8 *pData: data address
* @param[in] T_U32 len: data length
* @return T_S16
* @retval refer to error code of nandflash
*/
T_VOID nf_print_block_info(T_U16 block);
/** @} */
#endif// __NANDFLASH_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -