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

📄 flash.h

📁 嵌入式ARM的一些源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/**************** DEFINES for Intel 28F008S5 FLASH chip **********************/

/* register addresses, valid only following a I8S5_CMD_RD_ID command */
#define I8S5_ADDR_MAN	0x00000	/* manufacturer's id */
#define I8S5_ADDR_DEV	0x00001	/* device id */
#define I8S5_ADDR_CFGM	0x00003	/* master lock configuration */
#define I8S5_ADDR_CFG0	0x00002	/* block lock configuration */
#define I8S5_ADDR_CFG1	0x10002	/* " */
#define I8S5_ADDR_CFG2	0x20002	/* " */
#define I8S5_ADDR_CFG3	0x30002	/* " */
#define I8S5_ADDR_CFG4	0x40002	/* " */
#define I8S5_ADDR_CFG5	0x50002	/* " */
#define I8S5_ADDR_CFG6	0x60002	/* " */
#define I8S5_ADDR_CFG7	0x70002	/* " */
#define I8S5_ADDR_CFG8	0x80002	/* " */
#define I8S5_ADDR_CFG9	0x90002	/* " */
#define I8S5_ADDR_CFG10	0xA0002	/* " */
#define I8S5_ADDR_CFG11	0xB0002	/* " */
#define I8S5_ADDR_CFG12	0xC0002	/* " */
#define I8S5_ADDR_CFG13	0xD0002	/* " */
#define I8S5_ADDR_CFG14	0xE0002	/* " */
#define I8S5_ADDR_CFG15	0xF0002	/* " */

/* Commands */
#define I8S5_CMD_RST	0xFF	/* reset flash */
#define I8S5_CMD_RD_ID	0x90	/* read the id and lock bits */
#define I8S5_CMD_RD_STAT 0x70	/* read the status register */
#define I8S5_CMD_CLR_STAT 0x50	/* clear the staus register */
#define I8S5_CMD_ERASE1	0x20	/* first word for block erase */
#define I8S5_CMD_ERASE2	0xD0	/* second word for block erase */
#define I8S5_CMD_PROG	0x40	/* program word command */
#define I8S5_CMD_LOCK	0x60	/* first word for all lock commands */
#define I8S5_CMD_SET_LOCK_BLK 0x01 /* 2nd word for set block lock bit */
#define I8S5_CMD_SET_LOCK_MSTR 0xF1 /* 2nd word for set master lock bit */
#define I8S5_CMD_CLR_LOCK_BLK 0xD0 /* 2nd word for clear block lock bit */

/* status register bits */
#define I8S5_STAT_DPS	0x02	/* Device Protect Status */
#define I8S5_STAT_PSS	0x04	/* Program Suspend Status */
#define I8S5_STAT_VPPS	0x08	/* VPP Status */
#define I8S5_STAT_PSLBS	0x10	/* Program and Set Lock Bit Status */
#define I8S5_STAT_ECLBS	0x20	/* Erase and Clear Lock Bit Status */
#define I8S5_STAT_ESS	0x40	/* Erase Suspend Status */
#define I8S5_STAT_RDY	0x80	/* Write State Machine Status, 1=rdy */

#define I8S5_STAT_ERR	(I8S5_STAT_VPPS | I8S5_STAT_DPS | \
			    I8S5_STAT_ECLBS | I8S5_STAT_PSLBS)

/* ID and Lock Configuration */
#define I8S5_RD_ID_LOCK	0x01	/* Bit 0 of each byte */
#define I8S5_RD_ID_MAN	0x89	/* Manufacturer code = 0x89 */
#define I8S5_RD_ID_DEV	0xA6	/* Device code = 0xA6, 28F008S5 */

/* dimensions */
#define I8S5_NBLOCKS	16		/* a 28F008S5 consists of 16 blocks */
#define I8S5_BLKSZ	(64*1024)	/* of 64Kbyte each */
#define I8S5_SIZE	(I8S5_BLKSZ * I8S5_NBLOCKS)

/**************** DEFINES for Intel 28F800B5 FLASH chip **********************/

/* register addresses, valid only following a I8S5_CMD_RD_ID command */
#define I8B5_ADDR_MAN	0x00000	/* manufacturer's id */
#define I8B5_ADDR_DEV	0x00001	/* device id */

/* Commands */
#define I8B5_CMD_RST	0xFF	/* reset flash */
#define I8B5_CMD_RD_ID	0x90	/* read the id and lock bits */
#define I8B5_CMD_RD_STAT 0x70	/* read the status register */
#define I8B5_CMD_CLR_STAT 0x50	/* clear the staus register */
#define I8B5_CMD_ERASE1	0x20	/* first word for block erase */
#define I8B5_CMD_ERASE2	0xD0	/* second word for block erase */
#define I8B5_CMD_PROG	0x40	/* program word command */

/* status register bits */
#define I8B5_STAT_VPPS	0x08	/* VPP Status */
#define I8B5_STAT_DWS	0x10	/* Program and Set Lock Bit Status */
#define I8B5_STAT_ES	0x20	/* Erase and Clear Lock Bit Status */
#define I8B5_STAT_ESS	0x40	/* Erase Suspend Status */
#define I8B5_STAT_RDY	0x80	/* Write State Machine Status, 1=rdy */

#define I8B5_STAT_ERR	(I8B5_STAT_VPPS | I8B5_STAT_DWS | I8B5_STAT_ES)

