📄 davincievm_nandflash.h
字号:
/*
* Copyright 2005 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*
* Not for distrubition.
*/
/*
* ======== nandflash_test.h ========
*/
#ifndef NANDFLASH_
#define NANDFLASH_
#ifdef __cplusplus
extern "C" {
#endif
#include "davincievm.h"
/* ------------------------------------------------------------------------ *
* Flash Device - SAMSUNG NAND Flash Memory K9F5608U0B *
* ------------------------------------------------------------------------ */
#define MFG_SAMSUNG 0xEC
#define DEV_K9F5608U0B 0x75
#define DEV_K9F5608U0B_PAGE_COUNT 32 * 2048 // 32 pages * 2048 blocks
#define DEV_K9F5608Q0B 0x35
#define DEV_K9F5608Q0B_PAGE_COUNT 32 * 2048 // 32 pages * 2048 blocks
#define DEV_K9F2808U0C 0x73
#define DEV_K9F2808U0C_PAGE_COUNT 32 * 1024 // 32 pages * 1024 blocks
#define DEV_K9K1208Q0C 0x36
#define DEV_K9K1208Q0C_PAGE_COUNT 32 * 4096 // 32 pages * 4096 blocks
#define DEV_SMCARD_128 0x79
#define DEV_SMCARD_128_PAGE_COUNT 32 * 8192 // 32 pages * 8192 blocks
/* ------------------------------------------------------------------------ *
* Flash Memory Property Definitions *
* ------------------------------------------------------------------------ */
#define NANDFLASH_BASE 0x02000000 // SNAND.CS0 BASE
#define NANDFLASH_PAGESIZE 512
#define NANDFLASH_PAGESIZE_POW2 9
#define NANDFLASH_SPARESIZE 16
#define NANDFLASH_SPARESIZE_POW2 4
#define NANDFLASH_PAGES_PER_BLOCK 32
#define NANDFLASH_PAGES_PER_BLOCK_POW2 5
#define NANDFLASH_BLOCKSIZE \
NANDFLASH_PAGESIZE * NANDFLASH_PAGES_PER_BLOCK
#define NANDFLASH_BLOCKSIZE_POW2 \
NANDFLASH_PAGESIZE_POW2 + NANDFLASH_PAGES_PER_BLOCK_POW2
/* ------------------------------------------------------------------------ *
* NAND Flash Command Codes *
* ------------------------------------------------------------------------ */
#define NANDFLASH_READ 0x00
#define NANDFLASH_READ_HALF 0x01
#define NANDFLASH_READ_SPARE 0x50
#define NANDFLASH_READID 0x90
#define NANDFLASH_RESET 0xff
#define NANDFLASH_POINTER_MAIN 0x00
#define NANDFLASH_POINTER_MAIN_HALF 0x01
#define NANDFLASH_POINTER_SPARE 0x50
#define NANDFLASH_PROGRAM 0x80
#define NANDFLASH_PROGRAM_CONFIRM 0x10
#define NANDFLASH_COPYBACK 0x00
#define NANDFLASH_COPYBACK_CONFIRM 0x8A
#define NANDFLASH_ERASE 0x60
#define NANDFLASH_ERASE_CONFIRM 0xd0
#define NANDFLASH_STATUS 0x70
#define NANDFLASH_START_UNLOCK 0x23
#define NANDFLASH_END_UNLOCK 0x24
#define NANDFLASH_LOCK_BLOCK 0x2A
/* ------------------------------------------------------------------------ *
* NAND Flash Status Register Definitions *
* ------------------------------------------------------------------------ */
#define NANDFLASH_STATUS_SUCCESS 0xFFFE
#define NANDFLASH_STATUS_ERROR 0x0001
#define NANDFLASH_STATUS_BUSY 0xFFBF
#define NANDFLASH_STATUS_READY 0x0040
#define NANDFLASH_STATUS_WPROTECT 0xFF7F
#define NANDFLASH_STATUS_NOWPROTECT 0x0080
/* ------------------------------------------------------------------------ *
* NAND Flash Memory Data Pointer *
* ------------------------------------------------------------------------ */
#define NANDFLASH_BASE_PTR *( volatile Uint8* )( NANDFLASH_BASE + 0x00 )
#define NANDFLASH_CLE *( volatile Uint8* )( NANDFLASH_BASE + 0x10 )
#define NANDFLASH_ALE *( volatile Uint8* )( NANDFLASH_BASE + 0x0A )
#define NANDFLASH_ASSERT_CE
#define NANDFLASH_DEASSERT_CE
#define NANDFLASH_READ_RB ( ( *( volatile Uint32* )( 0x01E00064 ) ) & 1 )
/* ------------------------------------------------------------------------ *
* NAND Flash R/B functions *
* ------------------------------------------------------------------------ */
#define NANDFLASH_NOERROR 0
#define NANDFLASH_ERROR 1000
#define NANDFLASH_TIMEOUT 2000
/* ------------------------------------------------------------------------ *
* Address decoding *
* _3 = 24 address bits [00-07]--->[09-16]--->[17-23] *
* _2 = 16 address bits [09-16]--->[17-23] *
* _1 = 8 address bits [17-23] *
* ------------------------------------------------------------------------ */
#define NANDFLASH_ALE_1( addr ) \
NANDFLASH_ALE = ( addr >> 25 ) & 0xFF;
#define NANDFLASH_ALE_2( addr ) \
NANDFLASH_ALE = (addr >> 17) & 0xFF; NANDFLASH_ALE_1( addr );
#define NANDFLASH_ALE_3( addr ) \
NANDFLASH_ALE = (addr >> 9) & 0xFF; NANDFLASH_ALE_2( addr );
#define NANDFLASH_ALE_4( addr ) \
NANDFLASH_ALE = (addr >> 0) & 0xFF; NANDFLASH_ALE_3( addr );
/* ------------------------------------------------------------------------ *
* API Prototypes *
* ------------------------------------------------------------------------ */
Int16 NANDFLASH_init ( );
Int16 NANDFLASH_unProtect(Uint32 startBlkAddr, Uint32 endBlkAddr);
Int16 NANDFLASH_protect(Uint32 startBlkAddr, Uint32 endBlkAddr);
Int16 NANDFLASH_erase ( Uint32 start,
Uint32 block_count );
Uint32 NANDFLASH_getTotalPages ( );
Int16 NANDFLASH_readPage ( Uint32 src,
Uint32 dst,
Uint32 page_count );
Int16 NANDFLASH_writePage ( Uint32 src,
Uint32 dst,
Uint32 page_count );
Int16 NANDFLASH_readSpare ( Uint32 src,
Uint32 dst,
Uint32 spare_count );
Int16 NANDFLASH_writeSpare ( Uint32 src,
Uint32 dst,
Uint32 spare_count );
Int16 NANDFLASH_checksum ( Uint32 start,
Uint32 page_count,
Uint32* main_checksum,
Uint32* spare_checksum );
Int16 NANDFLASH_pollBusyBit ( Uint32 timeout );
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -