在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > s3c2440對K9F2G08UOB Nand Flash的簡單操作函數(shù)

            s3c2440對K9F2G08UOB Nand Flash的簡單操作函數(shù)

            作者: 時間:2016-11-10 來源:網(wǎng)絡 收藏
            功能:先擦除一塊nand flash地址,然后往里面寫一字符串,最后再讀出來

            實現(xiàn),擦除、寫、讀功能。 芯片型號:K9F2G08UOB

            /****************************************************
            擦除nand flash 0x500000 地址
            主函數(shù):erase.c
            ****************************************************/
            #define NFCONF *(volatile unsigned long *)0x4E000000
            #define NFCONT *(volatile unsigned long *)0x4E000004
            #define NFCMMD *(volatile unsigned long *)0x4E000008
            #define NFADDR *(volatile unsigned long *)0x4E00000C
            #define NFDATA *(volatile unsigned char *)0x4E000010
            #define NFSTAT *(volatile unsigned long *)0x4E000020

            void (*printf)(char *, ...) = 0x33f9291C;
            void erase_nand(unsigned long addr);

            void _start(void)
            {
            //configure for nand flash controller
            NFCONF = (0x2 << 12) | (0x7 << 8) | (0x1 << 4);

            //control
            //NAND flash 開始工作
            NFCONT = 1;

            //設置擦除地址
            erase_nand(0x500000);

            }

            //------發(fā)送地址參照K9F2G08UOA數(shù)據(jù)手冊第9頁--------
            void send_addr(unsigned long addr)
            {
            NFADDR = (addr >> 11) & 0xff;
            NFADDR = (addr >> 19) & 0xff;
            NFADDR = (addr >> 27) & 0x1;
            }

            /*****************************************
            塊擦除
            對照K9F2G08UOA手冊第28頁
            ******************************************/
            void erase_nand(unsigned long addr)
            {
            unsigned int stat;

            //發(fā)送指令60h塊擦除設置指令
            NFCMMD = 0x60;

            //發(fā)送三次行地址
            send_addr(addr);

            //nandflash ready
            //發(fā)送d0擦除指令
            NFCMMD = 0xd0;

            //等待忙狀態(tài)
            while(!(NFSTAT & 0x1))
            ;


            // 發(fā)送70h讀狀態(tài)指令
            NFCMMD = 0x70;

            //讀取數(shù)據(jù)
            stat = NFDATA;

            //最后一位判斷成功與否
            if(stat & 0x1){
            printf("erase nand flash device errn");
            return ;
            }

            printf("erase nand flash device successn");
            }

            /****************************************************
            寫nand flash 0x500000 地址 一個字符串
            主函數(shù):write.c
            ****************************************************/
            #define NFCONF *(volatile unsigned long *)0x4E000000
            #define NFCONT *(volatile unsigned long *)0x4E000004
            #define NFCMMD *(volatile unsigned long *)0x4E000008
            #define NFADDR *(volatile unsigned long *)0x4E00000C
            #define NFDATA *(volatile unsigned char *)0x4E000010
            #define NFSTAT *(volatile unsigned long *)0x4E000020


            void (*printf)(char *, ...) = 0x33f9291C;
            void write_nand(char *buf, unsigned long addr, int size);
            char buf[11];

            void _start(void)
            {
            int i;

            //configure for nand flash controller
            NFCONF = (0x2 << 12) | (0x7 << 8) | (0x1 << 4);

            //control
            NFCONT = 1;

            //準備一個全寫a的數(shù)組
            for(i = 0; i < 11; i++)
            {
            buf= a;
            }

            //往0x500000寫字符串buf 11個字節(jié)
            write_nand(buf, 0x500000, 11);

            }

            //------發(fā)送地址參照K9F2G08UOA數(shù)據(jù)手冊第9頁--------
            void send_addr(unsigned long addr)
            {
            NFADDR = addr & 0xff;
            NFADDR = (addr >> 8) & 0x7;
            NFADDR = (addr >> 11) & 0xff;
            NFADDR = (addr >> 19) & 0xff;
            NFADDR = (addr >> 27) & 0x1;
            }

            /*****************************************
            寫數(shù)據(jù)
            對照K9F2G08UOA手冊第25頁
            ******************************************/
            void write_nand(char *buf, unsigned long addr, int size)
            {
            int i;
            unsigned int stat;

            //發(fā)80h串口數(shù)據(jù)輸入指令
            NFCMMD = 0x80;

            //發(fā)送兩次列地址,三次行地址
            send_addr(addr);

            //nandflash 數(shù)據(jù)準備
            for(i = 0; i < (size); i++)
            {
            NFDATA = buf;
            }

            //發(fā)送10h寫指令
            NFCMMD = 0x10;

            //等待忙狀態(tài)
            while(!(NFSTAT & 0x1))
            ;

            // 發(fā)送70h讀狀態(tài)指令
            NFCMMD = 0x70;
            stat = NFDATA;

            //最后一位判斷成功與否
            if(stat & 0x1){
            printf("write nand flash device errn");
            return ;
            }
            printf("write nand flash device successn");
            }

            /****************************************************
            讀nand flash 0x500000 地址 10個字節(jié)
            主函數(shù):read.c
            ****************************************************/

            #define NFCONF *(volatile unsigned long *)0x4E000000
            #define NFCONT *(volatile unsigned long *)0x4E000004
            #define NFCMMD *(volatile unsigned long *)0x4E000008
            #define NFADDR *(volatile unsigned long *)0x4E00000C
            #define NFDATA *(volatile unsigned char *)0x4E000010
            #define NFSTAT *(volatile unsigned long *)0x4E000020


            void (*printf)(char *, ...) = 0x33f9291C;
            void read_nand(char *buf, unsigned long addr, int size);

            void _start(void)
            {
            char buf[11];


            //configure for nand flash controller
            NFCONF = (0x2 << 12) | (0x7 << 8) | (0x1 << 4);

            //control
            NFCONT = 1;

            //往0x500000讀數(shù)據(jù)
            read_nand(buf, 0x500000, 10);
            buf[11] = 0;

            printf("read from nandflash: %sn", buf);
            }

            //------發(fā)送地址參照K9F2G08UOA數(shù)據(jù)手冊第9頁--------
            void send_addr(unsigned long addr)
            {
            NFADDR = addr & 0xff;
            NFADDR = (addr >> 8) & 0x7;
            NFADDR = (addr >> 11) & 0xff;
            NFADDR = (addr >> 19) & 0xff;
            NFADDR = (addr >> 27) & 0x1;
            }

            /*****************************************
            讀數(shù)據(jù)
            對照K9F2G08UOA手冊第23頁
            ******************************************/
            void read_nand(char *buf, unsigned long addr, int size)
            {
            int i;

            NFCMMD = 0x00;

            send_addr(addr);

            NFCMMD = 0x30;

            while(!(NFSTAT & 0x1 ))
            ;

            //nandflash ready
            for(i = 0; i < (size); i++)
            {
            buf= NFDATA;
            }

            }


            評論


            技術專區(qū)

            關閉