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

ARM·Nand Flash的控制

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

gned int S3C24X0_REG32;

typedef struct {

S3C24X0_REG32 NFCONF;

S3C24X0_REG32 NFCMD;

S3C24X0_REG32 NFADDR;

S3C24X0_REG32 NFDATA;

S3C24X0_REG32 NFSTAT;

S3C24X0_REG32 NFECC;

} S3C2410_NAND;

typedef struct {

S3C24X0_REG32 NFCONF;

S3C24X0_REG32 NFCONT;

S3C24X0_REG32 NFCMD;

S3C24X0_REG32 NFADDR;

S3C24X0_REG32 NFDATA;

S3C24X0_REG32 NFMECCD0;

S3C24X0_REG32 NFMECCD1;

S3C24X0_REG32 NFSECCD;

S3C24X0_REG32 NFSTAT;

S3C24X0_REG32 NFESTAT0;

S3C24X0_REG32 NFESTAT1;

S3C24X0_REG32 NFMECC0;

S3C24X0_REG32 NFMECC1;

S3C24X0_REG32 NFSECC;

S3C24X0_REG32 NFSBLK;

S3C24X0_REG32 NFEBLK;

} S3C2440_NAND;

typedef struct {

void (*nand_reset)(void);

void (*wait_idle)(void);

void (*nand_select_chip)(void);

void (*nand_deselect_chip)(void);

void (*write_cmd)(int cmd);

void (*write_addr)(unsigned int addr);

unsigned char (*read_data)(void);

}t_nand_chip;

static S3C2410_NAND * s3c2410nand = (S3C2410_NAND *)0x4e000000;

static S3C2440_NAND * s3c2440nand = (S3C2440_NAND *)0x4e000000;

static t_nand_chip nand_chip;

void nand_init(void);

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

static void nand_reset(void);

static void wait_idle(void);

static void nand_select_chip(void);

static void nand_deselect_chip(void);

static void write_cmd(int cmd);

static void write_addr(unsigned int addr);

static unsigned char read_data(void);

static void s3c2410_nand_reset(void);

static void s3c2410_wait_idle(void);

static void s3c2410_nand_select_chip(void);

static void s3c2410_nand_deselect_chip(void);

static void s3c2410_write_cmd(int cmd);

static void s3c2410_write_addr(unsigned int addr);

static unsigned char s3c2410_read_data();

static void s3c2440_nand_reset(void);

static void s3c2440_wait_idle(void);

static void s3c2440_nand_select_chip(void);

static void s3c2440_nand_deselect_chip(void);

static void s3c2440_write_cmd(int cmd);

static void s3c2440_write_addr(unsigned int addr);

static unsigned char s3c2440_read_data(void);

static void s3c2410_nand_reset(void)

{

s3c2410_nand_select_chip();

s3c2410_write_cmd(0xff); // 复位命令

s3c2410_wait_idle();

s3c2410_nand_deselect_chip();

}

static void s3c2410_wait_idle(void)

{

int i;

volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFSTAT;

while(!(*p & BUSY))

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

}

static void s3c2410_nand_select_chip(void)

{

int i;

s3c2410nand->NFCONF &= ~(1<11);

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

}

static void s3c2410_nand_deselect_chip(void)

{

s3c2410nand->NFCONF |= (1<11);

}

static void s3c2410_write_cmd(int cmd)

{

volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFCMD;

*p = cmd;

}

static void s3c2410_write_addr(unsigned int addr)

{

int i;

volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->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 unsigned char s3c2410_read_data(void)

{

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

return *p;

}

static void s3c2440_nand_reset(void)

{

s3c2440_nand_select_chip();

s3c2440_write_cmd(0xff); // 复位命令

s3c2440_wait_idle();

s3c2440_nand_deselect_chip();

}

static void s3c2440_wait_idle(void)

{

int i;

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

while(!(*p & BUSY))

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

}

static void s3c2440_nand_select_chip(void)

{

int i;

s3c2440nand->NFCONT &= ~(1<1);

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

}

static void s3c2440_nand_deselect_chip(void)

{

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

}

static void s3c2440_write_cmd(int cmd)

{

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

*p = cmd;

}

static void s3c

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

网站地图

Top