欢迎来到天天文库
浏览记录
ID:18477057
大小:85.00 KB
页数:8页
时间:2018-09-18
《nandflash的规范程序代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、nandflash裸机驱动程序的分析nandflash在嵌入式设备中广泛的应用,学些nandflash的重要性不言而喻,这里分析一段实例代码,不管是编码规范还是程序的结构都是很有价值的。下边是K9F1208U0M的实例代码。首先看nand.h文件:#ifndef__NAND_Flash__#define__NAND_Flash__externvoidInitNandCfg(void);//初始化K9F1208UOMNANDflash配置externunsignedintReadChipId(void);//读取N
2、ANDFlash的ID号externunsignedshortReadStatus(void);//读取NANDFlash的状态externunsignedintEraseBlock(unsignedintaddr);//NANDFlash块擦除externvoidReadPage(unsignedintaddr,unsignedchar*buf);//K9F1208U0Mnandflash的页数据读externvoidWritePage(unsignedintaddr,unsignedchar*buf);//K
3、9F1208U0Mnandflash的页数据写externvoidMarkBadBlk(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、=
7、0x1000)//bit12=1initializeECC#defineNoEcc()(rNFCONF&=~0x1000)//bit12=0initializeECC#defineNFChipEn()(rNFCONF&=~0x800)//bit11=0NANDflashnFCE=L(active)#defineNFChipDs()(rNFCONF
8、=0x800)//bit11=1NANDflashnFCE=H(inactive)#defineWrNFCmd(cmd)(rNFCMD=(cmd))//writecom
9、mondtonandflash#defineWrNFAddr(addr)(rNFADDR=(addr))//writeaddresstonandflash#defineWrNFDat(dat)(rNFDATA=(dat))//writedatatonandflash#defineRdNFDat()(rNFDATA)//readdatafromnandflash#defineRdNFStat()(rNFSTAT)//readstatusfromnandflash#defineNFIsBusy()(!(rNFSTAT
10、&1))//whethernandflashisbusy?#defineNFIsReady()(rNFSTAT&1)//whethernandflashisready?#defineREADCMD00//Read0modelcommand==Pageaddr0~127#defineREADCMD11//Read1modelcommand==Pageaddr128~511#defineREADCMD20x50//Read2modelcommand==Pageaddr512~527#defineERASECMD00x
11、60//Blockerasecommand0#defineERASECMD10xd0//Blockerasecommand1#definePROGCMD00x80//pagewritecommand0#definePROGCMD10x10//pagewritecommand1#defineQUERYCMD0x70//querycommand#defineRdIDCMD0x
此文档下载收益归作者所有