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