📄 nand.h
字号:
//
// Copyright (c) Craftsman Software. All rights reserved.
//
// AUTHOR : junwei cheng
// E-MAIL : chjw_ch@yahoo.com
//
#ifndef __NAND_H__
#define __NAND_H__
#include "def.h"
#include "2440addr.h"
#define NUM_BLOCKS 2048
// FMD block status definitions.
#define BLOCK_STATUS_UNKNOWN 0x01
#define BLOCK_STATUS_BAD 0x02
#define BLOCK_STATUS_READONLY 0x04
#define BLOCK_STATUS_RESERVED 0x08
#define BLOCK_STATUS_XIP 0x10
// FMD OEM reserved area bitfield.
#define OEM_BLOCK_RESERVED 0x01
#define OEM_BLOCK_READONLY 0x02
#define INVALID_BLOCK_ID 0xFFFFFFFF
#define INVALID_SECTOR_ADDR 0xFFFFFFFF
//--------------------------- Structure Definitions -----------------------------
typedef enum _FLASH_TYPE { NAND, NOR } FLASH_TYPE;
typedef DWORD SECTOR_ADDR;
typedef PDWORD PSECTOR_ADDR;
typedef DWORD BLOCK_ID;
typedef PDWORD PBLOCK_ID;
typedef struct _FlashInfo
{
FLASH_TYPE flashType;
DWORD dwNumBlocks;
DWORD dwBytesPerBlock;
WORD wSectorsPerBlock;
WORD wDataBytesPerSector;
}FlashInfo, *PFlashInfo;
typedef struct _SectorInfo
{
DWORD dwReserved1; // Reserved - used by FAL
BYTE bOEMReserved; // For use by OEM
BYTE bBadBlock; // Indicates if block is BAD
WORD wReserved2; // Reserved - used by FAL
}SectorInfo, *PSectorInfo;
typedef struct _BlockLockInfo
{
BLOCK_ID StartBlock;
ULONG NumBlocks;
}BlockLockInfo, *PBlockLockInfo;
//--------------------------------------------------------------------------------------
// Supported Command Sets
//--------------------------------------------------------------------------------------
//K9F1G08, K9F2G08, K9F4G08, K9F8G08
#define CMD_Read_1st 0x00
#define CMD_Read_2nd 0x30
//K9F5608, K9F1208
#define CMD_Read1_00 0x00
#define CMD_Read1_01 0x01
#define CMD_Read2 0x50
//K9F5608, K9F1208, K9F1G08, K9F2G08, K9F4G08, K9F8G08
#define CMD_ReadID 0x90
#define CMD_Reset 0xFF
#define CMD_BlockErase_1st 0x60
#define CMD_BlockErase_2nd 0xD0
#define CMD_ReadStatus 0x70
#define CMD_PageProgram_1st 0x80
#define CMD_PageProgram_2nd 0x10
//--------------------------------------------------------------------------------------
// DMA_MODE
//--------------------------------------------------------------------------------------
#define DMA_MODE 1
//--------------------------------------------------------------------------------------
// Nand Interfaces
//--------------------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
/*
* Init Nand Flash register
*/
BOOL Nand_Init(void);
/*
* Reset Nand Flash Chip
*/
void Nand_Reset(void);
/*
* Read Nand Flash Chip ID
*
* Return
* Flash Chip ID
*/
U16 Nand_ReadID(void);
BOOL Nand_GetInfo(PFlashInfo pFlashInfo);
/*
* Read Nand Flash Operation Status
*
* Return
* status byte
*/
BYTE Nand_ReadStatus(void);
/*
* Erase a block
*
* Parameter
* block block no
* Return
* error code
*/
BOOL Nand_EraseBlock(BLOCK_ID block);
/*
* Is a block marked as bad?
*
* Return
* 0 marked as good
* 1 marked as bad
*/
BOOL Nand_IsBadBlock(BLOCK_ID block);
/*
* Mark a block as bad
*
* Parameter
* block block no to be marked
* Return
* error code
*/
BOOL Nand_MarkBadBlock(BLOCK_ID block);
DWORD Nand_GetBlockStatus(BLOCK_ID blockID);
BOOL Nand_SetBlockStatus(BLOCK_ID blockID, DWORD dwStatus);
/*
* Write a page
*
* Parameter
* block block no
* page page no
* pdata data buffer pointer
* len data buffer length
* Return
* error code
*/
BOOL Nand_WritePageEx(BLOCK_ID block, SECTOR_ADDR page, const void *pdata, DWORD len);
BOOL Nand_WritePage(SECTOR_ADDR absolute_pages, const void *pdata, DWORD len);
BOOL Nand_WritePageSpare(SECTOR_ADDR absolute_pages, const void *pdata, DWORD len);
/*
* Read a page
* block block no
* page page no
* pdata data buffer pointer
* len data buffer length
* Return
* error code
*/
BOOL Nand_ReadPageEx(BLOCK_ID block, SECTOR_ADDR page, void *pdata, DWORD len);
BOOL Nand_ReadPage(SECTOR_ADDR absolute_pages, void *pdata, DWORD len);
BOOL Nand_ReadPageSpare(SECTOR_ADDR absolute_pages, void *pdata, DWORD len);
/*
* Nand flash characterisc
*
* Return
* [0] 0 - 8-Bit bus width,1 - 16-Bit bus width
* [1] 0 - 3,4 cycles, 1 - 4,5 cycles
* [2] 0 - By word, 1 - By byte
* [3] 0 - Normal, 1 - Advance
* [4-31] Reserved.
*/
DWORD Nand_Characteristic(void);
/*
* page size
*
* Return
* page size, 512, 2048
*/
DWORD Nand_PageSize(void);
/*
* pages of one block
*
* Return
* pages per block , 32, 64
*/
DWORD Nand_PagesPerBlock(void);
DWORD Nand_BlockToPage(BLOCK_ID blockID);
DWORD Nand_PageToBlock(DWORD pages);
#ifdef __cplusplus
}
#endif
#define IS_BLOCK_BAD(blockID) ((Nand_GetBlockStatus (blockID) & BLOCK_STATUS_BAD) > 0)
#define IS_BLOCK_READONLY(blockID) ((Nand_GetBlockStatus (blockID) & BLOCK_STATUS_READONLY) > 0)
#define IS_BLOCK_RESERVED(blockID) ((Nand_GetBlockStatus (blockID) & BLOCK_STATUS_RESERVED) > 0)
#define IS_BLOCK_UNUSABLE(blockID) ((Nand_GetBlockStatus (blockID) & (BLOCK_STATUS_BAD|BLOCK_STATUS_RESERVED)) > 0)
#define Nand_IsBadBlock(blockID) IS_BLOCK_BAD(blockID)
#define Nand_MarkBadBlock(blockID) Nand_SetBlockStatus(blockID, BLOCK_STATUS_BAD)
//--------------------------------------------------------------------------------------
// NAND Constant Defines & Variables
//--------------------------------------------------------------------------------------
//NAND flash memory selection(Normal / Advance) , column address
#define NAND_Normal 0
#define NAND_Advance 1
//AddrCycle type (row address)
#define ADDR_CYCLE_3 0
#define ADDR_CYCLE_4 1
//--------------------------------------------------------------------------------------
//Chip Cap. 1 Page 1 Block Column Row
//--------------------------------------------------------------------------------------
//K9F5608 32M 512 + 16 32 A0-A7 (1) A9-A24 (2)
//K9F1208 64M 512 + 16 32 A0-A7 (1) A9-A25 (2)
//--------------------------------------------------------------------------------------
//K9F1G08 128M 2K + 64 64 A0-A11 (2) A12-A27 (2)
//K9F2G08 256M 2K + 64 64 A0-A11 (2) A12-A28 (3)
//K9F4G08 512M 2K + 64 64 A0-A11 (2) A12-A29 (3)
//K9K8G08 1G 2K + 64 64 A0-A11 (2) A12-A30 (3)
//--------------------------------------------------------------------------------------
//K9F4G08, K9F8G08 Command Sets
//--------------------------------------------------------------------------------------
//Function 1st.Cycle 2nd.Cycle Acceptable Command during Busy
//--------------------------------------------------------------------------------------
//Read 00h 30h
//--------------------------------------------------------------------------------------
//Read for Copy Back 00h 35h
//--------------------------------------------------------------------------------------
//Read ID 90h -
//--------------------------------------------------------------------------------------
//Reset FFh - O
//--------------------------------------------------------------------------------------
//Page Program 80h 10h
//--------------------------------------------------------------------------------------
//Two-Plane Page Program 80h---11h 81h---10h
//--------------------------------------------------------------------------------------
//Copy-Back Program 85h 10h
//--------------------------------------------------------------------------------------
//Two-Plane Copy-Back Program 85h---11h 81h---10h
//--------------------------------------------------------------------------------------
//Block Erase 60h D0h
//--------------------------------------------------------------------------------------
//Two-Plane Block Erase 60h---60h D0h
//--------------------------------------------------------------------------------------
//Random Data Input(1) 85h -
//--------------------------------------------------------------------------------------
//Random Data Output(1) 05h E0h
//--------------------------------------------------------------------------------------
//Read Status 70h - O
//--------------------------------------------------------------------------------------
//Read EDC Status(2) 7Bh - O
//--------------------------------------------------------------------------------------
//K9F1G08, K9F2G08 Command Sets
//--------------------------------------------------------------------------------------
//Function 1st.Cycle 2nd.Cycle Acceptable Command During Busy
//--------------------------------------------------------------------------------------
//Read 00h 30h
//--------------------------------------------------------------------------------------
//Read for Copy Back 00h 35h
//--------------------------------------------------------------------------------------
//Read ID 90h -
//--------------------------------------------------------------------------------------
//Reset FFh - O
//--------------------------------------------------------------------------------------
//Page Program 80h 10h
//--------------------------------------------------------------------------------------
//Cache Program 80h 15h
//--------------------------------------------------------------------------------------
//Copy-Back Program 85h 10h
//--------------------------------------------------------------------------------------
//Block Erase 60h D0h
//--------------------------------------------------------------------------------------
//Random Data Input 85h -
//--------------------------------------------------------------------------------------
//Random Data Output 05h E0h
//--------------------------------------------------------------------------------------
//Read Status 70h - O
//--------------------------------------------------------------------------------------
//K9F1208 Command Sets
//--------------------------------------------------------------------------------------
//Function 1st.Cycle 2nd.Cycle 3rd.Cycle Acceptable Command during Busy
//--------------------------------------------------------------------------------------
//Read 1 00h/01h(1) - -
//--------------------------------------------------------------------------------------
//Read 2 50h - -
//--------------------------------------------------------------------------------------
//Read ID 90h - -
//--------------------------------------------------------------------------------------
//Reset FFh - - O
//--------------------------------------------------------------------------------------
//Page Program (True)(2) 80h 10h -
//--------------------------------------------------------------------------------------
//Page Program (Dummy)(2) 80h 11h -
//--------------------------------------------------------------------------------------
//Copy-Back Program(True)(2) 00h 8Ah 10h
//--------------------------------------------------------------------------------------
//Copy-Back Program(Dummy)(2) 03h 8Ah 11h
//--------------------------------------------------------------------------------------
//Block Erase 60h D0h -
//--------------------------------------------------------------------------------------
//Multi-Plane Block Erase 60h----60h D0h -
//--------------------------------------------------------------------------------------
//Read Status 70h - - O
//--------------------------------------------------------------------------------------
//Read Multi-Plane Status 71h(3) - - O
//--------------------------------------------------------------------------------------
//K9F5608 Command Sets
//--------------------------------------------------------------------------------------
//Function 1st.Cycle 2nd.Cycle Acceptable Command during Busy
//--------------------------------------------------------------------------------------
//Read 1 00h/01h(1) -
//--------------------------------------------------------------------------------------
//Read 2 50h(2) -
//--------------------------------------------------------------------------------------
//Read ID 90h -
//--------------------------------------------------------------------------------------
//Reset FFh - O
//--------------------------------------------------------------------------------------
//Page Program 80h 10h
//--------------------------------------------------------------------------------------
//Block Erase 60h D0h
//--------------------------------------------------------------------------------------
//Read Status 70h - O
//--------------------------------------------------------------------------------------
#endif //__NAND_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -