diskio.c 5.0 KB

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