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

📄 nanddriver.c

📁 (1)基于部分u-boot代码自己调试的vxworks BSP (2)实现了nand/nor flash的tffs文件系统 (3)实现了对spi dataflash的访问 (4)实现了对启动参数
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * $Log:   V:/nfdc2048.c_v  $
 * 
 *    Rev 1.27   06 Oct 1997 18:37:34   ANDRY
 * no COBUX
 *
 *    Rev 1.26   06 Oct 1997 18:04:34   ANDRY
 * 16-bit access only for interleave 2 cards, COBUX
 *
 *    Rev 1.25   05 Oct 1997 12:02:32   danig
 * Support chip ID 0xEA
 *
 *    Rev 1.24   10 Sep 1997 16:14:08   danig
 * Got rid of generic names
 *
 *    Rev 1.23   08 Sep 1997 17:47:00   danig
 * fixed setAddress for big-endian
 *
 *    Rev 1.22   04 Sep 1997 13:59:44   danig
 * Debug messages
 *
 *    Rev 1.21   31 Aug 1997 15:18:04   danig
 * Registration routine return status
 *
 *    Rev 1.20   28 Aug 1997 17:47:08   danig
 * Buffer\remapped per socket
 *
 *    Rev 1.19   28 Jul 1997 15:10:36   danig
 * setPowerOnCallback & moved standard typedefs to flbase.h
 *
 *    Rev 1.18   24 Jul 1997 18:04:12   amirban
 * FAR to FAR0
 *
 *    Rev 1.17   21 Jul 1997 18:56:00   danig
 * nandBuffer static
 *
 *    Rev 1.16   20 Jul 1997 18:21:14   danig
 * Moved vendorID and chipID to Vars
 *
 *    Rev 1.15   20 Jul 1997 17:15:06   amirban
 * Added Toshiba 8MB
 *
 *    Rev 1.14   07 Jul 1997 15:22:26   amirban
 * Ver 2.0
 *
 *    Rev 1.13   02 Jul 1997 14:59:22   danig
 * More wait for socket to power up
 *
 *    Rev 1.12   01 Jul 1997 13:39:54   danig
 * Wait for socket to power up
 *
 *    Rev 1.11   22 Jun 1997 18:34:32   danig
 * Documentation
 *
 *    Rev 1.10   12 Jun 1997 17:22:24   amirban
 * Allow long extra read/writes
 *
 *    Rev 1.9   08 Jun 1997 19:18:06   danig
 * BIG_PAGE & FULL_PAGE moved to flash.h
 *
 *    Rev 1.8   08 Jun 1997 17:03:40   amirban
 * Fast Toshiba and power on callback
 *
 *    Rev 1.7   05 Jun 1997 12:31:38   amirban
 * Write corrections, and att reg changes
 *
 *    Rev 1.6   03 Jun 1997 18:45:14   danig
 * powerUp()
 *
 *    Rev 1.5   01 Jun 1997 13:42:52   amirban
 * Rewrite of read/write extra + major reduction
 *
 *    Rev 1.4   25 May 1997 16:41:38   amirban
 * Bg-endian, Toshiba fix & simplifications
 *
 *    Rev 1.3   18 May 1997 17:34:50   amirban
 * Use 'dataError'
 *
 *    Rev 1.2   23 Apr 1997 11:02:14   danig
 * Update to TFFS revision 1.12
 *
 *    Rev 1.1   15 Apr 1997 18:48:02   danig
 * Fixed FAR pointer issues.
 *
 *    Rev 1.0   08 Apr 1997 18:29:28   danig
 * Initial revision.
 */

/************************************************************************/
/*                                                                      */
/*		FAT-FTL Lite Software Development Kit			*/
/*		Copyright (C) M-Systems Ltd. 1995-1997			*/
/*									                    */
/************************************************************************/

/* CDSN : Common Design Standard for NAND */
#include "config.h"
#include "../../../h/drv/flash/nanddriver.h"