/* ID Configuration */
#define I8B5_RD_ID_MAN	0x89	/* Manufacturer code = 0x89 */
#define I8B5_RD_ID_DEV1	0x889D	/* Device code = 0x889D, 28F800B5 */

/* dimensions */
#define I8B5_NBLOCKS	8		/* a 28F008S5 consists of 16 blocks */
#define I8B5_BLKSZ	(128*1024)	/* of 64Kbyte each */
#define I8B5_SIZE	(I8B5_BLKSZ * I8B5_NBLOCKS)

/****************** DEFINES for Cogent CMA302 Flash **************************/

/*
 * Quoted from the CMA302 manual:
 *
 * Although the CMA302 supports 64-bit reads, all writes must be done with
 * word size only. When programming the CMA302, the FLASH devices appear as 2
 * banks of interleaved, 32-bit wide FLASH. Each 32-bit word consists of four
 * 28F008S5 devices. The first bank is accessed when the word address is even,
 * while the second bank is accessed when the word address is odd. This must
 * be taken into account when programming the desired word. Also, when locking
 * blocks, software must lock both banks. The CMA302 does not directly support
 * byte writing.  Programming and/or erasing individual bytes is done with
 * selective use of the Write Command.  By not placing the Write Command value
 * on a particular byte lane, that byte will not be written with the following
 * Write Data. Also, remember that within a byte lane (i.e. D0-7), there are
 * two 28F008S5 devices, one for each bank or every other word.
 *
 * End quote.
 *
 * Each 28F008S5 is 8Mbit, with 8 bit wide data. i.e. each is 1Mbyte. The
 * chips are arranged on the CMA302 in multiples of two banks, each bank having
 * 4 chips. Each bank must be accessed as a single 32 bit wide device (i.e.
 * aligned on a 32 bit boundary), with each byte lane within the 32 bits (0-3)
 * going to each of the 4 chips and the word address selecting the bank, even
 * being the low bank and odd the high bank. For 64bit reads, both banks are
 * read simultaneously with the second bank on byte lanes 4-7. Each 28F008S5
 * consists of 16 64Kbyte "block"s. Before programming a byte, the block that
 * the byte resides within must be erased. So if you want to program contiguous
 * memory locations, you must erase all 8 chips at the same time. i.e. the
 * flash on the CMA302 can be viewed as a number of 512Kbyte blocks.
 *
 * Note: I am going to treat banks as 8 Mbytes (1Meg of 64bit words), whereas
 * the example code treats them as a pair of interleaved 1 Mbyte x 32bit banks.
 */

typedef unsigned long c302f_word_t;	/* 32 or 64 bit unsigned integer */
typedef volatile c302f_word_t *c302f_addr_t;
typedef unsigned long c302f_size_t;	/* want this big - at least 32 bit */

/* layout of banks on cma302 board */
#define C302F_BNK_WIDTH		8	/* each bank is 8 chips wide */
#define C302F_BNK_WSHIFT	3	/* log base 2 of C302F_BNK_WIDTH */
#define C302F_BNK_NBLOCKS	I8S5_NBLOCKS
#define C302F_BNK_BLKSZ		(I8S5_BLKSZ * C302F_BNK_WIDTH)
#define C302F_BNK_SIZE		(I8S5_SIZE * C302F_BNK_WIDTH)

#define C302F_MAX_BANKS		2	/* up to 2 banks (8M each) on CMA302 */

/* align addresses and sizes to bank boundaries */
#define C302F_BNK_ADDR_ALIGN(a)	((c302f_addr_t)((c302f_size_t)(a) \
				    & ~(C302F_BNK_WIDTH - 1)))
#define C302F_BNK_SIZE_ALIGN(s)	((c302f_size_t)C302F_BNK_ADDR_ALIGN( \
				    (c302f_size_t)(s) + (C302F_BNK_WIDTH - 1)))

/* align addresses and sizes to block boundaries */
#define C302F_BLK_ADDR_ALIGN(a)	((c302f_addr_t)((c302f_size_t)(a) \
				    & ~(C302F_BNK_BLKSZ - 1)))
#define C302F_BLK_SIZE_ALIGN(s)	((c302f_size_t)C302F_BLK_ADDR_ALIGN( \
				    (c302f_size_t)(s) + (C302F_BNK_BLKSZ - 1)))

/* add a byte offset to a flash address */
#define C302F_ADDR_ADD_BYTEOFF(a,o) \
				(c302f_addr_t)((c302f_size_t)(a) + (o))

/* get base address of bank b, given flash base address a */
#define C302F_BNK_ADDR_BASE(a,b) \
				C302F_ADDR_ADD_BYTEOFF((a), \
				    (c302f_size_t)(b) * C302F_BNK_SIZE)

/* adjust an address a (within a bank) to next word, block or bank */
#define C302F_BNK_ADDR_NEXT_WORD(a) \
				C302F_ADDR_ADD_BYTEOFF((a), C302F_BNK_WIDTH)
#define C302F_BNK_ADDR_NEXT_BLK(a) \
				C302F_ADDR_ADD_BYTEOFF((a), C302F_BNK_BLKSZ)
#define C302F_BNK_ADDR_NEXT_BNK(a) \
				C302F_ADDR_ADD_BYTEOFF((a), C302F_BNK_SIZE)

/* get bank address of chip register r given a bank base address a */
#define C302F_BNK_ADDR_I8S5REG(a,r) \
				C302F_ADDR_ADD_BYTEOFF((a), \
				    (r) << C302F_BNK_WSHIFT)

/* make a bank representation for each chip address */

⌨️ 快捷键说明

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