新手入门
- 积分
- 15
- 金钱
- 15
- 注册时间
- 2019-9-11
- 在线时间
- 6 小时
|
1金钱
求助各位大佬。!!!
Petit Fatfs 轻量级SD卡中的pf_lseek有段这个函数。
现在在SD卡中创建了个100MB的文件,SD卡格式化为FAT32的
我想从末尾开始写fs->fptr大概要在0x06300000->0x06400000之间
然后我pf_lseek(0x06350000)
调试发现ofs就是我写的0x6350000。
但是bcs只有512个字节也就是0x200
也就是说执行这一遍函数ofs每次才判断512个字节,然后get_fat函数里面又要用到SPI读取的函数,导致pf_lseek越大这段执行就越久。
尝试过直接删除该段函数, 让fs->fptr = ofs;但是fs->curr_clust 又应该等于多少。
有大佬帮忙看看怎么优化比较好吗?
while (ofs > bcs) { /* Cluster following loop */
clst = get_fat(clst); /* Follow cluster chain */
if (clst <= 1 || clst >= fs->n_fatent) ABORT(FR_DISK_ERR);
fs->curr_clust = clst;
fs->fptr += bcs;
ofs -= bcs;
}
FRESULT pf_lseek (
DWORD ofs /* File pointer from top of file */
)
{
CLUST clst;
DWORD bcs, sect, ifptr;
FATFS *fs = FatFs;
if (!fs) return FR_NOT_ENABLED; /* Check file system */
if (!(fs->flag & FA_OPENED)) return FR_NOT_OPENED; /* Check if opened */
if (ofs > fs->fsize) ofs = fs->fsize; /* Clip offset with the file size */
ifptr = fs->fptr;
fs->fptr = 0;
if (ofs > 0) {
bcs = (DWORD)fs->csize * 512; /* Cluster size (byte) */
if (ifptr > 0 &&
(ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */
fs->fptr = (ifptr - 1) & ~(bcs - 1); /* start from the current cluster */
ofs -= fs->fptr;
clst = fs->curr_clust;
} else { /* When seek to back cluster, */
clst = fs->org_clust; /* start from the first cluster */
fs->curr_clust = clst;
}
while (ofs > bcs) { /* Cluster following loop */
clst = get_fat(clst); /* Follow cluster chain */
if (clst <= 1 || clst >= fs->n_fatent) ABORT(FR_DISK_ERR);
fs->curr_clust = clst;
fs->fptr += bcs;
ofs -= bcs;
}
fs->fptr += ofs;
sect = clust2sect(clst); /* Current sector */
if (!sect) ABORT(FR_DISK_ERR);
fs->dsect = sect + (fs->fptr / 512 & (fs->csize - 1));
}
return FR_OK;
}
#endif
|
|