hgftf

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
ajorgih3
Date:
Sat Apr 17 14:09:46 2021 +0000
Revision:
10:0b2f37cef9b9
Parent:
1:10330bce85cb
huhu

Who changed what in which revision?

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