ECE 2035 final project

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
rconnorlawson
Date:
Fri Mar 30 17:07:25 2018 +0000
Revision:
0:35660d7952f7
Hollowed out shell code.

Who changed what in which revision?

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