arm_mini2440_nand_flash 的操作

  • e5_489349
    了解作者
  • 280KB
    文件大小
  • 文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-01 01:26
    上传日期
mini2440 对NAND_FLASH的操作,代码里的可执行文件在我的mini2440测试正确,有什么不对的欢迎大家指正。
nand.tar.gz
  • nand
  • bin
  • nand.bin
    1.8KB
  • main.d
    16B
  • main.o
    6.1KB
  • nand_sct.Bak
    477B
  • nand.lnp
    260B
  • init.crf
    275B
  • nand.tra
    967B
  • main.crf
    341B
  • nand.crf
    2.8KB
  • nand.d
    16B
  • nand.map
    48.5KB
  • nand.o
    11.1KB
  • init.d
    16B
  • nand.axf
    17.4KB
  • nand.sct
    537B
  • head.lst
    4KB
  • head.s
    564B
  • init.c
    506B
  • nand.c
    4.8KB
  • init.o
    6.2KB
  • nand.uvproj
    14.6KB
  • nand_uvopt.bak
    46.6KB
  • nand.uvopt
    46.6KB
  • nand_Target 1.dep
    667B
  • nand.htm
    20.7KB
  • nand_uvproj.bak
    14.6KB
  • nand.plg
    157B
  • head.o
    1.9KB
  • main.c
    537B
内容介绍
#define GSTAUS1 (*(volatile unsigned int *)0x560000b0) #define BUSY 1 typedef unsigned long S3C24X0_REG32; //nand_flash需要设置的寄存器 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 NFSTAT; S3C24X0_REG32 NFESTAT0; S3C24X0_REG32 NFESTAT1; S3C24X0_REG32 NFMECC0; S3C24X0_REG32 NFMECC1; S3C24X0_REG32 NFSECC; S3C24X0_REG32 NFSBLK; S3C24X0_REG32 NFEBLK; } S3C2440_NAND; //nand_flash需要操作的函数 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; //nand_flash两个结构体变量 static S3C2440_NAND *s3c2440nand = (S3C2440_NAND *)0x4e000000; static t_nand_chip nand_chip; //对nand_flash的两个操作 void nand_init(void); void nand_read(unsigned char *buf, unsigned long start_addr, int size); //nand_flash两个操作所需的函数 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 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 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 s3c2440_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 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 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; nand_chip.write_addr = s3c2440_write_addr; nand_chip.read_data = s3c2440_read_data; /* 设置时序 */ s3c2440nand->NFCONF = (TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4); /* 使能NAND Flash控制器*/ s3c2440nand->NFCONT = (1<<4)|(1<<1)|(1<<0); /* \u017e\u017d位NAND Flash */ nand_reset(); } #define NAND_SECTOR_SIZE 2048 #define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1) /* 读函数 */ void nand_read(unsigned char *buf, unsigned long start_addr, int size) { int i, j; if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) { return ; /* 地址对齐*/ } /* 选中芯片 */ nand_select_chip(); for(i=start_addr; i < (start_addr + size);) { /* 发出READ0命令 */ write_cmd(0); /* Write Address */ write_addr(i); wait_idle(); for(j=0; j < NAND_SECTOR_SIZE; j++, i++) { *buf = read_data(); buf++; } } /* 取消片选信号 */ nand_deselect_chip(); }
评论
    相关推荐