diskio.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*-----------------------------------------------------------------------*/
  2. /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
  3. /*-----------------------------------------------------------------------*/
  4. /* This is a stub disk I/O module that acts as front end of the existing */
  5. /* disk I/O modules and attach it to FatFs module with common interface. */
  6. /*-----------------------------------------------------------------------*/
  7. #include "diskio.h"
  8. //#include <windows.h>
  9. //#include "sdfmd.h"
  10. //#include <ethdbg.h>
  11. //#include <halether.h>
  12. //extern DWORD SDInitialize(void);
  13. //extern DWORD WriteSector(PBYTE pData, DWORD dwStartSector, DWORD dwNumber);
  14. //extern DWORD ReadSector(PBYTE pData, DWORD dwStartSector, DWORD dwNumber);
  15. //extern void Delay(UINT32 count);
  16. /*-----------------------------------------------------------------------*/
  17. /* Correspondence between physical drive number and physical drive. */
  18. /* Note that Tiny-FatFs supports only single drive and always */
  19. /* accesses drive number 0. */
  20. /*-----------------------------------------------------------------------*/
  21. /* Inidialize a Drive */
  22. DSTATUS disk_initialize (
  23. BYTE drv /* Physical drive nmuber (0..) */
  24. )
  25. {
  26. DSTATUS stat;
  27. int result;
  28. switch (drv) {
  29. /*case ATA :
  30. result = ATA_disk_initialize();
  31. // translate the reslut code here
  32. return stat;*/
  33. case SDMMC :
  34. result = MMC_disk_initialize();
  35. // translate the reslut code here
  36. if(result < 0)
  37. stat = STA_NOINIT;
  38. else
  39. stat = 0;
  40. return stat;
  41. case USB :
  42. result = USB_disk_initialize();
  43. // translate the reslut code here
  44. if(result < 0)
  45. stat = STA_NOINIT;
  46. else
  47. stat = 0;
  48. return stat;
  49. }
  50. return STA_NOINIT;
  51. }
  52. /*-----------------------------------------------------------------------*/
  53. /* Return Disk Status */
  54. DSTATUS disk_status (
  55. BYTE drv /* Physical drive nmuber (0..) */
  56. )
  57. {
  58. //drv = drv;
  59. return 0;
  60. #if 0
  61. DSTATUS stat;
  62. int result;
  63. switch (drv) {
  64. case ATA :
  65. result = ATA_disk_status();
  66. // translate the reslut code here
  67. return stat;
  68. case SDMMC :
  69. result = MMC_disk_status();
  70. // translate the reslut code here
  71. return stat;
  72. #if 0
  73. case USB :
  74. result = USB_disk_status();
  75. // translate the reslut code here
  76. return stat;
  77. #endif
  78. }
  79. return STA_NOINIT;
  80. #endif
  81. }
  82. /*-----------------------------------------------------------------------*/
  83. /* Read Sector(s) */
  84. DRESULT disk_read (
  85. BYTE drv, /* Physical drive nmuber (0..) */
  86. BYTE *buff, /* Data buffer to store read data */
  87. DWORD sector, /* Sector address (LBA) */
  88. BYTE count /* Number of sectors to read (1..255) */
  89. )
  90. {
  91. DRESULT res;
  92. int result;
  93. switch (drv) {
  94. /*case ATA :
  95. result = ATA_disk_read(buff, sector, count);
  96. // translate the reslut code here
  97. return res;*/
  98. case SDMMC :
  99. result = MMC_disk_read(buff, sector, count);
  100. // translate the reslut code here
  101. if(result == 0)
  102. res = RES_ERROR;
  103. else
  104. res = RES_OK;
  105. return res;
  106. case USB :
  107. result = USB_disk_read(buff, sector, count);
  108. // translate the reslut code here
  109. if(result == 0)
  110. res = RES_ERROR;
  111. else
  112. res = RES_OK;
  113. return res;
  114. }
  115. return RES_PARERR;
  116. }
  117. /*-----------------------------------------------------------------------*/
  118. /* Write Sector(s) */
  119. #if _READONLY == 0
  120. DRESULT disk_write (
  121. BYTE drv, /* Physical drive nmuber (0..) */
  122. const BYTE *buff, /* Data to be written */
  123. DWORD sector, /* Sector address (LBA) */
  124. BYTE count /* Number of sectors to write (1..255) */
  125. )
  126. {
  127. DRESULT res;
  128. int result;
  129. switch (drv) {
  130. case ATA :
  131. result = ATA_disk_write(buff, sector, count);
  132. // translate the reslut code here
  133. return res;
  134. case SDMMC :
  135. result = MMC_disk_write(buff, sector, count);
  136. // translate the reslut code here
  137. return res;
  138. #if 0
  139. case USB :
  140. result = USB_disk_write(buff, sector, count);
  141. // translate the reslut code here
  142. return res;
  143. #endif
  144. }
  145. return RES_PARERR;
  146. }
  147. #endif /* _READONLY */
  148. /*-----------------------------------------------------------------------*/
  149. /* Miscellaneous Functions */
  150. DRESULT disk_ioctl (
  151. BYTE drv, /* Physical drive nmuber (0..) */
  152. BYTE ctrl, /* Control code */
  153. void *buff /* Buffer to send/receive control data */
  154. )
  155. {
  156. DRESULT res;
  157. int result;
  158. switch (drv) {
  159. /*case ATA :
  160. // pre-process here
  161. result = ATA_disk_ioctl(ctrl, buff);
  162. // post-process here
  163. return res;*/
  164. case SDMMC :
  165. // pre-process here
  166. result = MMC_disk_ioctl(ctrl, buff);
  167. // post-process here
  168. if(result < 0)
  169. res = RES_PARERR;
  170. else
  171. res = RES_OK;
  172. return res;
  173. case USB :
  174. // pre-process here
  175. result = USB_disk_ioctl(ctrl, buff);
  176. if(result < 0)
  177. res = RES_PARERR;
  178. else
  179. res = RES_OK;
  180. return res;
  181. }
  182. return RES_PARERR;
  183. }