hhhhhhhhh

Fork of FATFileSystem by mbed official

Committer:
mbed_official
Date:
Thu Aug 13 10:15:39 2015 +0100
Revision:
6:b3b3370574cf
Parent:
4:3ff2606d5713
Synchronized with git revision ab6a668ec18ad1530649c4cf1067a42816c6a7f8

Full URL: https://github.com/mbedmicro/mbed/commit/ab6a668ec18ad1530649c4cf1067a42816c6a7f8/

FATFileSystem - Updated FatFs to R0.11

Who changed what in which revision?

UserRevisionLine numberNew 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 (
mbed_official 6:b3b3370574cf 16 BYTE pdrv /* Physical drive number (0..) */
mbed_official 4:3ff2606d5713 17 )
emilmont 1:46ce1e16c870 18 {
mbed_official 6:b3b3370574cf 19 debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv);
mbed_official 6:b3b3370574cf 20 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_initialize();
emilmont 1:46ce1e16c870 21 }
emilmont 1:46ce1e16c870 22
emilmont 1:46ce1e16c870 23 DSTATUS disk_status (
mbed_official 6:b3b3370574cf 24 BYTE pdrv /* Physical drive number (0..) */
mbed_official 4:3ff2606d5713 25 )
emilmont 1:46ce1e16c870 26 {
mbed_official 6:b3b3370574cf 27 debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv);
mbed_official 6:b3b3370574cf 28 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_status();
emilmont 1:46ce1e16c870 29 }
emilmont 1:46ce1e16c870 30
emilmont 1:46ce1e16c870 31 DRESULT disk_read (
mbed_official 6:b3b3370574cf 32 BYTE pdrv, /* Physical drive number (0..) */
mbed_official 6:b3b3370574cf 33 BYTE* buff, /* Data buffer to store read data */
emilmont 1:46ce1e16c870 34 DWORD sector, /* Sector address (LBA) */
mbed_official 6:b3b3370574cf 35 UINT count /* Number of sectors to read (1..) */
emilmont 1:46ce1e16c870 36 )
emilmont 1:46ce1e16c870 37 {
mbed_official 6:b3b3370574cf 38 debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
mbed_official 6:b3b3370574cf 39 if (FATFileSystem::_ffs[pdrv]->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 (
mbed_official 6:b3b3370574cf 47 BYTE pdrv, /* Physical drive number (0..) */
mbed_official 6:b3b3370574cf 48 const BYTE* buff, /* Data to be written */
emilmont 1:46ce1e16c870 49 DWORD sector, /* Sector address (LBA) */
mbed_official 6:b3b3370574cf 50 UINT count /* Number of sectors to write (1..) */
emilmont 1:46ce1e16c870 51 )
emilmont 1:46ce1e16c870 52 {
mbed_official 6:b3b3370574cf 53 debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
mbed_official 6:b3b3370574cf 54 if (FATFileSystem::_ffs[pdrv]->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 (
mbed_official 6:b3b3370574cf 62 BYTE pdrv, /* Physical drive number (0..) */
mbed_official 6:b3b3370574cf 63 BYTE cmd, /* Control code */
mbed_official 6:b3b3370574cf 64 void* buff /* Buffer to send/receive control data */
emilmont 1:46ce1e16c870 65 )
emilmont 1:46ce1e16c870 66 {
mbed_official 6:b3b3370574cf 67 debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd);
mbed_official 6:b3b3370574cf 68 switch(cmd) {
emilmont 1:46ce1e16c870 69 case CTRL_SYNC:
mbed_official 6:b3b3370574cf 70 if(FATFileSystem::_ffs[pdrv] == NULL) {
emilmont 1:46ce1e16c870 71 return RES_NOTRDY;
mbed_official 6:b3b3370574cf 72 } else if(FATFileSystem::_ffs[pdrv]->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:
mbed_official 6:b3b3370574cf 77 if(FATFileSystem::_ffs[pdrv] == NULL) {
emilmont 1:46ce1e16c870 78 return RES_NOTRDY;
emilmont 1:46ce1e16c870 79 } else {
mbed_official 6:b3b3370574cf 80 DWORD res = FATFileSystem::_ffs[pdrv]->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 }