diskio.c

00001 /*-----------------------------------------------------------------------*/
00002 /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2007        */
00003 /*-----------------------------------------------------------------------*/
00004 /* This is a stub disk I/O module that acts as front end of the existing */
00005 /* disk I/O modules and attach it to FatFs module with common interface. */
00006 /*-----------------------------------------------------------------------*/
00007 
00008 #include "diskio.h"
00009 
00010 /*-----------------------------------------------------------------------*/
00011 /* Correspondence between physical drive number and physical drive.      */
00012 
00013 #define ATA     0
00014 #define MMC     1
00015 #define USB     2
00016 
00017 
00018 
00019 /*-----------------------------------------------------------------------*/
00020 /* Inidialize a Drive                                                    */
00021 
00022 DSTATUS disk_initialize (
00023     BYTE drv                /* Physical drive nmuber (0..) */
00024 )
00025 {
00026     DSTATUS stat;
00027     int result;
00028 
00029     switch (drv) {
00030     case ATA :
00031         result = ATA_disk_initialize();
00032         // translate the reslut code here
00033 
00034         return stat;
00035 
00036     case MMC :
00037         result = MMC_disk_initialize();
00038         // translate the reslut code here
00039 
00040         return stat;
00041 
00042     case USB :
00043         result = USB_disk_initialize();
00044         // translate the reslut code here
00045 
00046         return stat;
00047     }
00048     return STA_NOINIT;
00049 }
00050 
00051 
00052 
00053 /*-----------------------------------------------------------------------*/
00054 /* Return Disk Status                                                    */
00055 
00056 DSTATUS disk_status (
00057     BYTE drv        /* Physical drive nmuber (0..) */
00058 )
00059 {
00060     DSTATUS stat;
00061     int result;
00062 
00063     switch (drv) {
00064     case ATA :
00065         result = ATA_disk_status();
00066         // translate the reslut code here
00067 
00068         return stat;
00069 
00070     case MMC :
00071         result = MMC_disk_status();
00072         // translate the reslut code here
00073 
00074         return stat;
00075 
00076     case USB :
00077         result = USB_disk_status();
00078         // translate the reslut code here
00079 
00080         return stat;
00081     }
00082     return STA_NOINIT;
00083 }
00084 
00085 
00086 
00087 /*-----------------------------------------------------------------------*/
00088 /* Read Sector(s)                                                        */
00089 
00090 DRESULT disk_read (
00091     BYTE drv,       /* Physical drive nmuber (0..) */
00092     BYTE *buff,     /* Data buffer to store read data */
00093     DWORD sector,   /* Sector address (LBA) */
00094     BYTE count      /* Number of sectors to read (1..255) */
00095 )
00096 {
00097     DRESULT res;
00098     int result;
00099 
00100     switch (drv) {
00101     case ATA :
00102         result = ATA_disk_read(buff, sector, count);
00103         // translate the reslut code here
00104 
00105         return res;
00106 
00107     case MMC :
00108         result = MMC_disk_read(buff, sector, count);
00109         // translate the reslut code here
00110 
00111         return res;
00112 
00113     case USB :
00114         result = USB_disk_read(buff, sector, count);
00115         // translate the reslut code here
00116 
00117         return res;
00118     }
00119     return RES_PARERR;
00120 }
00121 
00122 
00123 
00124 /*-----------------------------------------------------------------------*/
00125 /* Write Sector(s)                                                       */
00126 
00127 #if _READONLY == 0
00128 DRESULT disk_write (
00129     BYTE drv,           /* Physical drive nmuber (0..) */
00130     const BYTE *buff,   /* Data to be written */
00131     DWORD sector,       /* Sector address (LBA) */
00132     BYTE count          /* Number of sectors to write (1..255) */
00133 )
00134 {
00135     DRESULT res;
00136     int result;
00137 
00138     switch (drv) {
00139     case ATA :
00140         result = ATA_disk_write(buff, sector, count);
00141         // translate the reslut code here
00142 
00143         return res;
00144 
00145     case MMC :
00146         result = MMC_disk_write(buff, sector, count);
00147         // translate the reslut code here
00148 
00149         return res;
00150 
00151     case USB :
00152         result = USB_disk_write(buff, sector, count);
00153         // translate the reslut code here
00154 
00155         return res;
00156     }
00157     return RES_PARERR;
00158 }
00159 #endif /* _READONLY */
00160 
00161 
00162 
00163 /*-----------------------------------------------------------------------*/
00164 /* Miscellaneous Functions                                               */
00165 
00166 DRESULT disk_ioctl (
00167     BYTE drv,       /* Physical drive nmuber (0..) */
00168     BYTE ctrl,      /* Control code */
00169     void *buff      /* Buffer to send/receive control data */
00170 )
00171 {
00172     DRESULT res;
00173     int result;
00174 
00175     switch (drv) {
00176     case ATA :
00177         // pre-process here
00178 
00179         result = ATA_disk_ioctl(ctrl, buff);
00180         // post-process here
00181 
00182         return res;
00183 
00184     case MMC :
00185         // pre-process here
00186 
00187         result = MMC_disk_ioctl(ctrl, buff);
00188         // post-process here
00189 
00190         return res;
00191 
00192     case USB :
00193         // pre-process here
00194 
00195         result = USB_disk_ioctl(ctrl, buff);
00196         // post-process here
00197 
00198         return res;
00199     }
00200     return RES_PARERR;
00201 }
00202