/* Flash commands:*/
#define SERIAL_DATA_INPUT   0x80
#define READ_MODE           0x00
#define READ_MODE_2         0x50
#define RESET_FLASH         0xff
#define SETUP_WRITE         0x10
#if 0
#define SETUP_ERASE         0x60
#endif
#define CONFIRM_ERASE       0xd0
#define READ_STATUS         0x70
#define READ_ID             0x90
#define SUSPEND_ERASE       0xb0
#define REGISTER_READ       0xe0

/* commands for moving flash pointer to areeas A,B or C of page*/
typedef enum  { 
    AREA_A = READ_MODE, 
    AREA_B = 0x1, 
    AREA_C = READ_MODE_2 
} PointerOp;


#define VERIFY_AFTER_WRITE

#define READY_BUZY_TIME_OUT  	0x20000000

#define NAND_FLASH_IO_0 	(UINT8)0x01
#define NAND_FLASH_IO_1 	(UINT8)0x02
#define NAND_FLASH_IO_2 	(UINT8)0x04
#define NAND_FLASH_IO_3 	(UINT8)0x08
#define NAND_FLASH_IO_4 	(UINT8)0x10
#define NAND_FLASH_IO_5 	(UINT8)0x20
#define NAND_FLASH_IO_6 	(UINT8)0x40
#define NAND_FLASH_IO_7 	(UINT8)0x80


/* NAND FLASH command */
#define CMD_READ1_1ST_HA		0x00        /*  Read1*/
#define CMD_READ1_2ND_HA		0x01        /*  Read1*/
#define CMD_READ2		0x50        /*  Read2*/
#define CMD_READID		0x90        /*  ReadID*/
#define CMD_WRITE		0x80        /*  Write phase 1*/
#define CMD_WRITE2		0x10        /*  Write phase 2*/
#define CMD_AUTO_BLK_ERASE_SETUP		0x60        /*  Erase phase 1*/
#define CMD_ERASE		0xd0        /*  Erase phase 2*/
#define CMD_STATUS		0x70        /*  Status read*/
#define CMD_RESET		0xFF        /*  Reset*/


#define NAND_FLASH_DEBUG

#define NAND_ChipID_UNKNOWN 	0x00

/* Signal Defintions */
#define DISABLE_NAND_CE 	do { *AT91C_PIOC_SODR = AT91C_PIO_PC0;} while(0)
#define ENABLE_NAND_CE 	do { *AT91C_PIOC_CODR = AT91C_PIO_PC0;} while(0)
#define SET_NAND_ALE 		(1 << 22)  /* our ALE is AD22 */
#define SET_NAND_CLE 		(1 << 21)  /* our CLE is AD21 */
#define GET_NAND_R_B		((AT91_SYS->PIOC_PDSR & AT91C_PIO_PC2) ? 1 : 0)

/* Operation */
#define WAIT_NAND_READY(nand) while (!(*AT91C_PIOC_PDSR & AT91C_PIO_PC2))

#define WRITE_NAND_COMMAND(cmd) 		do{ *(volatile UINT8 *)((UINT32)AT91_NANDFLASH_BASE | SET_NAND_CLE) = (UINT8)(cmd); } while(0)
#define WRITE_NAND_ADDRESS(nandadr) 	do{ *(volatile UINT8 *)((UINT32)AT91_NANDFLASH_BASE | SET_NAND_ALE) = (UINT8)(nandadr); } while(0)
#define WRITE_NAND_DATA(data) 			do{ *(volatile UINT8 *)((UINT32)AT91_NANDFLASH_BASE) = (UINT8)data; } while(0)
#define READ_NAND_DATA(adr) 			((volatile UINT8)(*(volatile UINT8 *)(UINT32)adr))



#define DEBUG_TFFS_READ     0x00000001
#define DEBUG_TFFS_WRITE    0x00000002
#define DEBUG_TFFS_PROGRAM  0x00000004
#define DEBUG_TFFS_ERASE    0x00000008
#define DEBUG_TFFS_ID       0x00000010
#define DEBUG_TFFS_MAP      0x00000020
#define DEBUG_TFFS_PROG32   0x00000040
#define DEBUG_TFFS_ALWAYS   0xffffffff


