nand_read.c

来自「英培特EDUKIT-III实验箱核心子板为s3c2410」· C语言 代码 · 共 60 行

C
60
字号
#include "s3c2410.h"#include "machine.h"#define BUSY 1inline void wait_idle(void) {	int i;	while (!(NFSTAT & BUSY)) {		for(i=0; i<10; i++) {			;		}	}}#define NAND_SECTOR_SIZE	512#define NAND_BLOCK_MASK		(NAND_SECTOR_SIZE - 1)/* low level nand read function */int nand_read_ll(unsigned char *buf, unsigned long start_addr, int size){	int i, j;	/*	 * K9F5608UOC asks for 512B per page, and read/write operation must	 * do with page. Therefore, first judge whether start_addr and size	 * are valid.	 */ 	if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {		return -1;	/* invalid alignment */	}	/* chip Enable */	NFCONF &= ~0x800;	for (i=0; i<10; i++) {		;	}	for (i=start_addr; i < (start_addr + size); i+=NAND_SECTOR_SIZE) {		NFCMD = 0;		/* Write Address */		NFADDR = i & 0xff;		NFADDR = (i >> 9) & 0xff;		NFADDR = (i >> 17) & 0xff;		NFADDR = (i >> 25) & 0xff;		wait_idle(); 		for(j=0; j < NAND_SECTOR_SIZE; j++) {			*buf++ = (NFDATA & 0xff);		}	}	/* chip Disable */	NFCONF |= 0x800;	/* chip disable */	return 0;}

⌨️ 快捷键说明

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