S3C2440之NAND FLASH移植到S3C2410的驱动分析[一]

S3C2440A的NAND FLASH驱动移植到S3C2410还是有些不一样的,最主要的这两个IC的NAND FLASH的寄存器有些不一样,请看下面的两者之间不同:

//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  Header: s3c2410x_nand.h
//
//  Defines the NAND controller CPU register layout and definitions.
//
#ifndef __S3C2410X_NAND_H
#define __S3C2410X_NAND_H

#if __cplusplus
    extern "C" 
    {
#endif


//------------------------------------------------------------------------------
//  Type: S3C2410X_NAND_REG    
//
//  NAND Flash controller register layout. This register bank is located 
//  by the constant CPU_BASE_REG_XX_NAND in the configuration file 
//  cpu_base_reg_cfg.h.
//

typedef struct  
{
    UINT32  NFCONF;             // configuration reg
    UINT8   NFCMD;              // command set reg
    UINT8   pad1[3];            // pad 
    UINT8   NFADDR;             // address set reg
    UINT8   pad2[3];            // pad 
    UINT8   NFDATA;             // data reg
    UINT8   pad3[3];            // pad
    UINT32  NFSTAT;             // operation status reg
    UINT32  NFECC;             // error correction code 0

} S3C2410X_NAND_REG, *PS3C2410X_NAND_REG;    


#if __cplusplus
    }
#endif

#endif 

上面的代码是S3C2410A的寄存器,我们在看看S3C2440A的寄存器地址说明:

//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  Header: s3c2440a_nand.h
//
//  Defines the NAND controller CPU register layout and definitions.
//
#ifndef __S3C2440A_NAND_H
#define __S3C2440A_NAND_H

#if __cplusplus
    extern "C" 
    {
#endif


//------------------------------------------------------------------------------
//  Type: S3C2440A_NAND_REG    
//
//  NAND Flash controller register layout. This register bank is located 
//  by the constant CPU_BASE_REG_XX_NAND in the configuration file 
//  cpu_base_reg_cfg.h.
//

typedef struct  
{
    UINT32  NFCONF;             // configuration reg
	UINT32  NFCONT;
    UINT8  	NFCMD;              // command set reg
    UINT8	d0[3];
    UINT8 	NFADDR;             // address set reg
    UINT8	d1[3];
    UINT8  	NFDATA;             // data reg
    UINT8	d2[3];
	UINT32  NFMECCD0;
	UINT32  NFMECCD1;
    UINT32  NFSECCD;    
    UINT32  NFSTAT;             // operation status reg
	UINT32  NFESTAT0;
	UINT32  NFESTAT1;
    UINT32  NFMECC0;             // error correction code 0
    UINT32  NFMECC1;             // error correction code 1
	UINT32  NFSECC;
	UINT32  NFSBLK;
    UINT32  NFEBLK;             // error correction code 2

} S3C2440A_NAND_REG, *PS3C2440A_NAND_REG;    


#if __cplusplus
    }
#endif

#endif 

这两者之间的差别是很大的。因此移植起来的难点主要是ECC部分,同时还有个别寄存器位地址不一样,需要修改,见下面:

//  Use Macros here to avoid extra over head for c function calls
#define READ_REGISTER_BYTE(p)		(*(PBYTE)(p))
#define WRITE_REGISTER_BYTE(p, v)	(*(PBYTE)(p)) = (v)
#define READ_REGISTER_USHORT(p)		(*(PUSHORT)(p))
#define WRITE_REGISTER_USHORT(p, v)	(*(PUSHORT)(p)) = (v)
#define READ_REGISTER_ULONG(p)		(*(PULONG)(p))
#define WRITE_REGISTER_ULONG(p, v)	(*(PULONG)(p)) = (v)

以上的代码不论S3C2410还是S3C2440都可以用,我在移植的时候,这两部是一样的。当然至于S3C2443和S3C2450这部分的寄存器改变并不多,不过S3C2450的BSP中NAND FLASH驱动还是有很大的变化,那以后再来分析吧,现在还是分析这个,WINCE5.0下的。WINCE6.0的我还没有来得急移植呢。我一般喜欢动手自己移植一遍,这样能深入的了解WINCE的流程,同时对这颗IC,也更熟悉。看看两者之间的不同吧。

