Austin Schuh | 41baf20 | 2022-01-01 14:33:40 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------- |
| 2 | / Low level disk interface modlue include file (C)ChaN, 2013 |
| 3 | /-----------------------------------------------------------------------*/ |
| 4 | |
| 5 | #ifndef _DISKIO_DEFINED |
| 6 | #define _DISKIO_DEFINED |
| 7 | |
| 8 | #ifdef __cplusplus |
| 9 | extern "C" { |
| 10 | #endif |
| 11 | |
| 12 | #define _USE_WRITE 1 /* 1: Enable disk_write function */ |
| 13 | #define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */ |
| 14 | |
| 15 | #include "integer.h" |
| 16 | #include <stdbool.h> |
| 17 | |
| 18 | /* Status of Disk Functions */ |
| 19 | typedef BYTE DSTATUS; |
| 20 | |
| 21 | /* Results of Disk Functions */ |
| 22 | typedef enum { |
| 23 | RES_OK = 0, /* 0: Successful */ |
| 24 | RES_ERROR, /* 1: R/W Error */ |
| 25 | RES_WRPRT, /* 2: Write Protected */ |
| 26 | RES_NOTRDY, /* 3: Not Ready */ |
| 27 | RES_PARERR /* 4: Invalid Parameter */ |
| 28 | } DRESULT; |
| 29 | |
| 30 | |
| 31 | /* Disk Status Bits (DSTATUS) */ |
| 32 | #define STA_NOINIT 0x01 /* Drive not initialized */ |
| 33 | #define STA_NODISK 0x02 /* No medium in the drive */ |
| 34 | #define STA_PROTECT 0x04 /* Write protected */ |
| 35 | |
| 36 | |
| 37 | /* Command code for disk_ioctrl fucntion */ |
| 38 | |
| 39 | /* Generic command (used by FatFs) */ |
| 40 | #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */ |
| 41 | #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */ |
| 42 | #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */ |
| 43 | #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */ |
| 44 | #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */ |
| 45 | |
| 46 | /* Generic command (not used by FatFs) */ |
| 47 | #define CTRL_POWER 5 /* Get/Set power status */ |
| 48 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ |
| 49 | #define CTRL_EJECT 7 /* Eject media */ |
| 50 | #define CTRL_FORMAT 8 /* Create physical format on the media */ |
| 51 | |
| 52 | /* MMC/SDC specific ioctl command */ |
| 53 | #define MMC_GET_TYPE 10 /* Get card type */ |
| 54 | #define MMC_GET_CSD 11 /* Get CSD */ |
| 55 | #define MMC_GET_CID 12 /* Get CID */ |
| 56 | #define MMC_GET_OCR 13 /* Get OCR */ |
| 57 | #define MMC_GET_SDSTAT 14 /* Get SD status */ |
| 58 | |
| 59 | /* ATA/CF specific ioctl command */ |
| 60 | #define ATA_GET_REV 20 /* Get F/W revision */ |
| 61 | #define ATA_GET_MODEL 21 /* Get model name */ |
| 62 | #define ATA_GET_SN 22 /* Get serial number */ |
| 63 | |
| 64 | |
| 65 | /* MMC card type flags (MMC_GET_TYPE) */ |
| 66 | #define CT_MMC 0x01 /* MMC ver 3 */ |
| 67 | #define CT_SD1 0x02 /* SD ver 1 */ |
| 68 | #define CT_SD2 0x04 /* SD ver 2 */ |
| 69 | #define CT_SDC (CT_SD1|CT_SD2) /* SD */ |
| 70 | #define CT_BLOCK 0x08 /* Block addressing */ |
| 71 | |
| 72 | /*---------------------------------------*/ |
| 73 | /* Prototypes for disk control functions */ |
| 74 | |
| 75 | void diskio_init(void); |
| 76 | void disk_deinitialize ( BYTE pdrv ); |
| 77 | DSTATUS disk_initialize (BYTE pdrv); |
| 78 | DSTATUS disk_status (BYTE pdrv); |
| 79 | DRESULT disk_read (BYTE pdrv, BYTE*buff, DWORD sector, BYTE count); |
| 80 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, BYTE count); |
| 81 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); |
| 82 | |
| 83 | static inline bool disk_is_ready(BYTE pdrv); |
| 84 | static inline bool disk_is_ready(BYTE pdrv) |
| 85 | { |
| 86 | return (pdrv < CFG_TUH_DEVICE_MAX) && |
| 87 | ( (disk_status(pdrv) & (STA_NOINIT | STA_NODISK)) == 0 ); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | #ifdef __cplusplus |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #endif |