BeRTOS
|
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 #include "ff.h" 00010 00011 #include <io/kblock.h> 00012 00013 #include "cfg/cfg_fat.h" 00014 #define LOG_LEVEL FAT_LOG_LEVEL 00015 #define LOG_FORMAT FAT_LOG_FORMAT 00016 #include <cfg/log.h> 00017 00018 static KBlock *devs[_DRIVES]; 00019 00020 void disk_assignDrive(KBlock *dev, int dev_num) 00021 { 00022 ASSERT(dev_num < _DRIVES); 00023 devs[dev_num] = dev; 00024 } 00025 00026 00027 /*-----------------------------------------------------------------------*/ 00028 /* Inidialize a Drive */ 00029 00030 DSTATUS disk_initialize ( 00031 BYTE drv /* Physical drive nmuber (0..) */ 00032 ) 00033 { 00034 return disk_status(drv); 00035 } 00036 00037 00038 00039 /*-----------------------------------------------------------------------*/ 00040 /* Return Disk Status */ 00041 00042 DSTATUS disk_status ( 00043 BYTE drv /* Physical drive nmuber (0..) */ 00044 ) 00045 { 00046 KBlock *dev = devs[drv]; 00047 ASSERT(dev); 00048 00049 if (kblock_error(dev) != 0) 00050 return STA_NOINIT; 00051 else 00052 return RES_OK; 00053 } 00054 00055 00056 00057 /*-----------------------------------------------------------------------*/ 00058 /* Read Sector(s) */ 00059 00060 DRESULT disk_read ( 00061 BYTE drv, /* Physical drive nmuber (0..) */ 00062 BYTE *buff, /* Data buffer to store read data */ 00063 DWORD sector, /* Sector address (LBA) */ 00064 BYTE count /* Number of sectors to read (1..255) */ 00065 ) 00066 { 00067 KBlock *dev = devs[drv]; 00068 ASSERT(dev); 00069 00070 00071 while (count--) 00072 { 00073 if (kblock_read(dev, sector++, buff, 0, dev->blk_size) != dev->blk_size) 00074 return RES_ERROR; 00075 buff += dev->blk_size; 00076 } 00077 return RES_OK; 00078 } 00079 00080 00081 00082 /*-----------------------------------------------------------------------*/ 00083 /* Write Sector(s) */ 00084 00085 #if _READONLY == 0 00086 DRESULT disk_write ( 00087 BYTE drv, /* Physical drive nmuber (0..) */ 00088 const BYTE *buff, /* Data to be written */ 00089 DWORD sector, /* Sector address (LBA) */ 00090 BYTE count /* Number of sectors to write (1..255) */ 00091 ) 00092 { 00093 KBlock *dev = devs[drv]; 00094 ASSERT(dev); 00095 00096 while (count--) 00097 { 00098 if (kblock_write(dev, sector++, buff, 0, dev->blk_size) != dev->blk_size) 00099 return RES_ERROR; 00100 buff += dev->blk_size; 00101 } 00102 return RES_OK; 00103 } 00104 #endif /* _READONLY */ 00105 00106 00107 00108 /*-----------------------------------------------------------------------*/ 00109 /* Miscellaneous Functions */ 00110 00111 DRESULT disk_ioctl ( 00112 BYTE drv, /* Physical drive nmuber (0..) */ 00113 BYTE ctrl, /* Control code */ 00114 void *buff /* Buffer to send/receive control data */ 00115 ) 00116 { 00117 KBlock *dev = devs[drv]; 00118 ASSERT(dev); 00119 00120 00121 switch (ctrl) 00122 { 00123 case CTRL_SYNC: 00124 if (kblock_flush(dev) == 0) 00125 return RES_OK; 00126 else 00127 return RES_ERROR; 00128 00129 case GET_SECTOR_SIZE: 00130 *(WORD *)buff = dev->blk_size; 00131 return RES_OK; 00132 00133 case GET_SECTOR_COUNT: 00134 *(DWORD *)buff = dev->blk_cnt; 00135 return RES_OK; 00136 00137 case GET_BLOCK_SIZE: 00138 *(DWORD *)buff = 1; 00139 return RES_OK; 00140 00141 default: 00142 LOG_ERR("unknown command: [%d]\n", ctrl); 00143 return RES_PARERR; 00144 } 00145 } 00146 00147 00148 DWORD get_fattime(void) 00149 { 00150 return 0; 00151 } 00152 00153