help :(
Dependencies: FFT
FATFileSystem/ChaN/diskio.cpp@11:951bbb0385aa, 2020-12-04 (annotated)
- Committer:
- dimitryjl23
- Date:
- Fri Dec 04 18:01:22 2020 +0000
- Revision:
- 11:951bbb0385aa
- Parent:
- 0:d6c9b09b4042
Final :)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
annieluo2 | 0:d6c9b09b4042 | 1 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */ |
annieluo2 | 0:d6c9b09b4042 | 3 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 4 | /* If a working storage control module is available, it should be */ |
annieluo2 | 0:d6c9b09b4042 | 5 | /* attached to the FatFs via a glue function rather than modifying it. */ |
annieluo2 | 0:d6c9b09b4042 | 6 | /* This is an example of glue functions to attach various exsisting */ |
annieluo2 | 0:d6c9b09b4042 | 7 | /* storage control modules to the FatFs module with a defined API. */ |
annieluo2 | 0:d6c9b09b4042 | 8 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 9 | |
annieluo2 | 0:d6c9b09b4042 | 10 | #include "diskio.h" |
annieluo2 | 0:d6c9b09b4042 | 11 | #include "mbed_debug.h" |
annieluo2 | 0:d6c9b09b4042 | 12 | #include "FATFileSystem.h" |
annieluo2 | 0:d6c9b09b4042 | 13 | |
annieluo2 | 0:d6c9b09b4042 | 14 | using namespace mbed; |
annieluo2 | 0:d6c9b09b4042 | 15 | |
annieluo2 | 0:d6c9b09b4042 | 16 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 17 | /* Get Drive Status */ |
annieluo2 | 0:d6c9b09b4042 | 18 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 19 | |
annieluo2 | 0:d6c9b09b4042 | 20 | DSTATUS disk_status ( |
annieluo2 | 0:d6c9b09b4042 | 21 | BYTE pdrv /* Physical drive nmuber to identify the drive */ |
annieluo2 | 0:d6c9b09b4042 | 22 | ) |
annieluo2 | 0:d6c9b09b4042 | 23 | { |
annieluo2 | 0:d6c9b09b4042 | 24 | debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv); |
annieluo2 | 0:d6c9b09b4042 | 25 | return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_status(); |
annieluo2 | 0:d6c9b09b4042 | 26 | } |
annieluo2 | 0:d6c9b09b4042 | 27 | |
annieluo2 | 0:d6c9b09b4042 | 28 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 29 | /* Inidialize a Drive */ |
annieluo2 | 0:d6c9b09b4042 | 30 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 31 | |
annieluo2 | 0:d6c9b09b4042 | 32 | DSTATUS disk_initialize ( |
annieluo2 | 0:d6c9b09b4042 | 33 | BYTE pdrv /* Physical drive nmuber to identify the drive */ |
annieluo2 | 0:d6c9b09b4042 | 34 | ) |
annieluo2 | 0:d6c9b09b4042 | 35 | { |
annieluo2 | 0:d6c9b09b4042 | 36 | debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv); |
annieluo2 | 0:d6c9b09b4042 | 37 | return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_initialize(); |
annieluo2 | 0:d6c9b09b4042 | 38 | } |
annieluo2 | 0:d6c9b09b4042 | 39 | |
annieluo2 | 0:d6c9b09b4042 | 40 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 41 | /* Read Sector(s) */ |
annieluo2 | 0:d6c9b09b4042 | 42 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 43 | |
annieluo2 | 0:d6c9b09b4042 | 44 | DRESULT disk_read ( |
annieluo2 | 0:d6c9b09b4042 | 45 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ |
annieluo2 | 0:d6c9b09b4042 | 46 | BYTE* buff, /* Data buffer to store read data */ |
annieluo2 | 0:d6c9b09b4042 | 47 | DWORD sector, /* Sector address in LBA */ |
annieluo2 | 0:d6c9b09b4042 | 48 | UINT count /* Number of sectors to read */ |
annieluo2 | 0:d6c9b09b4042 | 49 | ) |
annieluo2 | 0:d6c9b09b4042 | 50 | { |
annieluo2 | 0:d6c9b09b4042 | 51 | debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv); |
annieluo2 | 0:d6c9b09b4042 | 52 | if (FATFileSystem::_ffs[pdrv]->disk_read((uint8_t*)buff, sector, count)) |
annieluo2 | 0:d6c9b09b4042 | 53 | return RES_PARERR; |
annieluo2 | 0:d6c9b09b4042 | 54 | else |
annieluo2 | 0:d6c9b09b4042 | 55 | return RES_OK; |
annieluo2 | 0:d6c9b09b4042 | 56 | } |
annieluo2 | 0:d6c9b09b4042 | 57 | |
annieluo2 | 0:d6c9b09b4042 | 58 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 59 | /* Write Sector(s) */ |
annieluo2 | 0:d6c9b09b4042 | 60 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 61 | |
annieluo2 | 0:d6c9b09b4042 | 62 | #if _USE_WRITE |
annieluo2 | 0:d6c9b09b4042 | 63 | DRESULT disk_write ( |
annieluo2 | 0:d6c9b09b4042 | 64 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ |
annieluo2 | 0:d6c9b09b4042 | 65 | const BYTE* buff, /* Data to be written */ |
annieluo2 | 0:d6c9b09b4042 | 66 | DWORD sector, /* Sector address in LBA */ |
annieluo2 | 0:d6c9b09b4042 | 67 | UINT count /* Number of sectors to write */ |
annieluo2 | 0:d6c9b09b4042 | 68 | ) |
annieluo2 | 0:d6c9b09b4042 | 69 | { |
annieluo2 | 0:d6c9b09b4042 | 70 | debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv); |
annieluo2 | 0:d6c9b09b4042 | 71 | if (FATFileSystem::_ffs[pdrv]->disk_write((uint8_t*)buff, sector, count)) |
annieluo2 | 0:d6c9b09b4042 | 72 | return RES_PARERR; |
annieluo2 | 0:d6c9b09b4042 | 73 | else |
annieluo2 | 0:d6c9b09b4042 | 74 | return RES_OK; |
annieluo2 | 0:d6c9b09b4042 | 75 | } |
annieluo2 | 0:d6c9b09b4042 | 76 | #endif |
annieluo2 | 0:d6c9b09b4042 | 77 | |
annieluo2 | 0:d6c9b09b4042 | 78 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 79 | /* Miscellaneous Functions */ |
annieluo2 | 0:d6c9b09b4042 | 80 | /*-----------------------------------------------------------------------*/ |
annieluo2 | 0:d6c9b09b4042 | 81 | |
annieluo2 | 0:d6c9b09b4042 | 82 | #if _USE_IOCTL |
annieluo2 | 0:d6c9b09b4042 | 83 | DRESULT disk_ioctl ( |
annieluo2 | 0:d6c9b09b4042 | 84 | BYTE pdrv, /* Physical drive nmuber (0..) */ |
annieluo2 | 0:d6c9b09b4042 | 85 | BYTE cmd, /* Control code */ |
annieluo2 | 0:d6c9b09b4042 | 86 | void* buff /* Buffer to send/receive control data */ |
annieluo2 | 0:d6c9b09b4042 | 87 | ) |
annieluo2 | 0:d6c9b09b4042 | 88 | { |
annieluo2 | 0:d6c9b09b4042 | 89 | debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd); |
annieluo2 | 0:d6c9b09b4042 | 90 | switch(cmd) { |
annieluo2 | 0:d6c9b09b4042 | 91 | case CTRL_SYNC: |
annieluo2 | 0:d6c9b09b4042 | 92 | if(FATFileSystem::_ffs[pdrv] == NULL) { |
annieluo2 | 0:d6c9b09b4042 | 93 | return RES_NOTRDY; |
annieluo2 | 0:d6c9b09b4042 | 94 | } else if(FATFileSystem::_ffs[pdrv]->disk_sync()) { |
annieluo2 | 0:d6c9b09b4042 | 95 | return RES_ERROR; |
annieluo2 | 0:d6c9b09b4042 | 96 | } |
annieluo2 | 0:d6c9b09b4042 | 97 | return RES_OK; |
annieluo2 | 0:d6c9b09b4042 | 98 | case GET_SECTOR_COUNT: |
annieluo2 | 0:d6c9b09b4042 | 99 | if(FATFileSystem::_ffs[pdrv] == NULL) { |
annieluo2 | 0:d6c9b09b4042 | 100 | return RES_NOTRDY; |
annieluo2 | 0:d6c9b09b4042 | 101 | } else { |
annieluo2 | 0:d6c9b09b4042 | 102 | DWORD res = FATFileSystem::_ffs[pdrv]->disk_sectors(); |
annieluo2 | 0:d6c9b09b4042 | 103 | if(res > 0) { |
annieluo2 | 0:d6c9b09b4042 | 104 | *((DWORD*)buff) = res; // minimum allowed |
annieluo2 | 0:d6c9b09b4042 | 105 | return RES_OK; |
annieluo2 | 0:d6c9b09b4042 | 106 | } else { |
annieluo2 | 0:d6c9b09b4042 | 107 | return RES_ERROR; |
annieluo2 | 0:d6c9b09b4042 | 108 | } |
annieluo2 | 0:d6c9b09b4042 | 109 | } |
annieluo2 | 0:d6c9b09b4042 | 110 | case GET_BLOCK_SIZE: |
annieluo2 | 0:d6c9b09b4042 | 111 | *((DWORD*)buff) = 1; // default when not known |
annieluo2 | 0:d6c9b09b4042 | 112 | return RES_OK; |
annieluo2 | 0:d6c9b09b4042 | 113 | |
annieluo2 | 0:d6c9b09b4042 | 114 | } |
annieluo2 | 0:d6c9b09b4042 | 115 | return RES_PARERR; |
annieluo2 | 0:d6c9b09b4042 | 116 | } |
annieluo2 | 0:d6c9b09b4042 | 117 | #endif |