|
Functions | |
| __FATFS_STATUS | disk_initialize (u8 drv) |
| Initializes the disk drive. | |
| __FATFS_STATUS | disk_status (BYTE drv) |
| Returns the current disk status. | |
| __FATFS_RES | disk_ioctl (u8 drv, u8 ctrl, __PVOID buff) |
| Controls device specified features and miscellaneous functions other than disk read/write. | |
| __FATFS_RES | disk_read (u8 drv, u8 *buff, u32 sector, u8 count) |
| Reads sector(s) from the disk drive. | |
| __FATFS_RES | disk_write (BYTE drv, __CONST u8 *buff, u32 sector, u8 count) |
| Writes sector(s) to the disk. | |
| u32 | get_fattime (__VOID) |
| Gets current time. | |
| __BOOL | ff_cre_syncobj (u8 vol, _SYNC_t *sobj) |
| FatFS synchronization object creation. | |
| BOOL | ff_del_syncobj (_SYNC_t sobj) |
| FatFS deletes a synchronization object. | |
| BOOL | ff_req_grant (_SYNC_t sobj) |
| FatFS requests grant to access the volume. | |
| __VOID | ff_rel_grant (_SYNC_t sobj) |
| FatFS releases grant to access the volume. | |
Fat functions.
| __FATFS_STATUS disk_initialize | ( | u8 | drv | ) |
Initializes the disk drive.
Description from FatFs documentation:
The disk_initialize() function initializes a physical drive and put it ready to read/write. When the function succeeded, STA_NOINIT flag in the return value is cleared. Application program should not call this function, or FAT structure on the volume can be collapsed. To re-initialize the file system, use f_mount() function.This function is called on volume mount process in the FatFs module to manage the media change.
| drv | Specifies the physical drive number to initialize. |
Definition at line 809 of file fat.c.
{
/* Get the device */
__PDEVICE dv = __fatGetDevice(drv);
if (!dv) return RES_NOTRDY;
/* Call __deviceOpen. The device should return 0 on success.
* The device should be already registered with __deviceRegister().
*/
if (__deviceOpen(dv, 0) == 0) return RES_OK;
return RES_ERROR;
}

| __FATFS_STATUS disk_status | ( | BYTE | drv | ) |
Returns the current disk status.
Description from FatFs documentation:
The disk status is returned in combination of following flags. FatFs refers only STA_NOINIT and STA_PROTECTED.
| drv | Specifies the physical drive number to be confirmed. |
Definition at line 842 of file fat.c.
{
__FATFS_STATUS ret = 0;
__PDEVICE dv;
/* Get the device */
dv = __fatGetDevice(drv);
if (!dv) return ret;
switch (dv->dv_type)
{
/* SD/CF? */
case __DEV_CFSD:
if (__deviceIOCtl(dv, __IOCTL_WRITE_PROTECTED, 0, __NULL, 0))
{
ret |= STA_PROTECT;
}
if (!__deviceIOCtl(dv, __IOCTL_MEDIA_AVAILABLE, 0, __NULL, 0))
{
ret |= STA_NODISK;
}
break;
default:
/* TODO */
ret = STA_NOINIT;
break;
}
if (!dv->dv_initd || !dv->dv_opcnt)
{
ret |= STA_NOINIT;
}
return ret;
}

