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