Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Port of low level driver for FatFS

Low level driver for FatFS.

The driver is based on the ctrl access module of the specific MCU device.

Macros

#define SECTOR_SIZE_1024   2
 
#define SECTOR_SIZE_2048   4
 
#define SECTOR_SIZE_4096   8
 
#define SECTOR_SIZE_512   1
 Supported sector size. More...
 
#define SECTOR_SIZE_DEFAULT   512
 Default sector size. More...
 

Functions

DSTATUS disk_initialize (BYTE drv)
 Initialize a disk. More...
 
DRESULT disk_ioctl (BYTE drv, BYTE ctrl, void *buff)
 Miscellaneous functions, which support the following commands: More...
 
DRESULT disk_read (BYTE drv, BYTE *buff, DWORD sector, BYTE count)
 Read sector(s). More...
 
DSTATUS disk_status (BYTE drv)
 Return disk status. More...
 
DRESULT disk_write (BYTE drv, BYTE const *buff, DWORD sector, BYTE count)
 Write sector(s). More...
 

#define SECTOR_SIZE_1024   2

Referenced by disk_ioctl().

#define SECTOR_SIZE_2048   4

Referenced by disk_ioctl().

#define SECTOR_SIZE_4096   8

Referenced by disk_ioctl().

#define SECTOR_SIZE_512   1

Supported sector size.

These values are based on the LUN function: mem_sector_size().

Referenced by disk_ioctl().

#define SECTOR_SIZE_DEFAULT   512

Default sector size.

Referenced by disk_ioctl(), disk_read(), and disk_write().

DSTATUS disk_initialize ( BYTE  drv)

Initialize a disk.

Parameters
drvPhysical drive number (0..).
Returns
0 or disk status in combination of DSTATUS bits (STA_NOINIT, STA_PROTECT).

References CTRL_BUSY, CTRL_GOOD, LUN_ID_USB, Lun_usb_get_lun, MAX_LUN, mem_test_unit_ready(), mem_wr_protect(), STA_NOINIT, and STA_PROTECT.

Referenced by chk_mounted(), and f_mkfs().

DRESULT disk_ioctl ( BYTE  drv,
BYTE  ctrl,
void *  buff 
)

Miscellaneous functions, which support the following commands:

CTRL_SYNC 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. In read-only configuration, this command is not needed.

GET_SECTOR_COUNT Return total sectors on the drive into the DWORD variable pointed by buffer. This command is used only in f_mkfs function.

GET_BLOCK_SIZE Return erase block size of the memory array in unit of sector into the DWORD variable pointed by Buffer. When the erase block size is unknown or magnetic disk device, return 1. This command is used only in f_mkfs function.

GET_SECTOR_SIZE Return sector size of the memory array.

Parameters
drvPhysical drive number (0..).
ctrlControl code.
buffBuffer to send/receive control data.
Returns
RES_OK for success, otherwise DRESULT error code.

References CTRL_GOOD, CTRL_SYNC, GET_BLOCK_SIZE, GET_SECTOR_COUNT, GET_SECTOR_SIZE, mem_read_capacity(), mem_sector_size(), mem_test_unit_ready(), RES_ERROR, RES_NOTRDY, RES_OK, RES_PARERR, SECTOR_SIZE_1024, SECTOR_SIZE_2048, SECTOR_SIZE_4096, SECTOR_SIZE_512, and SECTOR_SIZE_DEFAULT.

Referenced by chk_mounted(), f_mkfs(), remove_chain(), and sync().

DRESULT disk_read ( BYTE  drv,
BYTE buff,
DWORD  sector,
BYTE  count 
)

Read sector(s).

Parameters
drvPhysical drive number (0..).
buffData buffer to store read data.
sectorSector address (LBA).
countNumber of sectors to read (1..255).
Returns
RES_OK for success, otherwise DRESULT error code.

References CTRL_GOOD, mem_read_capacity(), mem_sector_size(), memory_2_ram(), RES_ERROR, RES_OK, RES_PARERR, and SECTOR_SIZE_DEFAULT.

Referenced by check_fs(), chk_mounted(), f_lseek(), f_mkfs(), f_read(), f_write(), and move_window().

DSTATUS disk_status ( BYTE  drv)

Return disk status.

Parameters
drvPhysical drive number (0..).
Returns
0 or disk status in combination of DSTATUS bits (STA_NOINIT, STA_NODISK, STA_PROTECT).

References CTRL_GOOD, CTRL_NO_PRESENT, mem_test_unit_ready(), STA_NODISK, and STA_NOINIT.

Referenced by chk_mounted(), and validate().

DRESULT disk_write ( BYTE  drv,
BYTE const *  buff,
DWORD  sector,
BYTE  count 
)

Write sector(s).

The FatFs module will issue multiple sector transfer request (count > 1) to the disk I/O layer. The disk function should process the multiple sector transfer properly. Do not translate it into multiple sector transfers to the media, or the data read/write performance may be drastically decreased.

Parameters
drvPhysical drive number (0..).
buffData buffer to store read data.
sectorSector address (LBA).
countNumber of sectors to read (1..255).
Returns
RES_OK for success, otherwise DRESULT error code.

References CTRL_GOOD, mem_read_capacity(), mem_sector_size(), ram_2_memory(), RES_ERROR, RES_OK, RES_PARERR, and SECTOR_SIZE_DEFAULT.

Referenced by f_lseek(), f_mkfs(), f_read(), f_sync(), f_write(), move_window(), and sync().