#define TFFS_CDSN_DEBUG
#ifdef  TFFS_CDSN_DEBUG
    LOCAL UINT32 tffs_cdsn_debug_switch;
    #define TFFS_CDSN_DEBUG_PRINT(mask, string) \
                if ((tffs_cdsn_debug_switch & mask) || (mask == DEBUG_TFFS_ALWAYS)) \
                printf string
#else
    #define TFFS_CDSN_DEBUG_PRINT(mask, string)
#endif

LOCAL STATUS nand_flash_wait_ready(void);
static unsigned char readStatus(void);


#ifdef INCLUDE_TFFS 

#include "tffs/flflash.h"
#include "tffs/reedsol.h"

#undef NFDC2048	/* Support NFDC2048 ASIC controller */

#define MAX_FLASH_DEVICES   1

#define PAGES_PER_BLOCK     32          /* 32 pages per block on a single chip*/
#define SYNDROM_BYTES       6            /* Number of syndrom bytes: 5 + 1 parity*/

/* Flash IDs*/
#define KM29N16000_FLASH    0xec64
#define KM29N32000_FLASH    0xece5
#define KM29V64000_FLASH    0xece6
#define K9F5608U0B_FLASH    0xec75
#define NM29N16_FLASH       0x8f64
#define NM29N32_FLASH	    0x8fe5
#define NM29N64_FLASH       0x8fe6
#define TC5816_FLASH        0x9864
#define TC5832_FLASH        0x98e5
#define TC5864_FLASH        0x98e6

typedef union {  unsigned short w ; unsigned char b ;  } WordByte;


	/*Memory window to cards common memory*/

typedef struct
{
  volatile WordByte 		signals;            /* CDSN control register*/

	  #define CE                  0x01
	  #define CLE                 0x02
	  #define ALE                 0x04
	  #define NOT_WP              0x08
	  #define RB                  0x80

	  #define FAIL                0x01
	  #define SUSPENDED           0x20
	  #define READY               0x40
	  #define NOT_PROTECTED       0x80

	   unsigned char     	fillerA[1024 - sizeof(WordByte)];
  volatile LEushort 		deviceSelector;
  volatile WordByte             eccConfig;  /* EDC configuration register*/

	#define TOGGLE    0x04              /* Read*/
#ifdef NFDC2048
	#define ECC_RST   0x04              /* Write*/
	#define ECC_EN    0x08              /* Read / Write*/
	#define PAR_DIS   0x10              /* Read / Write*/
	#define ECC_RW    0x20              /* Read / Write*/
	#define ECC_RDY   0x40              /* Read */
	#define ECC_ERROR 0x80              /* Read*/

  volatile unsigned short     	syndrom[3];
	   unsigned char     	fillerC[1024-10];   /* 1kbytes minus 10 bytes*/
#else
	   unsigned char     	fillerC[1024-4];    /* 1kbytes minus 3 words */
#endif	/* NFDC2048 */
  volatile WordByte 		io[1024];
} ContComWin;


/* #defines for writing to ContComWin.eccConfig */  /* HOOK - added */
#define SET_ECC_CONFIG(win,val) ((win)->eccConfig.b = (unsigned char)(val))
#define CHK_ECC_ERROR(win)      ((win)->eccConfig.b & (unsigned char)ECC_ERROR)

typedef ContComWin FAR0 * Interface;

#define  DBL(x)   ( (unsigned char)(x))
#define  SECOND_TRY 0x8000

#ifdef NFDC2048

/* Controller registers: Addresses & values */

#define ATTRIBUTE_MEM_START 0x8000000L  /* Attribute memory starts at 128MB    */

/* Controller configuration register */
#define	CONFIG1		ATTRIBUTE_MEM_START + 0x3ffc

	#define PWR_DN     0x01              /* Read / Write*/
	#define PWR_DN2    0x02              /* Read / Write*/
	#define STOP_CDSN  0x04              /* Read / Write*/
	#define STOP_CDSNS 0x08              /* Read / Write*/
	#define C_CDSN     0x10              /* Read / Write*/
	#define R_CDSN     0x20              /* Read / Write*/
	#define WP_C       0x40              /* Read / Write*/
	#define WP_A       0x80              /* Read / Write*/

