diskio.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*-----------------------------------------------------------------------/
  2. / Low level disk interface modlue include file (C)ChaN, 2019 /
  3. /-----------------------------------------------------------------------*/
  4. #ifndef _DISKIO_DEFINED
  5. #define _DISKIO_DEFINED
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. enum {
  10. DISK_SPI = 0,
  11. DISK_SDIO,
  12. DISK_RAM,
  13. DISK_USB
  14. };
  15. /* Status of Disk Functions */
  16. typedef BYTE DSTATUS;
  17. /* Results of Disk Functions */
  18. typedef enum {
  19. RES_OK = 0, /* 0: Successful */
  20. RES_ERROR, /* 1: R/W Error */
  21. RES_WRPRT, /* 2: Write Protected */
  22. RES_NOTRDY, /* 3: Not Ready */
  23. RES_PARERR /* 4: Invalid Parameter */
  24. } DRESULT;
  25. typedef struct block_disk_opts {
  26. DSTATUS (*initialize) (void* userdata);
  27. DSTATUS (*status) (void* userdata);
  28. DRESULT (*read) (void* userdata, BYTE* buff, LBA_t sector, UINT count);
  29. DRESULT (*write) (void* userdata, const BYTE* buff, LBA_t sector, UINT count);
  30. DRESULT (*ioctl) (void* userdata, BYTE cmd, void* buff);
  31. }block_disk_opts_t;
  32. typedef struct block_disk {
  33. void* userdata;
  34. const block_disk_opts_t* opts;
  35. }block_disk_t;
  36. DRESULT diskio_open(BYTE pdrv, block_disk_t * disk);
  37. DRESULT diskio_close(BYTE pdrv);
  38. /*---------------------------------------*/
  39. /* Prototypes for disk control functions */
  40. DSTATUS disk_initialize (BYTE pdrv);
  41. DSTATUS disk_status (BYTE pdrv);
  42. DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
  43. DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
  44. DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
  45. /* Disk Status Bits (DSTATUS) */
  46. #define STA_NOINIT 0x01 /* Drive not initialized */
  47. #define STA_NODISK 0x02 /* No medium in the drive */
  48. #define STA_PROTECT 0x04 /* Write protected */
  49. /* Command code for disk_ioctrl fucntion */
  50. /* Generic command (Used by FatFs) */
  51. #define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
  52. #define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
  53. #define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
  54. #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
  55. #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
  56. /* Generic command (Not used by FatFs) */
  57. #define CTRL_POWER 5 /* Get/Set power status */
  58. #define CTRL_LOCK 6 /* Lock/Unlock media removal */
  59. #define CTRL_EJECT 7 /* Eject media */
  60. #define CTRL_FORMAT 8 /* Create physical format on the media */
  61. /* MMC/SDC specific ioctl command */
  62. #define MMC_GET_TYPE 10 /* Get card type */
  63. #define MMC_GET_CSD 11 /* Get CSD */
  64. #define MMC_GET_CID 12 /* Get CID */
  65. #define MMC_GET_OCR 13 /* Get OCR */
  66. #define MMC_GET_SDSTAT 14 /* Get SD status */
  67. #define ISDIO_READ 55 /* Read data form SD iSDIO register */
  68. #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
  69. #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
  70. /* ATA/CF specific ioctl command */
  71. #define ATA_GET_REV 20 /* Get F/W revision */
  72. #define ATA_GET_MODEL 21 /* Get model name */
  73. #define ATA_GET_SN 22 /* Get serial number */
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif