diskio.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. /*-----------------------------------------------------------------------*/
  9. /* Correspondence between physical drive number and physical drive. */
  10. #define ATA 0
  11. #define MMC 1
  12. #define USB 2
  13. /*-----------------------------------------------------------------------*/
  14. /* Inidialize a Drive */
  15. DSTATUS disk_initialize (
  16. BYTE drv /* Physical drive nmuber (0..) */
  17. )
  18. {
  19. DSTATUS stat;
  20. int result;
  21. switch (drv) {
  22. case ATA :
  23. result = ATA_disk_initialize();
  24. // translate the reslut code here
  25. return stat;
  26. case MMC :
  27. result = MMC_disk_initialize();
  28. // translate the reslut code here
  29. return stat;
  30. case USB :
  31. result = USB_disk_initialize();
  32. // translate the reslut code here
  33. return stat;
  34. }
  35. return STA_NOINIT;
  36. }
  37. /*-----------------------------------------------------------------------*/
  38. /* Return Disk Status */
  39. DSTATUS disk_status (
  40. BYTE drv /* Physical drive nmuber (0..) */
  41. )
  42. {
  43. DSTATUS stat;
  44. int result;
  45. switch (drv) {
  46. case ATA :
  47. result = ATA_disk_status();
  48. // translate the reslut code here
  49. return stat;
  50. case MMC :
  51. result = MMC_disk_status();
  52. // translate the reslut code here
  53. return stat;
  54. case USB :
  55. result = USB_disk_status();
  56. // translate the reslut code here
  57. return stat;
  58. }
  59. return STA_NOINIT;
  60. }
  61. /*-----------------------------------------------------------------------*/
  62. /* Read Sector(s) */
  63. DRESULT disk_read (
  64. BYTE drv, /* Physical drive nmuber (0..) */
  65. BYTE *buff, /* Data buffer to store read data */
  66. DWORD sector, /* Sector address (LBA) */
  67. BYTE count /* Number of sectors to read (1..255) */
  68. )
  69. {
  70. DRESULT res;
  71. int result;
  72. switch (drv) {
  73. case ATA :
  74. result = ATA_disk_read(buff, sector, count);
  75. // translate the reslut code here
  76. return res;
  77. case MMC :
  78. result = MMC_disk_read(buff, sector, count);
  79. // translate the reslut code here
  80. return res;
  81. case USB :
  82. result = USB_disk_read(buff, sector, count);
  83. // translate the reslut code here
  84. return res;
  85. }
  86. return RES_PARERR;
  87. }
  88. /*-----------------------------------------------------------------------*/
  89. /* Write Sector(s) */
  90. #if _READONLY == 0
  91. DRESULT disk_write (
  92. BYTE drv, /* Physical drive nmuber (0..) */
  93. const BYTE *buff, /* Data to be written */
  94. DWORD sector, /* Sector address (LBA) */
  95. BYTE count /* Number of sectors to write (1..255) */
  96. )
  97. {
  98. DRESULT res;
  99. int result;
  100. switch (drv) {
  101. case ATA :
  102. result = ATA_disk_write(buff, sector, count);
  103. // translate the reslut code here
  104. return res;
  105. case MMC :
  106. result = MMC_disk_write(buff, sector, count);
  107. // translate the reslut code here
  108. return res;
  109. case USB :
  110. result = USB_disk_write(buff, sector, count);
  111. // translate the reslut code here
  112. return res;
  113. }
  114. return RES_PARERR;
  115. }
  116. #endif /* _READONLY */
  117. /*-----------------------------------------------------------------------*/
  118. /* Miscellaneous Functions */
  119. DRESULT disk_ioctl (
  120. BYTE drv, /* Physical drive nmuber (0..) */
  121. BYTE ctrl, /* Control code */
  122. void *buff /* Buffer to send/receive control data */
  123. )
  124. {
  125. DRESULT res;
  126. int result;
  127. switch (drv) {
  128. case ATA :
  129. // pre-process here
  130. result = ATA_disk_ioctl(ctrl, buff);
  131. // post-process here
  132. return res;
  133. case MMC :
  134. // pre-process here
  135. result = MMC_disk_ioctl(ctrl, buff);
  136. // post-process here
  137. return res;
  138. case USB :
  139. // pre-process here
  140. result = USB_disk_ioctl(ctrl, buff);
  141. // post-process here
  142. return res;
  143. }
  144. return RES_PARERR;
  145. }