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