..

Fork of FATFileSystem by mbed official

Committer:
emilmont
Date:
Thu Nov 29 10:56:08 2012 +0000
Revision:
2:b6669c987c8e
Parent:
1:46ce1e16c870
Update mbed debug header name

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 (
emilmont 1:46ce1e16c870 16 BYTE drv /* Physical drive nmuber (0..) */
emilmont 1:46ce1e16c870 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..) */
emilmont 1:46ce1e16c870 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);
emilmont 1:46ce1e16c870 39 for(DWORD s=sector; s<sector+count; s++) {
emilmont 1:46ce1e16c870 40 debug_if(FFS_DBG, " disk_read(sector %d)\n", s);
emilmont 1:46ce1e16c870 41 int res = FATFileSystem::_ffs[drv]->disk_read((uint8_t*)buff, s);
emilmont 1:46ce1e16c870 42 if(res) {
emilmont 1:46ce1e16c870 43 return RES_PARERR;
emilmont 1:46ce1e16c870 44 }
emilmont 1:46ce1e16c870 45 buff += 512;
emilmont 1:46ce1e16c870 46 }
emilmont 1:46ce1e16c870 47 return RES_OK;
emilmont 1:46ce1e16c870 48 }
emilmont 1:46ce1e16c870 49
emilmont 1:46ce1e16c870 50 #if _READONLY == 0
emilmont 1:46ce1e16c870 51 DRESULT disk_write (
emilmont 1:46ce1e16c870 52 BYTE drv, /* Physical drive nmuber (0..) */
emilmont 1:46ce1e16c870 53 const BYTE *buff, /* Data to be written */
emilmont 1:46ce1e16c870 54 DWORD sector, /* Sector address (LBA) */
emilmont 1:46ce1e16c870 55 BYTE count /* Number of sectors to write (1..255) */
emilmont 1:46ce1e16c870 56 )
emilmont 1:46ce1e16c870 57 {
emilmont 1:46ce1e16c870 58 debug_if(FFS_DBG, "disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv);
emilmont 1:46ce1e16c870 59 for(DWORD s = sector; s < sector + count; s++) {
emilmont 1:46ce1e16c870 60 debug_if(FFS_DBG, " disk_write(sector %d)\n", s);
emilmont 1:46ce1e16c870 61 int res = FATFileSystem::_ffs[drv]->disk_write((uint8_t*)buff, s);
emilmont 1:46ce1e16c870 62 if(res) {
emilmont 1:46ce1e16c870 63 return RES_PARERR;
emilmont 1:46ce1e16c870 64 }
emilmont 1:46ce1e16c870 65 buff += 512;
emilmont 1:46ce1e16c870 66 }
emilmont 1:46ce1e16c870 67 return RES_OK;
emilmont 1:46ce1e16c870 68 }
emilmont 1:46ce1e16c870 69 #endif /* _READONLY */
emilmont 1:46ce1e16c870 70
emilmont 1:46ce1e16c870 71 DRESULT disk_ioctl (
emilmont 1:46ce1e16c870 72 BYTE drv, /* Physical drive nmuber (0..) */
emilmont 1:46ce1e16c870 73 BYTE ctrl, /* Control code */
emilmont 1:46ce1e16c870 74 void *buff /* Buffer to send/receive control data */
emilmont 1:46ce1e16c870 75 )
emilmont 1:46ce1e16c870 76 {
emilmont 1:46ce1e16c870 77 debug_if(FFS_DBG, "disk_ioctl(%d)\n", ctrl);
emilmont 1:46ce1e16c870 78 switch(ctrl) {
emilmont 1:46ce1e16c870 79 case CTRL_SYNC:
emilmont 1:46ce1e16c870 80 if(FATFileSystem::_ffs[drv] == NULL) {
emilmont 1:46ce1e16c870 81 return RES_NOTRDY;
emilmont 1:46ce1e16c870 82 } else if(FATFileSystem::_ffs[drv]->disk_sync()) {
emilmont 1:46ce1e16c870 83 return RES_ERROR;
emilmont 1:46ce1e16c870 84 }
emilmont 1:46ce1e16c870 85 return RES_OK;
emilmont 1:46ce1e16c870 86 case GET_SECTOR_COUNT:
emilmont 1:46ce1e16c870 87 if(FATFileSystem::_ffs[drv] == NULL) {
emilmont 1:46ce1e16c870 88 return RES_NOTRDY;
emilmont 1:46ce1e16c870 89 } else {
emilmont 1:46ce1e16c870 90 DWORD res = FATFileSystem::_ffs[drv]->disk_sectors();
emilmont 1:46ce1e16c870 91 if(res > 0) {
emilmont 1:46ce1e16c870 92 *((DWORD*)buff) = res; // minimum allowed
emilmont 1:46ce1e16c870 93 return RES_OK;
emilmont 1:46ce1e16c870 94 } else {
emilmont 1:46ce1e16c870 95 return RES_ERROR;
emilmont 1:46ce1e16c870 96 }
emilmont 1:46ce1e16c870 97 }
emilmont 1:46ce1e16c870 98 case GET_BLOCK_SIZE:
emilmont 1:46ce1e16c870 99 *((DWORD*)buff) = 1; // default when not known
emilmont 1:46ce1e16c870 100 return RES_OK;
emilmont 1:46ce1e16c870 101
emilmont 1:46ce1e16c870 102 }
emilmont 1:46ce1e16c870 103 return RES_PARERR;
emilmont 1:46ce1e16c870 104 }