欢迎来到天天文库
浏览记录
ID:50556113
大小:33.50 KB
页数:8页
时间:2020-03-10
《NandFlash的规范程序代码.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、nandflash裸机驱动程序的分析nandflash在嵌入式设备中广泛的应用,学些nandflash的重要性不言而喻,这里分析一段实例代码,不管是编码规范还是程序的结构都是很有价值的。下边是K9F1208U0M的实例代码。首先看nand.h文件:#ifndef__NAND_Flash__#define__NAND_Flash__externvoidInitNandCfg(void);//初始化K9F1208UOMNANDflash配置externunsignedintReadChipId(void);//读取NANDFlash的ID号externu
2、nsignedshortReadStatus(void);//读取NANDFlash的状态externunsignedintEraseBlock(unsignedintaddr);//NANDFlash块擦除externvoidReadPage(unsignedintaddr,unsignedchar*buf);//K9F1208U0Mnandflash的页数据读externvoidWritePage(unsignedintaddr,unsignedchar*buf);//K9F1208U0Mnandflash的页数据写externvoidMarkB
3、adBlk(unsignedintaddr);//屏蔽K9F1208U0Mnandflash的坏块externintCheckBadBlk(unsignedintaddr);//检查K9F1208U0Mnandflash的坏块externvoidInitNandFlash(void);//K9F1208U0Mnandflash的初始化#endif需要详细看的是nandflash.c文件://====================================================//常量定义区//====================
4、================================#defineEnNandFlash()(rNFCONF
5、=0x8000)//bit15=1enableNANDflashcontroller#defineDsNandFlash()(rNFCONF&=~0x8000)//bit15=1disableNANDflashcontroller#defineInitEcc()(rNFCONF
6、=0x1000)//bit12=1initializeECC#defineNoEcc()(rNFCONF&=~0x1000)//bit12=0initia
7、lizeECC#defineNFChipEn()(rNFCONF&=~0x800)//bit11=0NANDflashnFCE=L(active)#defineNFChipDs()(rNFCONF
8、=0x800)//bit11=1NANDflashnFCE=H(inactive)#defineWrNFCmd(cmd)(rNFCMD=(cmd))//writecommondtonandflash#defineWrNFAddr(addr)(rNFADDR=(addr))//writeaddresstonandflash#defineWrNFDat(dat
9、)(rNFDATA=(dat))//writedatatonandflash#defineRdNFDat()(rNFDATA)//readdatafromnandflash#defineRdNFStat()(rNFSTAT)//readstatusfromnandflash#defineNFIsBusy()(!(rNFSTAT&1))//whethernandflashisbusy?#defineNFIsReady()(rNFSTAT&1)//whethernandflashisready?#defineREADCMD00//Read0modelco
10、mmand==Pageaddr0~127#defineREADCMD11//Read1modelcommand==Pageaddr128~511#defineREADCMD20x50//Read2modelcommand==Pageaddr512~527#defineERASECMD00x60//Blockerasecommand0#defineERASECMD10xd0//Blockerasecommand1#definePROGCMD00x80//pagewritecommand0#definePROGCMD10x10//pagewritecom
11、mand1#defineQUERYCMD0x70//querycommand#defineRdIDCMD0x
此文档下载收益归作者所有