双口ram读数据的速度太慢
时间:10-02
整理:3721RD
点击:
系统结构与功能:
lpc3131外接8k*8双口ram与8G Flash,从双口ram读取数据(来自FPGA),并存至Flash中。
问题:
丢数据,系统速度远低于ram的读速与Flash的写速度。
双口ram读数据直接采用指针,如下:
for(i=0;i<tmp;i++)
{
nandflash.databuf[nandflash.ptr_buf] = *(volatile UNS_8 *)(EXT_SRAM0_0_BASE + ram.ptr);
nandflash.ptr_buf++;
ram.ptr++;
}
Flash按页写的程序如下:
INT_32 nand_page_write(INT_32 devid,
void * buffer,
INT_32 bank_num,
INT_32 block_num,
INT_32 page_num)
{
NAND_DRV_T *nanddrv = (NAND_DRV_T *) devid;
NAND_FLASH_CTRL_REGS_T *nandreg = nanddrv->regptr;
UNS_32 * pData;
UNS_32 * pnfbuf[2];
UNS_32 i,j,tmp;
UNS_8 addr1 = 0;
UNS_8 addr2 = 0;
UNS_8 addr3 = (UNS_8)(((block_num<<6)&0x0C0)+(page_num&0x03F));
UNS_8 addr4 = (UNS_8)((block_num>>2)&0x0FF);
UNS_8 addr5 = (UNS_8)((block_num>>10)&0x07);
pnfbuf[0] = (UNS_32 *) NANDFLASH_CTRL_S0_BASE;
pnfbuf[1] = (UNS_32 *) (NANDFLASH_CTRL_S0_BASE + 0x400);
nandreg->set_ce = NAND_SETCE_WP | NAND_SETCE_CV(bank_num);
nandreg->set_cmd = NAND_CMD_SDIN;
nandreg->set_addr = addr1;
nandreg->set_addr = addr2;
nandreg->set_addr = addr3;
nandreg->set_addr = addr4;
nandreg->set_addr = addr5;
for(j=0;j<8;j++)
{
pData = (UNS_32 *)((UNS_8 *)buffer + j*512);
tmp = j&0x01;
for(i=0;i<128;i++)
{
*(pnfbuf[tmp]+i) = *(pData + i);
}
if(j>0)
{
while(!(nand_ioctl(devid, NAND_IRQ_STATUS, 3-tmp)));
while((nand_ioctl(devid, NAND_IRQ_STATUS, 3-tmp)))nandreg->irq_status_raw = 0xFFFFFFFF;
}
nandreg->control_flow = NAND_CTRL_RD_RAM(4+tmp);
}
while(!(nand_ioctl(devid, NAND_IRQ_STATUS, 3)));
while((nand_ioctl(devid, NAND_IRQ_STATUS, 3)))nandreg->irq_status_raw = 0xFFFFFFFF;
nandreg->set_cmd = NAND_CMD_PAGEPROG;
while((nand_ioctl(devid, NAND_RB_STATUS, bank_num)));
while(!(nand_ioctl(devid, NAND_RB_STATUS, bank_num)));
return 0;
}
为什么速度远低于芯片说明文档中的读写速度?
求指点,非常感谢!
lpc3131外接8k*8双口ram与8G Flash,从双口ram读取数据(来自FPGA),并存至Flash中。
问题:
丢数据,系统速度远低于ram的读速与Flash的写速度。
双口ram读数据直接采用指针,如下:
for(i=0;i<tmp;i++)
{
nandflash.databuf[nandflash.ptr_buf] = *(volatile UNS_8 *)(EXT_SRAM0_0_BASE + ram.ptr);
nandflash.ptr_buf++;
ram.ptr++;
}
Flash按页写的程序如下:
INT_32 nand_page_write(INT_32 devid,
void * buffer,
INT_32 bank_num,
INT_32 block_num,
INT_32 page_num)
{
NAND_DRV_T *nanddrv = (NAND_DRV_T *) devid;
NAND_FLASH_CTRL_REGS_T *nandreg = nanddrv->regptr;
UNS_32 * pData;
UNS_32 * pnfbuf[2];
UNS_32 i,j,tmp;
UNS_8 addr1 = 0;
UNS_8 addr2 = 0;
UNS_8 addr3 = (UNS_8)(((block_num<<6)&0x0C0)+(page_num&0x03F));
UNS_8 addr4 = (UNS_8)((block_num>>2)&0x0FF);
UNS_8 addr5 = (UNS_8)((block_num>>10)&0x07);
pnfbuf[0] = (UNS_32 *) NANDFLASH_CTRL_S0_BASE;
pnfbuf[1] = (UNS_32 *) (NANDFLASH_CTRL_S0_BASE + 0x400);
nandreg->set_ce = NAND_SETCE_WP | NAND_SETCE_CV(bank_num);
nandreg->set_cmd = NAND_CMD_SDIN;
nandreg->set_addr = addr1;
nandreg->set_addr = addr2;
nandreg->set_addr = addr3;
nandreg->set_addr = addr4;
nandreg->set_addr = addr5;
for(j=0;j<8;j++)
{
pData = (UNS_32 *)((UNS_8 *)buffer + j*512);
tmp = j&0x01;
for(i=0;i<128;i++)
{
*(pnfbuf[tmp]+i) = *(pData + i);
}
if(j>0)
{
while(!(nand_ioctl(devid, NAND_IRQ_STATUS, 3-tmp)));
while((nand_ioctl(devid, NAND_IRQ_STATUS, 3-tmp)))nandreg->irq_status_raw = 0xFFFFFFFF;
}
nandreg->control_flow = NAND_CTRL_RD_RAM(4+tmp);
}
while(!(nand_ioctl(devid, NAND_IRQ_STATUS, 3)));
while((nand_ioctl(devid, NAND_IRQ_STATUS, 3)))nandreg->irq_status_raw = 0xFFFFFFFF;
nandreg->set_cmd = NAND_CMD_PAGEPROG;
while((nand_ioctl(devid, NAND_RB_STATUS, bank_num)));
while(!(nand_ioctl(devid, NAND_RB_STATUS, bank_num)));
return 0;
}
为什么速度远低于芯片说明文档中的读写速度?
求指点,非常感谢!
RAM的读写速度很快 只是读写FLASH会很慢一些
你说的‘远低于’包不包括FLASH写页的过程?
如果包括建议合理安排写页和读取的顺序,比如可以在写页后先不马上判断是否写入完成,而是先读空双口RAM,然后再去判断,这样,最低的处理速度基本就只取决于FLASH的速度;还是不行的话就只有中断方式读RAM,或者中断方式结束写页判断;还是不行,就需要考虑换速度快的flash,或增加缓冲区大小了;
还有,时间比较紧迫的应用里面,尽量使用临时变量作为增量指针,不要使用结构体里面的元素,因为使用结构体里面的元素作为指针的话,会有一个对该元素寻址的计算过程,会花CPU时间,如果编译器优化较差的话,对一个元素的增量、使用、保存增量后的值,均会重复这个寻址的计算过程,成倍增加CPU开销