-

Dependents:   RSALB_hbridge_helloworld RSALB_lobster WavPlayer_test AudioCODEC_HelloWorld ... more

Fork of FatFileSystemCpp by Igor Skochinsky

Committer:
p07gbar
Date:
Wed Sep 19 11:03:35 2012 +0000
Revision:
2:e869ee8f3c3d
Parent:
1:88f22c32a456
-

Who changed what in which revision?

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