diskio.h 3.3 KB

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