NANDFlashd的读写(基于s3c2440)
时间:11-20
来源:互联网
点击:
- #ifndef__TEST_H__
- #define__TEST_H__
- #include"def.h"
- #defineMAX_NAND_BLOCK2048//一共2048块
- #defineNAND_PAGE_SIZE2048//每块main区2k字节=2048
- typedefstructnand_id_info//芯片的ID信息
- {
- U8IDm;//厂商ID
- U8IDd;//设备ID
- U8ID3rd;
- U8ID4th;
- U8ID5th;
- }nand_id_info;
- typedefstructbad_block_info//登记坏块
- {
- U8area[MAX_NAND_BLOCK];//0表示非坏块,1表示坏块
- U32sum;//坏块的总数
- }bad_block_info;
- //NAND操作指令
- #defineNAND_CMD_READ_1st0x00
- #defineNAND_CMD_READ_2st0x30
- #defineNAND_CMD_RANDOM_WRITE0x85//随机写
- #defineNAND_CMD_RANDOM_READ_1st0x05
- #defineNAND_CMD_RANDOM_READ_2st0xe0
- #defineNAND_CMD_READ_CB_1st0x00//将NAND里一块内容写进另一块
- #defineNAND_CMD_READ_CB_2st0x35
- #defineNAND_CMD_READ_ID0x90
- #defineNAND_CMD_RES0xff//复位命令
- #defineNAND_CMD_WRITE_PAGE_1st0x80
- #defineNAND_CMD_WRITE_PAGE_2st0x10
- #defineNAND_CMD_BLOCK_ERASE_1st0x60//擦除命令
- #defineNAND_CMD_BLOCK_ERASE_2st0xd0
- #defineNAND_CMD_READ_STATUS0x70
- //NAND中断向量
- #defineINT_NFCON24
- //NFCONFHCLK=100MHZ
- #defineS3C2440_NFCONF_TACLS_init(1<12)
- #defineS3C2440_NFCONF_TWRPH0_init(4<8)
- #defineS3C2440_NFCONF_TWRPH1_init(0<4)
- #defineS3C2440_NFCONF_BusWidth_init(0)
- #defineS3C2440_NFCONF_init()(rNFCONF=S3C2440_NFCONF_TACLS_init|/
- S3C2440_NFCONF_TWRPH0_init|/
- S3C2440_NFCONF_TWRPH1_init|/
- S3C2440_NFCONF_BusWidth_init)
- //NFCONT
- #defineS3C2440_NFCONT_LockTight_init(0<13)
- #defineS3C2440_NFCONT_SoftLock_init(0<12)
- #defineS3C2440_NFCONT_EnbIllegalAccINT_init(1<10)
- #defineS3C2440_NFCONT_EnbRnBINT_init(0<9)
- #defineS3C2440_NFCONT_RnB_TransMode_init(0<8)
- #defineS3C2440_NFCONT_SpareECCLock_init(1<6)
- #defineS3C2440_NFCONT_MainECCLock_init(1<5)
- #defineS3C2440_NFCONT_InitECC_init(1<4)
- #defineS3C2440_NFCONT_Reg_nCE_init(1<1)//初始配置片选无效
- #defineS3C2440_NFCONT_MODE_init(0)
- #defineS3C2440_NFCONT_init()(rNFCONT=S3C2440_NFCONT_LockTight_init|/
- S3C2440_NFCONT_SoftLock_init|/
- S3C2440_NFCONT_EnbIllegalAccINT_init|/
- S3C2440_NFCONT_EnbRnBINT_init|/
- S3C2440_NFCONT_RnB_TransMode_init|/
- S3C2440_NFCONT_SpareECCLock_init|/
- S3C2440_NFCONT_MainECCLock_init|/
- S3C2440_NFCONT_InitECC_init|/
- S3C2440_NFCONT_Reg_nCE_init|/
- S3C2440_NFCONT_MODE_init)
- //NFSTAT
- #defineS3C2440_NFSTAT_init()(rNFSTAT&=0x3)
- //NFESTAT0
- #defineS3C2440_NFESTAT0_init()(rNFESTAT0=0)
- //NFESTAT1
- #defineS3C2440_NFESTAT1_init()(rNFESTAT1=0)
- //
- #defineselect_nand()(rNFCONT&=~(1<1))
- #definedis_select_nand()(rNFCONT|=1<1)
- #definecontroller_enable()(rNFCONT|=1)
- #definecontroller_disable()(rNFCONT&=~1)
- //
- voidnand_flash_init(void);//初始化
- voidnand_read_id(void);
- externintnand_block_erase(U32num);//num要删除的块号
- externintnand_page_write(U32addr,U8*buffer,U32size);//addr要写的起始页地址,buffer要写的缓存,size要写的字节大小最大为4G
- externintnand_page_read(U32addr,U8*buffer,U32size);//addr开始页地址,从每页00地址开始读
- externintnand_random_read(U32paddr,U32offset,U8*data);//随机读数据paddr页地址,offset页内偏移地址
- externintnand_random_write(U32paddr,U32offset,U8data);//随机写,paddr页地址,offset页内区最后一个地偏移地址
- externvoidnand_test_bad_block(void);//测试坏块函数,并标记在nand_bbi变量里和spare里(如果非0xff则为坏块)
- #endif
- #include"2440addr.h"
- #include"test.h"
- #include"def.h"
- #defineNAND_DEBUG1//打印一些串口调试信息
- #defineUSE_ECC1//使用ECC验证
- nand_id_infonand_id;//定义登记芯片ID的全局变量
- bad_block_infonand_bbi;//定义来登记坏的全局变量
- voidinit_nand_bbi(void)//初始化变量
- {
- U32i;
- nand_bbi.sum=0;
- for(i=0;i
- nand_bbi.area[i]=0;//全部初始化为0
- }
- voidnand_mask_bad_block(U32n)//标志坏块,n是坏块的块号
- {
- #ifdefNAND_DEBUG
- Uart_Printf("NANDfoundandmaskabadblock=%d.",n);
- #endif
- if(nand_bbi.area[n]!=1)
- {
- nand_bbi.area[n]=1;
- nand_bbi.sum++;
- nand_random_write(n*64,2048+64-1,0);//每块的第一个spare的最后一个字节,标志本块是否为坏块,非0xff为坏块
- }
- }
- intdetect_nand_busy(void)//检测是否忙
- {
- U32a;
- a=0;
- while(!(rNFSTAT&(1<2)))
- {
- a++;
- if(a==5000000)//等待超时
- {
- Uart_Prin
NANDFlashd读写s3c244 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)