-- CHANGED -- To stop compilation errors I changed all *.c files to *.cpp. I have not tested this to see if it actually works. --- Updated FAT File System driver. Features include: * Updated to R0.09 - Sep 06, 2011 [[http://elm-chan.org/fsw/ff/00index_e.html]] * Bug fixes from Stéphane Bausseron ** [[http://mbed.org/forum/mbed/topic/2273/?page=1#comment-11521]] ** [[http://mbed.org/forum/mbed/topic/2307]] * Long filename support enabled and exposed through mbed SDK.

Dependents:   WAVEplayer_fix

Fork of FatFileSystem by Adam Green

Committer:
bridadan
Date:
Mon Feb 09 16:02:31 2015 +0000
Revision:
1:8263aa1f626a
Parent:
diskio.c@0:6ceefe1c53e4
Attempting to fix program for K64F platform.

Who changed what in which revision?

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