xilffs
Vitis Drivers API Documentation
diskio.c File Reference

Overview

This file is the glue layer between file system and driver.

    Description related to SD driver:
    Process to use file system with SD
    Select xilffs in SDK when creating a BSP
    In SDK, set "fs_interface" to 1 to select SD interface.
    This glue layer can currently be used only with one
    SD controller enabled.
    In order to use eMMC, in SDK set "Enable MMC" to 1. If not,
    SD support is enabled by default.

    Description:
    This glue layer initializes the host controller and SD card
    in disk_initialize. If SD card supports it, 4-bit mode and
    high speed mode will be enabled.
    The default block size is 512 bytes.
    disk_read and disk_write functions are used to read and
    write files using ADMA2 in polled mode.
    The file system can be used to read from and write to an
    SD card that is already formatted as FATFS.
MODIFICATION HISTORY:
Ver     Who     Date            Changes
----- ---- -------- -------------------------------------------------------
1.00a hk   10/17/13 First release
2.0   hk   02/12/14 Corrected status check in disk initialize. CR# 772072.
2.1   hk   04/16/14 Move check for ExtCSD high speed bit set inside if
                    condition for high speed support.
                    Include xil_types.h irrespective of xsdps.h. CR# 797086.
2.2   hk   07/28/14 Make changes to enable use of data cache.
3.0     sk       12/04/14 Added support for micro SD without
                                          WP/CD. CR# 810655.
                                  Make changes for prototypes of disk_read and
                                  disk_write according to latest version.
                 12/15/14 Modified the code according to MISRAC 2012 Compliant.
                                  Updated the FatFs to R0.10b
                                  Removed alignment for local buffers as CacheInvalidate
                                  will take care of it.
        sg   03/03/15 Added card detection check logic
             04/28/15 Card detection only in case of card detection signal
3.1   sk   06/04/15 Added support for SD1.
3.2   sk   11/24/15 Considered the slot type before checking the CD/WP pins.
3.3   sk   04/01/15 Added one second delay for checking CD pin.
3.4   sk   06/09/16 Added support for mkfs.
3.8   mj   07/31/17 Added support for RAM based FATfs.
      mn   12/04/17 Resolve errors in XilFFS for ARMCC compiler
3.9   mn   04/18/18 Resolve build warnings for xilffs library
      mn   07/06/18 Fix Cppcheck and Doxygen warnings
4.2   mn   08/16/19 Initialize Status variables with failure values
      mn   09/25/19 Check if the SD is powered on or not in disk_status()
4.3   mn   02/24/20 Remove unused macro defines
      mn   04/08/20 Set IsReady to '0' before calling XSdPs_CfgInitialize
4.5   sk   03/31/21 Maintain discrete global variables for each controller.
4.6   sk   07/20/21 Fixed compilation warning in RAM interface.
4.8   sk   05/05/22 Replace standard lib functions with Xilinx functions.
5.1   ro   06/12/23 Added support for system device-tree flow.
5.2   ap   12/05/23 Add SDT check to fix bug in disk_initialize.
      ap   01/11/24 Fix Doxygen warnings.
      sk   07/11/24 Add UFS interface support.
Note

Macros

#define XSDPS_NUM_INSTANCES   2
 Number of SD instances. More...
 
#define XUFSPSXC_START_INDEX   3
 Start index of UFS instances. More...
 

Functions

DSTATUS disk_status (BYTE pdrv)
 Gets the status of the disk. More...
 
DSTATUS disk_initialize (BYTE pdrv)
 Initializes the drive. More...
 
DRESULT disk_read (BYTE pdrv, BYTE *buff, LBA_t sector, UINT count)
 Reads the drive In case of SD, it reads the SD card using ADMA2 in polled mode. More...
 
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void *buff)
 List specific features and do miscellaneous functions on device. More...
 
DWORD get_fattime (void)
 This function is User Provided Timer Function for FatFs module. More...
 
DRESULT disk_write (BYTE pdrv, const BYTE *buff, LBA_t sector, UINT count)
 Reads the drive In case of SD, it reads the SD card using ADMA2 in polled mode. More...
 

Macro Definition Documentation

#define XSDPS_NUM_INSTANCES   2

Number of SD instances.

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

#define XUFSPSXC_START_INDEX   3

Start index of UFS instances.

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

Function Documentation

DSTATUS disk_initialize ( BYTE  pdrv)

Initializes the drive.

In case of SD, it initializes the host controller and the card. This function also selects additional settings such as bus width, speed and block size.

Parameters
pdrv- Drive number
Returns
s - which contains an OR of the following information STA_NODISK Disk is not present STA_NOINIT Drive not initialized STA_PROTECT Drive is write protected 0 or only STA_PROTECT both indicate successful initialization.
Note

References disk_status(), and XSDPS_NUM_INSTANCES.

DRESULT disk_ioctl ( BYTE  pdrv,
BYTE  cmd,
void *  buff 
)

List specific features and do miscellaneous functions on device.

In case of SD, it control device specific features and miscellaneous functions other than generic read/write.

Parameters
pdrv- Drive number
cmd- Command code
buff- Pointer to the parameter depends on the command code.
Returns
RES_OK Command successful RES_PARERR Command is invalid RES_NOTRDY Drive not initialized RES_ERROR Error occured
Note

References disk_status(), XSDPS_NUM_INSTANCES, and XUFSPSXC_START_INDEX.

DRESULT disk_read ( BYTE  pdrv,
BYTE *  buff,
LBA_t  sector,
UINT  count 
)

Reads the drive In case of SD, it reads the SD card using ADMA2 in polled mode.

Parameters
pdrv- Drive number
buff- Pointer to the data buffer to store read data
sector- Start sector number
count- Sector count
Returns
RES_OK Read successful STA_NOINIT Drive not initialized RES_ERROR Read not successful
Note

References disk_status(), XSDPS_NUM_INSTANCES, and XUFSPSXC_START_INDEX.

DSTATUS disk_status ( BYTE  pdrv)

Gets the status of the disk.

In case of SD, it checks whether card is present or not.

Parameters
pdrv- Drive number
Returns
0 Status ok STA_NOINIT Drive not initialized STA_NODISK No medium in the drive STA_PROTECT Write protected
Note
In case Card detect signal is not connected, this function will not be able to check if card is present.

References XSDPS_NUM_INSTANCES.

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

DRESULT disk_write ( BYTE  pdrv,
const BYTE *  buff,
LBA_t  sector,
UINT  count 
)

Reads the drive In case of SD, it reads the SD card using ADMA2 in polled mode.

Parameters
pdrv- Drive number
buff- Pointer to the data to be written
sector- Sector address
count- Sector count
Returns
RES_OK Read successful STA_NOINIT Drive not initialized RES_ERROR Read not successful
Note

References disk_status(), XSDPS_NUM_INSTANCES, and XUFSPSXC_START_INDEX.

DWORD get_fattime ( void  )

This function is User Provided Timer Function for FatFs module.

Returns
DWORD
Note
None