免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1957 | 回复: 5
打印 上一主题 下一主题

flash write函数相关的一段代码,有很多不理解 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-27 11:20 |只看该作者 |倒序浏览
static int write_word (flash_info_t *info, ulong dest, ulong data)
{
        vu_long *addr = (vu_long*)(info->start[0]);
        ulong start,barf;
        int flag;


        /* Check if Flash is (sufficiently) erased */
        if ((*((vu_long *)dest) & data) != data) {
                return (2);
        }

        /* Disable interrupts which might cause a timeout here */
        flag = disable_interrupts();//关中断

     if(info->flash_id > FLASH_AMD_COMP) {
        /* AMD stuff */
        addr[0x0555] = 0x00AA00AA;//这些地址是做什么用的?为什么是常数?
        addr[0x02AA] = 0x00550055;
        addr[0x0555] = 0x00A000A0;
     } else {
        /* intel stuff */
        *addr = 0x00400040;
     }
        *((vu_long *)dest) = data;

        /* re-enable interrupts if necessary */
        if (flag)
                enable_interrupts();//开中断

        /* data polling for D7 */
        start = get_timer (0);

     if(info->flash_id > FLASH_AMD_COMP) {

        while ((*((vu_long *)dest) & 0x00800080) != (data & 0x00800080)) {//同问,为何是0x00800080
                if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
                        return (1);
                }
        }

     } else {

        while(!(addr[0] & 0x00800080)){          /* wait for error or finish */
                if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
                        return (1);
        }

        if( addr[0] & 0x003A003A) {        /* check for error */
                barf = addr[0] & 0x003A0000;
                if( barf ) {
                        barf >>=16;
                } else {
                        barf = addr[0] & 0x0000003A;
                }
                printf("\nFlash write error at address %lx\n",(unsigned long)dest);
                if(barf & 0x0002) printf("Block locked, not erased.\n");
                if(barf & 0x0010) printf("Programming error.\n");
                if(barf & 0x0008) printf("Vpp Low error.\n");
                return(2);
        }


     }

        return (0);

}
上面有很多十六进制的常数进行的与或操作,它们的作用是什么呢?

[ 本帖最后由 fuchuangbob 于 2009-10-27 11:21 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-10-27 12:25 |只看该作者
看地址~ 应该是NOR FLASH的接口操作~

看NOR FLASH的数据手册吧~

论坛徽章:
0
3 [报告]
发表于 2009-10-27 14:05 |只看该作者
这些应该是寄存器相关的指定的命令。
至于代表什么意义得看具体的芯片手册。

论坛徽章:
0
4 [报告]
发表于 2009-10-27 14:22 |只看该作者
谢谢两位了

论坛徽章:
5
5 [报告]
发表于 2009-10-28 09:00 |只看该作者
addr[0x0555] = 0x00AA00AA;//这些地址是做什么用的?为什么是常数?

对flash 设备的操作,是往特定的地址写入特定的命令序列。上面这个,是命令序列的一个命令。

(data & 0x00800080)) {//同问,为何是0x00800080

写命令执行时,读某些特定地址,来判断写命令是否完成。
没有完成时,上面的DATA是不断变化的。

按三楼所说,详读手册,就明白了。

论坛徽章:
0
6 [报告]
发表于 2009-10-28 17:49 |只看该作者
还是一头雾水呀,data sheet看得也不明白,图表不懂,可能英语也是不行
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP