主题 : nand flash 复制链接 | 浏览器收藏 | 打印
Are you mad at me?
级别: 新手上路
UID: 24333
精华: 0
发帖: 11
金钱: 55 两
威望: 11 点
综合积分: 22 分
注册时间: 2010-07-06
最后登录: 2010-07-20
楼主  发表于: 2010-07-15 15:11

 nand flash

大家好,关于板子上自带的代码,有几个问题搞不明白,还请大家帮的看看
代码如下
void CopyProgramFromNand(void)
{
  const  int    bLargeBlock  = Nand_Init();        
  const  unsigned  StartSector      = 0;                
  const  unsigned  StopSector              = 5120;            
  const  unsigned   byte_sector_shift   = 9;
  const  unsigned   sector_block_shift    = bLargeBlock ? 8 : 5;       //5
  unsigned     char          *RAM     = (unsigned char *)0x30000000;
  unsigned         Sector, GoodSector;
    
       for (Sector = StartSector, GoodSector = Sector; Sector < StopSector; Sector ++, GoodSector++)
       {    // 从第一块开始
                     if (GoodSector & ( (1 << sector_block_shift) - 1 ) == 0)
                     {
                                       for (;;)
                                       {
                                                       if (!Nand_IsBadBlock(GoodSector >> sector_block_shift, bLargeBlock))
                                                          {        //如果不是坏块就跳出循环
                                                                      break;
                                                          }
                                                          // try next block 下一个
                                                          GoodSector += (1 << sector_block_shift);
                                       }
                       }
                       Nand_ReadSector(GoodSector, RAM + (Sector << byte_sector_shift ), bLargeBlock);
        }
}
我的问题是,到底从NAND上拷贝了多少到SARAM里?
这个是拷贝到0x30000000地址上的吗?如果是这样的话,下面的代码又怎么理解呢?
RAM + (Sector << byte_sector_shift ).
就这些了,麻烦高手帮我瞅瞅,多谢了。
[ 此帖被朱伟在2010-07-15 16:23重新编辑 ]
Are you mad at me?
级别: 新手上路
UID: 24333
精华: 0
发帖: 11
金钱: 55 两
威望: 11 点
综合积分: 22 分
注册时间: 2010-07-06
最后登录: 2010-07-20
1楼  发表于: 2010-07-15 16:40
高手哪去了啊,自己给自己顶一下。
级别: 新手上路
UID: 21714
精华: 0
发帖: 42
金钱: 210 两
威望: 42 点
综合积分: 84 分
注册时间: 2010-05-20
最后登录: 2015-04-12
2楼  发表于: 2011-03-30 16:01
到底从NAND上拷贝了多少到SARAM里?
应该是拷贝了5120x512字节到RAM中(因为Nand_ReadSector()函数每次读512字节)


RAM + (Sector << byte_sector_shift ).怎么理解呢?
Sector在for循环中是一个索引,在for循环中加1.
Sector << byte_sector_shift 等于Sector*512
为什么要乘512,因为Nand_ReadSector()函数每次是读512字节的.
这样就可以连续的把数据读到RAM了.