S3C2440A的寄存器宏定义:

//  MACROS
#define NF_CE_L()			WRITE_REGISTER_USHORT(pNFCONT, (USHORT) (READ_REGISTER_USHORT(pNFCONT) & ~(1<<1)))
#define NF_CE_H()			WRITE_REGISTER_USHORT(pNFCONT, (USHORT) (READ_REGISTER_USHORT(pNFCONT) | (1<<1)))
#define NF_CMD(cmd)			WRITE_REGISTER_USHORT(pNFCMD, (USHORT) (cmd))
#define NF_ADDR(addr)		WRITE_REGISTER_USHORT(pNFADDR, (USHORT) (addr))
#define NF_DATA_R()			READ_REGISTER_BYTE(pNFDATA)
#define NF_DATA_W(val)		WRITE_REGISTER_BYTE(pNFDATA, (BYTE) (val))
#define NF_DATA_R4()		READ_REGISTER_ULONG(pNFDATA)
#define NF_DATA_W4(val)		WRITE_REGISTER_ULONG(pNFDATA, (ULONG) (val))
#define NF_STAT()			READ_REGISTER_USHORT(pNFSTAT)
#define NF_MECC_UnLock()	WRITE_REGISTER_USHORT(pNFCONT, (USHORT) (READ_REGISTER_USHORT(pNFCONT) & ~(1<<5)))
#define NF_MECC_Lock()		WRITE_REGISTER_USHORT(pNFCONT, (USHORT) (READ_REGISTER_USHORT(pNFCONT) | (1<<5)))
#define NF_RSTECC()			WRITE_REGISTER_USHORT(pNFCONT, (USHORT) (READ_REGISTER_USHORT(pNFCONT) | (1<<4)))
#define NF_WAITRB()			{while(!(NF_STAT() & (1<<1))) ;}
#define NF_CLEAR_RB()		WRITE_REGISTER_USHORT(pNFSTAT, (USHORT) (READ_REGISTER_USHORT(pNFSTAT) | (1<<2)))
#define NF_DETECT_RB()		{while(!(NF_STAT() & (1<<2)));}
#define NF_ECC()			READ_REGISTER_ULONG(pNFECC)

S3C2410A的寄存器宏定义:

//  MACROS
#define NF_CE_L()				WRITE_REGISTER_USHORT(pNFCONF, (USHORT) (READ_REGISTER_USHORT(pNFCONF) & ~(1 << 11)))
#define NF_CE_H()				WRITE_REGISTER_USHORT(pNFCONF, (USHORT) (READ_REGISTER_USHORT(pNFCONF) | (1 << 11)))
#define NF_CMD(cmd)     		WRITE_REGISTER_USHORT(pNFCMD, (USHORT) (cmd))
#define NF_ADDR(addr)   		WRITE_REGISTER_USHORT(pNFADDR, (USHORT) (addr))
#define NF_DATA_R()     		READ_REGISTER_USHORT(pNFDATA)
#define NF_DATA_W(val)			WRITE_REGISTER_BYTE(pNFDATA, (BYTE)(val))

#define NF_STAT()       		READ_REGISTER_USHORT(pNFSTAT)
		
#define NF_RSTECC()				WRITE_REGISTER_USHORT(pNFCONF, (USHORT) (READ_REGISTER_USHORT(pNFCONF) | (1 << 12)))
#define NF_WAITRB()				{while(!(NF_STAT() & (1<<0))) ;}
#define NF_DETECT_RB()			{while(!(NF_STAT() & 0x01));}
#define NF_ECC()				READ_REGISTER_ULONG(pNFECC)

S3C2410的寄存器是我修改过的寄存器定义,主要不同之处:NF_CE_L()、NF_CE_H()、NF_RSTECC()、NF_WAITRB()、NF_DETECT_RB(),这些寄存器可以通过两者的Datasheet上的详细说明可以分别出来。这里不详细解说啦!寄存器的修改是移植NAND FLASH驱动的第一步。也是最重要的一步,下一步主要分析驱动移植需要注意的部分。
   未完待续。。。。。。

你可能感兴趣的:(c,Microsoft,cmd,Flash,byte,WinCE)