Lab Checkoff

Dependencies:   SDFileSystem TextLCD mbed-rtos mbed wave_player FATFileSystem

Committer:
doubster
Date:
Wed Nov 13 20:00:28 2013 +0000
Revision:
0:67dbd54e60d4
Lab Checkoff

Who changed what in which revision?

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