/* board's jumper settings*/
#define	JUMPERS		ATTRIBUTE_MEM_START + 0x3ffe

	#define JMPER_INLV      0x08
	#define JMPER_CDSNS     0x10
	#define JMPER_EXT_CIS   0x20
	#define JMPER_LDR_MASK  0x40
	#define JMPER_MAX_MODE  0x80

/* PCMCIA register #0*/
#define CONFIG_OPTION	ATTRIBUTE_MEM_START + 0x4000

	#define CONFIGIDX 0x3F              /* Read / Write*/
	#define SREST     0x80              /* Read / Write*/

/* PCMCIA register #1*/
#define	CARD_CONFIG	ATTRIBUTE_MEM_START + 0x4002

	#define PWRDWN    0x04              /* Read / Write*/

#else

#define INLV 1		/* Must define interleaving statically */

#endif /* NFDC2048 */

/* customization for this MTD*/
/*#define MULTI_ERASE  */   /* use multiple block erase feature*/
#define USE_EDC             /* use Error Detection /Correction Code */
/* #define VERIFY_AFTER_WRITE */

typedef struct {
  unsigned short	vendorID;
  unsigned short	chipID;
  unsigned short      	pageSize ;              /* all....................*/
  unsigned short      	pageMask ;              /* ...these...............*/
  unsigned short      	pageAreaSize ;          /* .......variables.......*/
  unsigned short      	tailSize ;              /* .............interleave*/
  unsigned short      	noOfBlocks ;            /* total erasable blocks in flash device*/
  FLBuffer  		*buffer;		/* buffer for map through buffer */
} Vars;

static Vars mtdVars[DRIVES];

#define thisVars   ((Vars *) vol.mtdVars)
#define thisBuffer (thisVars->buffer->data)

/*----------------------------------------------------------------------*/
/*              t f f s c p y 8 b                                        */
/*									*/
/* Move data in 16-bit words.                                           */
/*                                                                      */
/* Parameters:                                                          */
/*      dst             : destination buffer                            */
/*      src             : source buffer                                 */
/*      len             : bytes to move                                 */
/*                                                                      */
/*----------------------------------------------------------------------*/

static void tffscpy8b (unsigned char FAR0       *dst,
		       const unsigned char FAR0 *src,
		       int                      len)
{
  register int i = 0;

  /* move data in 16-bit words */
  for (i = 0;  len > 0; len--, i++)
    *((volatile unsigned char *) dst + i) = *((unsigned char *) src + i);
}


			
#if FALSE
/*----------------------------------------------------------------------*/
/*              t f f s c p y 1 6                                       */
/*									*/
/* Move data in 16-bit words.                                           */
/*                                                                      */
/* Parameters:                                                          */
/*      dst             : destination buffer                            */
/*      src             : source buffer                                 */
/*      len             : bytes to move                                 */
/*                                                                      */
/*----------------------------------------------------------------------*/

static void tffscpy16 (unsigned char FAR0       *dst,
		       const unsigned char FAR0 *src,
		       int                      len)
{
  register int i = 0;

  /* move data in 16-bit words */
  for (i = 0;  i < (len >> 1);  i++)
    *((unsigned short *) dst + i) = *((unsigned short *) src + i);

  /* move last byte (if any) */
  if (len & 1)
    *(dst + len-1) = *(src + len-1);
}

/*----------------------------------------------------------------------*/
/*              t f f s s e t 1 6                                       */
/*									*/
/* Set data buffer in 16-bit words.                                     */
/*                                                                      */
/* Parameters:                                                          */
/*      dst             : destination buffer                            */
/*      val             : byte value tofill the buffer                  */
/*      len             : setination buffer size in bytes               */
/*                                                                      */

⌨️ 快捷键说明

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