微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM·Nand Flash的控制

ARM·Nand Flash的控制

时间:11-24 来源:互联网 点击:

2440_write_addr(unsigned int addr)

{

int i;

volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFADDR;

*p = addr & 0xff;

for(i=0; i<10; i++);

*p = (addr >> 9) & 0xff;

for(i=0; i<10; i++);

*p = (addr >> 17) & 0xff;

for(i=0; i<10; i++);

*p = (addr >> 25) & 0xff;

for(i=0; i<10; i++);

}

static void s3c2440_write_addr_lp(unsigned int addr)

{

int i;

volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFADDR;

int col, page;

col = addr & NAND_BLOCK_MASK_LP;

page = addr / NAND_SECTOR_SIZE_LP;

*p = col & 0xff;

for(i=0; i<10; i++);

*p = (col >> 8) & 0x0f;

for(i=0; i<10; i++);

*p = page & 0xff;

for(i=0; i<10; i++);

*p = (page >> 8) & 0xff;

for(i=0; i<10; i++);

*p = (page >> 16) & 0x03;

for(i=0; i<10; i++);

}

static unsigned char s3c2440_read_data(void)

{

volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFDATA;

return *p;

}

static void nand_reset(void)

{

nand_chip.nand_reset();

}

static void wait_idle(void)

{

nand_chip.wait_idle();

}

static void nand_select_chip(void)

{

int i;

nand_chip.nand_select_chip();

for(i=0; i<10; i++);

}

static void nand_deselect_chip(void)

{

nand_chip.nand_deselect_chip();

}

static void write_cmd(int cmd)

{

nand_chip.write_cmd(cmd);

}

static void write_addr(unsigned int addr)

{

nand_chip.write_addr(addr);

}

static unsigned char read_data(void)

{

return nand_chip.read_data();

}

void nand_init(void)

{

#define TACLS 0

#define TWRPH0 3

#define TWRPH1 0

if ((GSTATUS1 == 0x32410000) || (GSTATUS1 == 0x32410002))

{

nand_chip.nand_reset = s3c2410_nand_reset;

nand_chip.wait_idle = s3c2410_wait_idle;

nand_chip.nand_select_chip = s3c2410_nand_select_chip;

nand_chip.nand_deselect_chip = s3c2410_nand_deselect_chip;

nand_chip.write_cmd = s3c2410_write_cmd;

nand_chip.write_addr = s3c2410_write_addr;

nand_chip.read_data = s3c2410_read_data;

s3c2410nand->NFCONF = (1<15)|(1<12)|(1<11)|(TACLS<8)|(TWRPH0<4)|(TWRPH1<0);

}

else

{

nand_chip.nand_reset = s3c2440_nand_reset;

nand_chip.wait_idle = s3c2440_wait_idle;

nand_chip.nand_select_chip = s3c2440_nand_select_chip;

nand_chip.nand_deselect_chip = s3c2440_nand_deselect_chip;

nand_chip.write_cmd = s3c2440_write_cmd;

#ifdef LARGER_NAND_PAGE

nand_chip.write_addr = s3c2440_write_addr_lp;

#else

nand_chip.write_addr = s3c2440_write_addr;

#endif

nand_chip.read_data = s3c2440_read_data;

s3c2440nand->NFCONF = (TACLS<12)|(TWRPH0<8)|(TWRPH1<4);

s3c2440nand->NFCONT = (1<4)|(1<1)|(1<0);

}

nand_reset();

}

void nand_read(unsigned char *buf, unsigned long start_addr, int size)

{

int i, j;

#ifdef LARGER_NAND_PAGE

if ((start_addr & NAND_BLOCK_MASK_LP) || (size & NAND_BLOCK_MASK_LP)) {

return ;

}

#else

if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {

return ;

}

#endif

nand_select_chip();

for(i=start_addr; i < (start_addr + size);) {

write_cmd(0);

write_addr(i);

#ifdef LARGER_NAND_PAGE

write_cmd(0x30);

#endif

wait_idle();

#ifdef LARGER_NAND_PAGE

for(j=0; j < NAND_SECTOR_SIZE_LP; j++, i++) {

#else

for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {

#endif

*buf = read_data();

buf++;

}

}

nand_deselect_chip();

return ;

}

这一长串红色的代码也就是Nand Flash的初始化,我们可以仔细的分析一下Nand的控制寄存器

再看代码,从head.s中也就跳转到了nand.c中的灰色部分 ;

1)S3C2410和S3C2440的一个判断

2)定义了一个结构体

{

nand_chip.nand_reset = s3c2440_nand_reset;

nand_chip.wait_idle = s3c2440_wait_idle;

nand_chip.nand_select_chip = s3c2440_nand_select_chip;

nand_chip.nand_deselect_chip = s3c2440_nand_deselect_chip;

nand_chip.write_cmd = s3c2440_write_cmd;

#ifdef LARGER_NAND_PAGE

nand_chip.write_addr = s3c2440_write_addr_lp;

#else

nand_chip.write_addr = s3c2440_write_addr;

#endif

nand_chip.read_data = s3c2440_read_data;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top