NAND Flash內(nèi)存設(shè)備的讀寫控制設(shè)計(jì)
圖3 讀頁流程
圖4 讀頁時(shí)序
2.2.2 讀頁主要函數(shù)
NAND Flash讀頁的主要函數(shù)有nand_read、nand_do_read_ops、nand_command_lp、nand_read_page_hwecc、read_buf。MTD上層會(huì)調(diào)用struct mtd_info中的讀page函數(shù),即nand_read函數(shù),然后調(diào)用nand_do_read_ops,接著會(huì)調(diào)用struct nand_chip中的cmdfunc函數(shù)。這個(gè)cmdfunc函數(shù)與具體的NAND controller相關(guān),它的作用是使NAND controller向NAND芯片發(fā)出讀命令,NAND芯片收到命令后,就會(huì)做好準(zhǔn)備等待NAND controller下一步的讀取。接著nand_read函數(shù)又會(huì)調(diào)用struct nand_ecc_ctrl中的read_page函數(shù),而read_page函數(shù)又會(huì)調(diào)用struct nand_chip中read_buf函數(shù),從而真正把NAND芯片中的數(shù)據(jù)讀取到buffer中。read_buf函數(shù)返回后,read_page函數(shù)就會(huì)對(duì)buffer中的數(shù)據(jù)做一些處理,比如ECC校驗(yàn)。讀頁主要函數(shù)代碼如下:
static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) {
……
while(1) {
……
/*先發(fā)送對(duì)應(yīng)的讀頁(read page)的命令*/
chip博cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
……
/*發(fā)送完命令,接著去調(diào)用read_page函數(shù)讀取對(duì)應(yīng)的數(shù)據(jù)*/
ret=chip博ecc.read_page(mtd, chip, bufpoi);
buf+=bytes;
……
readlen-=bytes;
if(!readlen)
break;
col=0;/*頁內(nèi)地址對(duì)齊*/
ealpage++;/*頁號(hào)加1*/
page=realpage chip博pagemask;
……
}
……
}
2.3 NAND Flash的寫頁流程
2.3.1 寫頁時(shí)序
圖5 寫頁時(shí)序
從圖5寫頁時(shí)序可以看到,如果要實(shí)現(xiàn)寫一個(gè)頁的數(shù)據(jù),就要發(fā)送Page program的命令,而且是分兩個(gè)周期,即分兩次發(fā)送對(duì)應(yīng)的命令。第一次是80h,第二次是10h,而兩次命令中間,需要發(fā)送對(duì)應(yīng)的要寫的頁的地址和數(shù)據(jù)。第3個(gè)周期是發(fā)送讀狀態(tài)寄存器命令70h, 如果I/O口為低電平,表示數(shù)據(jù)寫入成功,否則失敗。寫頁流程如圖6所示。
圖6 寫頁流程
2.3.2 寫頁主要函數(shù)
以寫NAND Flash芯片為例,其寫數(shù)據(jù)的工作過程:首先,MTD上層會(huì)調(diào)用struct mtd_info中的寫page函數(shù),即nand_write函數(shù),然后調(diào)用nand_do_read_ops。接著函數(shù)會(huì)調(diào)用struct nand_chip中cmdfunc函數(shù),這個(gè)cmdfunc函數(shù)與具體的NAND controller相關(guān),它的作用是使NAND controller向NAND芯片發(fā)出寫命令,NAND芯片收到命令后,就會(huì)做好準(zhǔn)備等待NAND controller下一步的讀取。接著nand_write函數(shù)又會(huì)調(diào)用struct nand_ecc_ctrl中的write_page函數(shù),而write_page函數(shù)又會(huì)調(diào)用struct nand_chip中write_buf函數(shù),從而真正把數(shù)據(jù)寫到NAND Flash芯片中。
MTD讀取數(shù)據(jù)的入口是nand_write,然后調(diào)用nand_do_write_ops,此函數(shù)主體代碼如下:
static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops){
……
if (nand_check_wp(mtd))/*檢測(cè),寫保護(hù)*/
return -EIO;
……
while(1){
……
ret=chip博write_page(mtd, chip, wbuf, page, cached,(ops博mode==MTD_OOB_RAW));/*寫頁數(shù)據(jù)*/
writelen-=bytes;
if (!writelen)
break;
column=0; /*頁內(nèi)地址對(duì)齊*/
buf+=bytes;
realpage++; /*頁號(hào)加1*/
page=realpage chip博pagemask;
……
}
……
}本文引用地址:http://butianyuan.cn/article/148135.htm
評(píng)論