| __FATFS_RES disk_ioctl | ( | u8 | drv, |
| u8 | ctrl, | ||
| __PVOID | buff | ||
| ) |
Controls device specified features and miscellaneous functions other than disk read/write.
From FatFS documentation: The FatFs module uses only device independent commands described below. Any device dependent function is not used.
| drv | Specifies the drive number (0-9). |
| ctrl | Specifies the command code.
|
| buff | Pointer to the parameter buffer depends on the command code. When it is not used, specify a NULL pointer. |
Definition at line 907 of file fat.c.
{
__FATFS_RES res = RES_ERROR;
u8* ptr = (u8*) buff;
__PDEVICE dv;
/* Get the device */
dv = __fatGetDevice(drv);
if (!dv) return res;
/* SC/CF? */
if (dv->dv_type == __DEV_CFSD)
{
/* Power control code */
if (ctrl == CTRL_POWER)
{
switch (*ptr) {
/* Power off */
case 0:
if (__deviceIOCtl(dv, __IOCTL_GET_POWER_STATUS, 0, __NULL, 0)) {
__deviceIOCtl(dv, __IOCTL_SET_POWER_STATUS, 0, __NULL, 0);
}
res = RES_OK;
break;
/* Power on */
case 1:
__deviceIOCtl(dv, __IOCTL_SET_POWER_STATUS, 1, __NULL, 0);
res = RES_OK;
break;
/* Get power status */
case 2:
*(ptr+1) = (u8) __deviceIOCtl(dv, __IOCTL_GET_POWER_STATUS, 0, __NULL, 0);
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
} else
{
/* The next control codes need the device in ready state */
if (disk_status(drv) & STA_NOINIT) return RES_NOTRDY;
switch (ctrl)
{
/* Make sure that the disk drive has finished pending write process.
* When the disk I/O module has a write back cache, flush the dirty
* sector immediately. This command is not used in read-only configuration.
*/
case CTRL_SYNC:
/* TODO flush cache */
res = RES_OK;
break;
/* Returns number of available sectors on the drive into the DWORD variable
* pointed by Buffer. This command is used by only f_mkfs function to determine
* the volume size to be created.
*/
case GET_SECTOR_COUNT:
*(u32*) buff = __deviceIOCtl(dv, __IOCTL_GET_SECTOR_COUNT, 0, __NULL, 0);
res = RES_OK;
break;
/* Returns sector size of the drive into the WORD variable pointed by Buffer.
* This command is not used in fixed sector size configuration, _MAX_SS is 512.
*/
case GET_SECTOR_SIZE:
*(u16*) buff = 512;
res = RES_OK;
break;
/* Returns erase block size of the flash memory in unit of sector into the
* DWORD variable pointed by Buffer. The allowable value is 1 to 32768 in power
* of 2. Return 1 if the erase block size is unknown or disk devices. This command
* is used by only f_mkfs function and it attempts to align data area to the erase
* block boundary.
*/
case GET_BLOCK_SIZE:
*(u32*) buff = __deviceIOCtl(dv, __IOCTL_GET_BLOCK_SIZE, 0, __NULL, 0);
res = RES_OK;
break;
/* Get card type */
case MMC_GET_TYPE:
*ptr = (u8) __deviceIOCtl(dv, __IOCTL_GET_CARD_TYPE, 0, __NULL, 0);
res = RES_OK;
break;
case MMC_GET_CSD:
__deviceIOCtl(dv, __IOCTL_GET_CSD, 0, __NULL, 0);
res = RES_OK;
break;
case MMC_GET_CID:
__deviceIOCtl(dv, __IOCTL_GET_CID, 0, __NULL, 0);
res = RES_OK;
break;
case MMC_GET_OCR:
__deviceIOCtl(dv, __IOCTL_GET_OCR, 0, __NULL, 0);
res = RES_OK;
break;
case MMC_GET_SDSTAT:
__deviceIOCtl(dv, __IOCTL_GET_SDSTAT, 0, __NULL, 0);
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
}
}
return res;
}

| __FATFS_RES disk_read | ( | u8 | drv, |
| u8 * | buff, | ||
| u32 | sector, | ||
| u8 | count | ||
| ) |
Reads sector(s) from the disk drive.
| drv | Specifies the physical drive number. |
| buff | Pointer to the byte array to store the read data. The buffer size of number of bytes to be read, sector size * sector count, is required. Note that the specified memory address is not that always aligned to word boundary. If the hardware does not support misaligned data transfer, it must be solved in this function. |
| sector | Specifies the start sector number in logical block address (LBA). |
| count | Specifies number of sectors to read. The value can be 1 to 128. Generally, a multiple sector transfer request must not be split into single sector transactions to the device, or you may not get good read performance (TODO). |
Definition at line 1052 of file fat.c.
{
__PDEVICE dv;
/* Get the device */
dv = __fatGetDevice(drv);
if (!dv) return RES_PARERR;
/* Set the sector to read */
if (dv->dv_type == __DEV_CFSD) __deviceIOCtl(dv, __IOCTL_SET_SECTOR, sector, __NULL, 0);
if (__deviceRead(dv, buff, count) == 0) return RES_OK;
return RES_ERROR;
}

| __FATFS_RES disk_write | ( | BYTE | drv, |
| __CONST u8 * | buff, | ||
| u32 | sector, | ||
| u8 | count | ||
| ) |
Writes sector(s) to the disk.
| drv | Specifies the physical drive number. |
| buff | Pointer to the byte array to be written. Note that the specified memory address is not that always aligned to word boundary. If the hardware does not support misaligned data transfer, it must be solved in this function. |
| sector | Specifies the start sector number in logical block address (LBA). |
| count | Specifies the number of sectors to write. The value can be 1 to 128. Generally, a multiple sector transfer request must not be split into single sector transactions to the device, or you will never get good write performance (TODO). |
Definition at line 1093 of file fat.c.
{
__PDEVICE dv;
/* Get the device */
dv = __fatGetDevice(drv);
if (!dv) return RES_PARERR;
if (dv->dv_type == __DEV_CFSD)
{
if (__deviceIOCtl(dv, __IOCTL_WRITE_PROTECTED, 0, __NULL, 0))
{
return RES_WRPRT;
}
}
/* Set the sector to write */
if (dv->dv_type == __DEV_CFSD)
{
__deviceIOCtl(dv, __IOCTL_SET_SECTOR, sector, __NULL, 0);
}
/* Write */
if (__deviceWrite(dv, buff, count) == 0) return RES_OK;
return RES_ERROR;
}

| u32 get_fattime | ( | __VOID | ) |
Gets current time.
The get_fattime function must return any valid time even if the system does not support a real time clock. If a zero is returned, the file will not have a valid time. This function is not required in read only configuration.
Definition at line 1143 of file fat.c.
{
#if __CONFIG_COMPILE_RTC
__DATETIME dt;
__rtcGetDateTime(&dt);
return ((dt.year - 1980) << 25 |
dt.month << 21 |
dt.day << 16 |
dt.hour << 11 |
dt.min << 5 |
dt.sec);
#else
/* fixed date-time */
return (30 << 25 | 12 << 21 | 30 << 16 | 19 << 11 | 2 << 5 | 50);
#endif /* __CONFIG_COMPILE_RTC */
}

| __BOOL ff_cre_syncobj | ( | u8 | vol, |
| _SYNC_t * | sobj | ||
| ) |
FatFS synchronization object creation.
From FatFS description: this function is called in f_mount function to create a new synchronization object, such as semaphore and mutex. When a FALSE is returned, the f_mount function fails with FR_INT_ERR.
| vol | Corresponding logical drive being processed. |
| sobj | Pointer to return the created sync object. |
Definition at line 1181 of file fat.c.
{
__BOOL ret = __FALSE;
*sobj = __lockCreate();
ret = (*sobj != __NULL) ? __TRUE : __FALSE;
return ret;
}

| BOOL ff_del_syncobj | ( | _SYNC_t | sobj | ) |
FatFS deletes a synchronization object.
From FatFS description: This function is called in f_mount function to delete a synchronization object that created with ff_cre_syncobj function. When a FALSE is returned, the f_mount function fails with FR_INT_ERR.
| sobj | Sync object tied to the logical drive to be deleted. |
Definition at line 1204 of file fat.c.
{
__lockDestroy(sobj);
return __TRUE;
}

| BOOL ff_req_grant | ( | _SYNC_t | sobj | ) |
FatFS requests grant to access the volume.
From FatFS description: This function is called on entering file functions to lock the volume. When a FALSE is returned, the file function fails with FR_TIMEOUT.
| sobj | Sync object to wait. |
Definition at line 1221 of file fat.c.

| __VOID ff_rel_grant | ( | _SYNC_t | sobj | ) |
FatFS releases grant to access the volume.
From FatFS description: This function is called on leaving file functions to unlock the volume.
| sobj | Sync object to be signaled. |
Definition at line 1239 of file fat.c.
{
__lockRelease(sobj);
}
