bla bla bla
Fork of FATFileSystem by
ChaN/diskio.cpp@4:3ff2606d5713, 2014-08-28 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Aug 28 13:15:31 2014 +0100
- Revision:
- 4:3ff2606d5713
- Parent:
- 2:b6669c987c8e
- Child:
- 5:b3b3370574cf
Synchronized with git revision fee50a80ffdc8f9d9ee97be545ff36b5a986f041
Full URL: https://github.com/mbedmicro/mbed/commit/fee50a80ffdc8f9d9ee97be545ff36b5a986f041/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:46ce1e16c870 | 1 | /*-----------------------------------------------------------------------*/ |
emilmont | 1:46ce1e16c870 | 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ |
emilmont | 1:46ce1e16c870 | 3 | /*-----------------------------------------------------------------------*/ |
emilmont | 1:46ce1e16c870 | 4 | /* This is a stub disk I/O module that acts as front end of the existing */ |
emilmont | 1:46ce1e16c870 | 5 | /* disk I/O modules and attach it to FatFs module with common interface. */ |
emilmont | 1:46ce1e16c870 | 6 | /*-----------------------------------------------------------------------*/ |
emilmont | 1:46ce1e16c870 | 7 | #include "ffconf.h" |
emilmont | 1:46ce1e16c870 | 8 | #include "diskio.h" |
emilmont | 1:46ce1e16c870 | 9 | |
emilmont | 2:b6669c987c8e | 10 | #include "mbed_debug.h" |
emilmont | 1:46ce1e16c870 | 11 | #include "FATFileSystem.h" |
emilmont | 1:46ce1e16c870 | 12 | |
emilmont | 1:46ce1e16c870 | 13 | using namespace mbed; |
emilmont | 1:46ce1e16c870 | 14 | |
emilmont | 1:46ce1e16c870 | 15 | DSTATUS disk_initialize ( |
emilmont | 1:46ce1e16c870 | 16 | BYTE drv /* Physical drive nmuber (0..) */ |
mbed_official | 4:3ff2606d5713 | 17 | ) |
emilmont | 1:46ce1e16c870 | 18 | { |
emilmont | 1:46ce1e16c870 | 19 | debug_if(FFS_DBG, "disk_initialize on drv [%d]\n", drv); |
emilmont | 1:46ce1e16c870 | 20 | return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize(); |
emilmont | 1:46ce1e16c870 | 21 | } |
emilmont | 1:46ce1e16c870 | 22 | |
emilmont | 1:46ce1e16c870 | 23 | DSTATUS disk_status ( |
emilmont | 1:46ce1e16c870 | 24 | BYTE drv /* Physical drive nmuber (0..) */ |
mbed_official | 4:3ff2606d5713 | 25 | ) |
emilmont | 1:46ce1e16c870 | 26 | { |
emilmont | 1:46ce1e16c870 | 27 | debug_if(FFS_DBG, "disk_status on drv [%d]\n", drv); |
emilmont | 1:46ce1e16c870 | 28 | return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status(); |
emilmont | 1:46ce1e16c870 | 29 | } |
emilmont | 1:46ce1e16c870 | 30 | |
emilmont | 1:46ce1e16c870 | 31 | DRESULT disk_read ( |
emilmont | 1:46ce1e16c870 | 32 | BYTE drv, /* Physical drive nmuber (0..) */ |
emilmont | 1:46ce1e16c870 | 33 | BYTE *buff, /* Data buffer to store read data */ |
emilmont | 1:46ce1e16c870 | 34 | DWORD sector, /* Sector address (LBA) */ |
emilmont | 1:46ce1e16c870 | 35 | BYTE count /* Number of sectors to read (1..255) */ |
emilmont | 1:46ce1e16c870 | 36 | ) |
emilmont | 1:46ce1e16c870 | 37 | { |
emilmont | 1:46ce1e16c870 | 38 | debug_if(FFS_DBG, "disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv); |
mbed_official | 4:3ff2606d5713 | 39 | if (FATFileSystem::_ffs[drv]->disk_read((uint8_t*)buff, sector, count)) |
mbed_official | 4:3ff2606d5713 | 40 | return RES_PARERR; |
mbed_official | 4:3ff2606d5713 | 41 | else |
mbed_official | 4:3ff2606d5713 | 42 | return RES_OK; |
emilmont | 1:46ce1e16c870 | 43 | } |
emilmont | 1:46ce1e16c870 | 44 | |
emilmont | 1:46ce1e16c870 | 45 | #if _READONLY == 0 |
emilmont | 1:46ce1e16c870 | 46 | DRESULT disk_write ( |
emilmont | 1:46ce1e16c870 | 47 | BYTE drv, /* Physical drive nmuber (0..) */ |
emilmont | 1:46ce1e16c870 | 48 | const BYTE *buff, /* Data to be written */ |
emilmont | 1:46ce1e16c870 | 49 | DWORD sector, /* Sector address (LBA) */ |
emilmont | 1:46ce1e16c870 | 50 | BYTE count /* Number of sectors to write (1..255) */ |
emilmont | 1:46ce1e16c870 | 51 | ) |
emilmont | 1:46ce1e16c870 | 52 | { |
emilmont | 1:46ce1e16c870 | 53 | debug_if(FFS_DBG, "disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv); |
mbed_official | 4:3ff2606d5713 | 54 | if (FATFileSystem::_ffs[drv]->disk_write((uint8_t*)buff, sector, count)) |
mbed_official | 4:3ff2606d5713 | 55 | return RES_PARERR; |
mbed_official | 4:3ff2606d5713 | 56 | else |
mbed_official | 4:3ff2606d5713 | 57 | return RES_OK; |
emilmont | 1:46ce1e16c870 | 58 | } |
emilmont | 1:46ce1e16c870 | 59 | #endif /* _READONLY */ |
emilmont | 1:46ce1e16c870 | 60 | |
emilmont | 1:46ce1e16c870 | 61 | DRESULT disk_ioctl ( |
emilmont | 1:46ce1e16c870 | 62 | BYTE drv, /* Physical drive nmuber (0..) */ |
emilmont | 1:46ce1e16c870 | 63 | BYTE ctrl, /* Control code */ |
emilmont | 1:46ce1e16c870 | 64 | void *buff /* Buffer to send/receive control data */ |
emilmont | 1:46ce1e16c870 | 65 | ) |
emilmont | 1:46ce1e16c870 | 66 | { |
emilmont | 1:46ce1e16c870 | 67 | debug_if(FFS_DBG, "disk_ioctl(%d)\n", ctrl); |
emilmont | 1:46ce1e16c870 | 68 | switch(ctrl) { |
emilmont | 1:46ce1e16c870 | 69 | case CTRL_SYNC: |
emilmont | 1:46ce1e16c870 | 70 | if(FATFileSystem::_ffs[drv] == NULL) { |
emilmont | 1:46ce1e16c870 | 71 | return RES_NOTRDY; |
emilmont | 1:46ce1e16c870 | 72 | } else if(FATFileSystem::_ffs[drv]->disk_sync()) { |
emilmont | 1:46ce1e16c870 | 73 | return RES_ERROR; |
emilmont | 1:46ce1e16c870 | 74 | } |
emilmont | 1:46ce1e16c870 | 75 | return RES_OK; |
emilmont | 1:46ce1e16c870 | 76 | case GET_SECTOR_COUNT: |
emilmont | 1:46ce1e16c870 | 77 | if(FATFileSystem::_ffs[drv] == NULL) { |
emilmont | 1:46ce1e16c870 | 78 | return RES_NOTRDY; |
emilmont | 1:46ce1e16c870 | 79 | } else { |
emilmont | 1:46ce1e16c870 | 80 | DWORD res = FATFileSystem::_ffs[drv]->disk_sectors(); |
emilmont | 1:46ce1e16c870 | 81 | if(res > 0) { |
emilmont | 1:46ce1e16c870 | 82 | *((DWORD*)buff) = res; // minimum allowed |
emilmont | 1:46ce1e16c870 | 83 | return RES_OK; |
emilmont | 1:46ce1e16c870 | 84 | } else { |
emilmont | 1:46ce1e16c870 | 85 | return RES_ERROR; |
emilmont | 1:46ce1e16c870 | 86 | } |
emilmont | 1:46ce1e16c870 | 87 | } |
emilmont | 1:46ce1e16c870 | 88 | case GET_BLOCK_SIZE: |
emilmont | 1:46ce1e16c870 | 89 | *((DWORD*)buff) = 1; // default when not known |
emilmont | 1:46ce1e16c870 | 90 | return RES_OK; |
emilmont | 1:46ce1e16c870 | 91 | |
emilmont | 1:46ce1e16c870 | 92 | } |
emilmont | 1:46ce1e16c870 | 93 | return RES_PARERR; |
emilmont | 1:46ce1e16c870 | 94 | } |