پاسخ : [آموزش] نحوه استفاده از کتابخانه pff.h
سلام دوستان از کدوم توابع کتابخانه pff باید برای بدست اوردن حجم فایل استفاده کرد؟؟
سلام دوستان از کدوم توابع کتابخانه pff باید برای بدست اوردن حجم فایل استفاده کرد؟؟
RESULT disk_readp
(
unsigned char *buff, /* Pointer to the read buffer (NULL:Read bytes are forwarded to the stream) */
unsigned long lba, /* Sector number (LBA) */
unsigned short ofs, /* Byte offset to read from (0..511) */
unsigned short cnt /* Number of bytes to read (ofs + cnt mus be <= 512) */
)
{
RESULT res;
unsigned char rc;
unsigned short bc;
if (!(CardType & CT_BLOCK)) lba *= 512; /* Convert to byte address if needed */
res = RES_ERROR;
if (send_cmd(CMD17, lba) == 0) /* READ_SINGLE_BLOCK */
{
bc = 30000;
do /* Wait for data packet in timeout of 100ms */
{
rc = rcv_spi();
} while (rc == 0xFF && --bc);
if (rc == 0xFE) /* A data packet arrived */
{
bc = 514 - ofs - cnt;
/* Skip leading bytes */
if (ofs)
{
do rcv_spi(); while (--ofs);
}
/* Receive a part of the sector */
if (buff) /* Store data to the memory */
{
do
*buff++ = rcv_spi();
while (--cnt);
}
do rcv_spi(); while (--bc);
res = RES_OK;
}
}
release_spi();
return res;
}
[FONT=Yekan]RESULT pf_read ([/FONT] void *buff, /* Pointer to the read buffer (NULL:Forward data to the stream)*/
unsigned short btr, /* Number of bytes to read */
unsigned short* br /* Pointer to number of bytes read */
)
{
RESULT dr;
CLUST clst;
unsigned long sect, remain;
unsigned char *rbuff = buff;
unsigned short rcnt;
FATFS *fs = FatFs;
*br = 0;
if (!fs) return FR_NOT_ENABLED; /* Check file system */
if (!(fs->flag & FA_OPENED)) /* Check if opened */
return FR_NOT_OPENED;
remain = fs->fsize - fs->fptr;
if (btr > remain) btr = (unsigned short)remain; /* Truncate btr by remaining bytes */
while (btr) { /* Repeat until all data transferred */
if ((fs->fptr % 512) == 0) { /* On the sector boundary? */
if ((fs->fptr / 512 % fs->csize) == 0) { /* On the cluster boundary? */
clst = (fs->fptr == 0) ? /* On the top of the file? */
fs->org_clust : get_fat(fs->curr_clust);
if (clst <= 1) goto fr_abort;
fs->curr_clust = clst; /* Update current cluster */
fs->csect = 0; /* Reset sector offset in the cluster */
}
sect = clust2sect(fs->curr_clust); /* Get current sector */
if (!sect) goto fr_abort;
fs->dsect = sect + fs->csect++;
}
rcnt = 512 - ((unsigned short)fs->fptr % 512); /* Get partial sector data from sector buffer */
if (rcnt > btr) rcnt = btr;
dr = disk_readp(!buff ? 0 : rbuff, fs->dsect, (unsigned short)(fs->fptr % 512), rcnt);
if (dr) goto fr_abort;
fs->fptr += rcnt; rbuff += rcnt; /* Update pointers and counters */
btr -= rcnt; *br += rcnt;
}
return FR_OK;
fr_abort:
fs->flag = 0;
return FR_DISK_ERR;
}
RESULT pf_open (
const char *path /* Pointer to the file name */
)
{
RESULT res;
DIR dj;
unsigned char sp[12], dir[32];
FATFS *fs = FatFs;
if (!fs) /* Check file system */
return FR_NOT_ENABLED;
fs->flag = 0;
fs->buf = dir;
dj.fn = sp;
res = follow_path(&dj, path); /* Follow the file path */
if (res != FR_OK) return res; /* Follow failed */
if (!dir[0] || (dir[DIR_Attr] & AM_DIR)) /* It is a directory */
return FR_NO_FILE;
fs->org_clust = /* File start cluster */
#if _FS_FAT32
((unsigned long)LD_WORD(dir+DIR_FstClusHI) << 16) |
#endif
LD_WORD(dir+DIR_FstClusLO);
fs->fsize = LD_DWORD(dir+DIR_FileSize); /* File size */
fs->fptr = 0; /* File pointer */
fs->flag = FA_OPENED;
return FR_OK;
}
دیدگاه