s

Fork of FATFileSystem by Chaiyaporn Boonyasathian

Committer:
583405000008
Date:
Tue Dec 06 07:22:42 2016 +0000
Revision:
1:6fa3f673d44c
Parent:
0:9296bb2a98a8
d;

Who changed what in which revision?

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