管理员
  
- 积分
- 165602
- 金钱
- 165602
- 注册时间
- 2010-12-1
- 在线时间
- 2121 小时
|
发表于 2013-5-6 17:57:32
|
显示全部楼层
//fname:文件名
//strx:要写入的字符串
//repeat:写入的次数(文件大小=strx长度*repeat次数)
void testwrite(u8 *fname,u8* strx,u32 repeat)
{
FIL* f_test;
u8 *databuf; //数组
u8 strxlen=strlen((const char*)strx); //字符串长度
u32 bufrpt=2048/strxlen; //databuf每次能存储strx的条数
u32 rpcnt=0;
u8 *ptr;
u8 res,i;
f_test=(FIL*)mymalloc(SRAMIN,sizeof(FIL));
databuf=mymalloc(SRAMIN,2048);
if(f_test==NULL||databuf==NULL)
{
myfree(SRAMIN,f_test);
myfree(SRAMIN,databuf);
return ;
}
res=f_open(f_test,(const TCHAR*)fname,FA_CREATE_NEW|FA_WRITE);//创建文件
if(res==FR_OK)//创建成功
{
ptr=databuf;
for(rpcnt=0;rpcnt<repeat;)
{
for(i=0;i<bufrpt;)//将databuf尽量填满
{
strncpy((char*)ptr,(char*)strx,strxlen);
ptr+=strxlen;
rpcnt++;i++;
if(rpcnt>=repeat)break;
}
printf("\r\nreptx:%02d strxlen:%d",rpcnt,strxlen); //打印当前已写数目
res=f_write(f_test,databuf,(u32)i*strxlen,&bw); //一次写入i*strxlen个字节
if(res||bw!=(bufrpt*strxlen))break; //写入出错/结束
ptr=databuf;
}
f_close(f_test);
printf("\r\nfile size:%d\r\n",rpcnt*strxlen);//总文件大小
}
myfree(SRAMIN,f_test);
myfree(SRAMIN,databuf);
}
这是我们sdio的一个测试代码,最大一次写入2048个字节。 |
|