arm2440的nandflash相关函数
下面几点是编程时需要注意的:
1.NAND FLASH芯片手册里说的column是指页内地址,row是指页地址,page也是指页;
2.删除时是以块为单位的,但是删除块时写的是row地址,自动会删除row所在的块;
3.读写方式有页读写,或随机读写,所谓的随机读写就是可以在页内的任一地方读写一个字节;
4.ECC校验码分为main区的ECC和spare区的ECC,它们一般都会存放在64字节的spare区内,下面是翻译2440手册的关于ECC编程的内容:
MainECCLock(NFCONT[5]) 和 SpareECCLock(NFCONT[6] 控制 ECC 校验码是否产生。
接下来是代码:
#ifndef __NAND_FLASH_H__ //为了防止重复包含
#define __NAND_FLASH_H__
#include "lhg_def.h" //U8,U32相关的宏,也即变量类型
#define MAX_NAND_BLOCK 2048
#define NAND_PAGE_SIZE 2048 //2048 blocks,1block has 64pages, each page has 2k+64 bytes
typedef struct nand_id_info //这样的结构体变量保存芯片的ID信息
{
} nand_id_info;
typedef struct bad_block_info //登记坏块用的,只记录数量,没有记录坏块地址
{
} bad_block_info;
//
//NAND 操作指令,??从哪里来的,我看你怎么用
#define NAND_CMD_READ_1st
#define NAND_CMD_READ_2st
#define NAND_CMD_RANDOM_WRITE
#define NAND_CMD_RANDOM_READ_1st
#define NAND_CMD_RANDOM_READ_2st
#define NAND_CMD_READ_CB_1st
#define NAND_CMD_READ_CB_2st
#define NAND_CMD_READ_ID
#define NAND_CMD_RES
#define NAND_CMD_WRITE_PAGE_1st
#define NAND_CMD_WRITE_PAGE_2st
#define NAND_CMD_BLOCK_ERASE_1st
#define NAND_CMD_BLOCK_ERASE_2st
#define NAND_CMD_READ_STATUS
//NAND 中断向量,?这是什么意思
#define INT_NFCON (24)
//NFCONF HCLK=100MHZ,nandflash configuration register
#define S3C2440_NFCONF_TACLS_init (1<12) //设置cle ale的持续时间,NFCONF[14:12]
#define S3C2440_NFCONF_TWRPH0_init (4<8) //TWRPH0持续时间设置,NFCONF[10:8]
#define S3C2440_NFCONF_TWRPH1_init (0<4) //TWRPH1持续时间设置,NFCONF[6:4]
#define S3C2440_NFCONF_BusWidth_init (0)
#define S3C2440_NFCONF_init() ( rNFCONF = S3C2440_NFCONF_TACLS_init
//NFCONT,nandflash control register
#define S3C2440_NFCONT_LockTight_init (0<13)//disable lock-tight
#define S3C2440_NFCONT_SoftLock_init (0<12)//disable lock
#define S3C2440_NFCONT_EnbIllegalAccINT_init (1<10)//illegal access interrupt enable
#define S3C2440_NFCONT_EnbRnBINT_init (0<9)//RnB ready not busy
#define S3C2440_NFCONT_RnB_TransMode_init (0<8)//detect RnB type is rising edge
#define S3C2440_NFCONT_SpareECCLock_init (1<6)//1 is to lock spare
#define S3C2440_NFCONT_MainECCLock_init (1<5)//1 is to lock main area ecc generation
#define S3C2440_NFCONT_InitECC_init (1<4)//1 is to initialize ecc decoder and encoder
#define S3C2440_NFCONT_Reg_nCE_init (1<1)//force nFCE to high,namely disable chip-select
#define S3C2440_NFCONT_MODE_init (0)//disable nandflash controller
#define S3C2440_NFCONT_init() ( rNFCONT = S3C2440_NFCONT_LockTight_init | /
//NFSTAT
#define S3C2440_NFSTAT_init() ( rNFSTAT &= 0x3 )//NFSTAT 8 bits, 0x3 means nCE output high,
//NFESTAT0
#define S3C2440_NFESTAT0_init() ( rNFESTAT0 = 0 )//ecc status for io0-io7,k9f1208 only io0-i07
//NFESTAT1
#define S3C2440_NFESTAT1_init() ( rNFESTAT1 = 0 )//ecc status for io8-io15
//
#define select_nand() ( rNFCONT &= ~(1<1) )
#define dis_select_nand() ( rNFCONT |= 1<1 )片选信号设置不说了啊
#define controller_enable() ( rNFCONT |= 1 )
#define controller_disable() ( rNFCONT &= ~1 )nandflash控制器使能与否也不说了
//
extern void nand_flash_init(void);//初始化,extern意思是提供给外部上层
arm2440nandflash函 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)