LCD1289Serial_Ethenet

Dependencies:   EthernetInterface FatFileSystemCpp SDFileSystem mbed-rtos mbed

Committer:
shindo
Date:
Wed Nov 07 06:42:34 2012 +0000
Revision:
0:a5367e4d8591
LCD1289Serial_Ethenet

Who changed what in which revision?

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