diskio.c 5.0 KB

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