EA BaseBoard, playing wav, PC see\'s SD-card through USB port.

Dependencies:   mbed

Committer:
Lerche
Date:
Tue Nov 22 05:45:58 2011 +0000
Revision:
0:fef366d2ed20
Thanks to those who provided EA_WavPlayer and USB_MSC

Who changed what in which revision?

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