microCD

Fork of FATFileSystem by mbed official

Committer:
vnemera
Date:
Fri Feb 17 16:43:26 2017 +0000
Revision:
8:0345cdc7efa5
Parent:
6:a5fcdbf92056
1.4.4

Who changed what in which revision?

UserRevisionLine numberNew 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
mbed_official 6:a5fcdbf92056 14 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 15 /* Get Drive Status */
mbed_official 6:a5fcdbf92056 16 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 17
mbed_official 6:a5fcdbf92056 18 DSTATUS disk_status (
mbed_official 6:a5fcdbf92056 19 BYTE pdrv /* Physical drive nmuber to identify the drive */
mbed_official 6:a5fcdbf92056 20 )
mbed_official 6:a5fcdbf92056 21 {
mbed_official 6:a5fcdbf92056 22 debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv);
mbed_official 6:a5fcdbf92056 23 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_status();
mbed_official 6:a5fcdbf92056 24 }
mbed_official 6:a5fcdbf92056 25
mbed_official 6:a5fcdbf92056 26 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 27 /* Inidialize a Drive */
mbed_official 6:a5fcdbf92056 28 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 29
emilmont 1:46ce1e16c870 30 DSTATUS disk_initialize (
vnemera 8:0345cdc7efa5 31 BYTE pdrv /* Physical drive number to identify the drive */
mbed_official 4:3ff2606d5713 32 )
emilmont 1:46ce1e16c870 33 {
mbed_official 5:b3b3370574cf 34 debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv);
mbed_official 5:b3b3370574cf 35 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_initialize();
emilmont 1:46ce1e16c870 36 }
emilmont 1:46ce1e16c870 37
mbed_official 6:a5fcdbf92056 38 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 39 /* Read Sector(s) */
mbed_official 6:a5fcdbf92056 40 /*-----------------------------------------------------------------------*/
emilmont 1:46ce1e16c870 41
emilmont 1:46ce1e16c870 42 DRESULT disk_read (
mbed_official 6:a5fcdbf92056 43 BYTE pdrv, /* Physical drive nmuber to identify the drive */
mbed_official 5:b3b3370574cf 44 BYTE* buff, /* Data buffer to store read data */
mbed_official 6:a5fcdbf92056 45 DWORD sector, /* Sector address in LBA */
mbed_official 6:a5fcdbf92056 46 UINT count /* Number of sectors to read */
emilmont 1:46ce1e16c870 47 )
emilmont 1:46ce1e16c870 48 {
mbed_official 5:b3b3370574cf 49 debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
mbed_official 5:b3b3370574cf 50 if (FATFileSystem::_ffs[pdrv]->disk_read((uint8_t*)buff, sector, count))
mbed_official 4:3ff2606d5713 51 return RES_PARERR;
mbed_official 4:3ff2606d5713 52 else
mbed_official 4:3ff2606d5713 53 return RES_OK;
emilmont 1:46ce1e16c870 54 }
emilmont 1:46ce1e16c870 55
mbed_official 6:a5fcdbf92056 56 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 57 /* Write Sector(s) */
mbed_official 6:a5fcdbf92056 58 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 59
mbed_official 6:a5fcdbf92056 60 #if _USE_WRITE
emilmont 1:46ce1e16c870 61 DRESULT disk_write (
mbed_official 6:a5fcdbf92056 62 BYTE pdrv, /* Physical drive nmuber to identify the drive */
mbed_official 5:b3b3370574cf 63 const BYTE* buff, /* Data to be written */
mbed_official 6:a5fcdbf92056 64 DWORD sector, /* Sector address in LBA */
mbed_official 6:a5fcdbf92056 65 UINT count /* Number of sectors to write */
emilmont 1:46ce1e16c870 66 )
emilmont 1:46ce1e16c870 67 {
mbed_official 5:b3b3370574cf 68 debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
mbed_official 5:b3b3370574cf 69 if (FATFileSystem::_ffs[pdrv]->disk_write((uint8_t*)buff, sector, count))
mbed_official 4:3ff2606d5713 70 return RES_PARERR;
mbed_official 4:3ff2606d5713 71 else
mbed_official 4:3ff2606d5713 72 return RES_OK;
emilmont 1:46ce1e16c870 73 }
mbed_official 6:a5fcdbf92056 74 #endif
emilmont 1:46ce1e16c870 75
mbed_official 6:a5fcdbf92056 76 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 77 /* Miscellaneous Functions */
mbed_official 6:a5fcdbf92056 78 /*-----------------------------------------------------------------------*/
mbed_official 6:a5fcdbf92056 79
mbed_official 6:a5fcdbf92056 80 #if _USE_IOCTL
emilmont 1:46ce1e16c870 81 DRESULT disk_ioctl (
mbed_official 6:a5fcdbf92056 82 BYTE pdrv, /* Physical drive nmuber (0..) */
mbed_official 5:b3b3370574cf 83 BYTE cmd, /* Control code */
mbed_official 5:b3b3370574cf 84 void* buff /* Buffer to send/receive control data */
emilmont 1:46ce1e16c870 85 )
emilmont 1:46ce1e16c870 86 {
mbed_official 5:b3b3370574cf 87 debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd);
mbed_official 5:b3b3370574cf 88 switch(cmd) {
emilmont 1:46ce1e16c870 89 case CTRL_SYNC:
mbed_official 5:b3b3370574cf 90 if(FATFileSystem::_ffs[pdrv] == NULL) {
emilmont 1:46ce1e16c870 91 return RES_NOTRDY;
mbed_official 5:b3b3370574cf 92 } else if(FATFileSystem::_ffs[pdrv]->disk_sync()) {
emilmont 1:46ce1e16c870 93 return RES_ERROR;
emilmont 1:46ce1e16c870 94 }
emilmont 1:46ce1e16c870 95 return RES_OK;
emilmont 1:46ce1e16c870 96 case GET_SECTOR_COUNT:
mbed_official 5:b3b3370574cf 97 if(FATFileSystem::_ffs[pdrv] == NULL) {
emilmont 1:46ce1e16c870 98 return RES_NOTRDY;
emilmont 1:46ce1e16c870 99 } else {
mbed_official 5:b3b3370574cf 100 DWORD res = FATFileSystem::_ffs[pdrv]->disk_sectors();
emilmont 1:46ce1e16c870 101 if(res > 0) {
emilmont 1:46ce1e16c870 102 *((DWORD*)buff) = res; // minimum allowed
emilmont 1:46ce1e16c870 103 return RES_OK;
emilmont 1:46ce1e16c870 104 } else {
emilmont 1:46ce1e16c870 105 return RES_ERROR;
emilmont 1:46ce1e16c870 106 }
emilmont 1:46ce1e16c870 107 }
emilmont 1:46ce1e16c870 108 case GET_BLOCK_SIZE:
emilmont 1:46ce1e16c870 109 *((DWORD*)buff) = 1; // default when not known
emilmont 1:46ce1e16c870 110 return RES_OK;
emilmont 1:46ce1e16c870 111
emilmont 1:46ce1e16c870 112 }
emilmont 1:46ce1e16c870 113 return RES_PARERR;
emilmont 1:46ce1e16c870 114 }
mbed_official 6:a5fcdbf92056 115 #endif