diskio.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*-----------------------------------------------------------------------/
  2. / Low level disk interface modlue include file (C)ChaN, 2014 /
  3. /-----------------------------------------------------------------------*/
  4. #ifndef _DISKIO_DEFINED
  5. #define _DISKIO_DEFINED
  6. #include <disk/disk_access.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include "integer.h"
  11. /* Status of Disk Functions */
  12. typedef BYTE DSTATUS;
  13. /* Results of Disk Functions */
  14. typedef enum {
  15. RES_OK = 0, /* 0: Successful */
  16. RES_ERROR, /* 1: R/W Error */
  17. RES_WRPRT, /* 2: Write Protected */
  18. RES_NOTRDY, /* 3: Not Ready */
  19. RES_PARERR /* 4: Invalid Parameter */
  20. } DRESULT;
  21. /*---------------------------------------*/
  22. /* Prototypes for disk control functions */
  23. DSTATUS disk_initialize (BYTE pdrv);
  24. DSTATUS disk_status (BYTE pdrv);
  25. DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
  26. DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
  27. DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
  28. int diskio_cache_read(
  29. const char *pdrv,
  30. BYTE *buff, /* Data buffer to store read data */
  31. DWORD sector, /* Start sector in LBA */
  32. UINT count /* Number of sectors to read */);
  33. int diskio_cache_write(
  34. const char *pdrv,
  35. const BYTE *buff, /* Data to be written */
  36. DWORD sector, /* Start sector in LBA */
  37. UINT count /* Number of sectors to write */);
  38. int diskio_cache_flush(const char *pdrv);
  39. int diskio_cache_invalid(const char *pdrv);
  40. /* Disk Status Bits (DSTATUS) */
  41. #define STA_NOINIT 0x01 /* Drive not initialized */
  42. #define STA_NODISK 0x02 /* No medium in the drive */
  43. #define STA_PROTECT 0x04 /* Write protected */
  44. /* In order to support medium hotplug */
  45. #define STA_DISK_OK 0x08 /* Medium OK in the drive */
  46. /* Command code for disk_ioctrl fucntion */
  47. /* Generic command (Used by FatFs) */
  48. #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
  49. #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
  50. #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
  51. #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
  52. #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
  53. /* Generic command (Not used by FatFs) */
  54. #define CTRL_POWER 5 /* Get/Set power status */
  55. #define CTRL_LOCK 6 /* Lock/Unlock media removal */
  56. #define CTRL_EJECT 7 /* Eject media */
  57. #define CTRL_FORMAT 8 /* Create physical format on the media */
  58. /* MMC/SDC specific ioctl command */
  59. #define MMC_GET_TYPE 10 /* Get card type */
  60. #define MMC_GET_CSD 11 /* Get CSD */
  61. #define MMC_GET_CID 12 /* Get CID */
  62. #define MMC_GET_OCR 13 /* Get OCR */
  63. #define MMC_GET_SDSTAT 14 /* Get SD status */
  64. #define ISDIO_READ 55 /* Read data form SD iSDIO register */
  65. #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
  66. #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
  67. /* ATA/CF specific ioctl command */
  68. #define ATA_GET_REV 20 /* Get F/W revision */
  69. #define ATA_GET_MODEL 21 /* Get model name */
  70. #define ATA_GET_SN 22 /* Get serial number */
  71. /* Disk detect */
  72. #define DISK_HW_DETECT 100 /* Detect disk hardware insert or remove */
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif