diskio.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*-----------------------------------------------------------------------*/
  2. /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
  3. /*-----------------------------------------------------------------------*/
  4. /* If a working storage control module is available, it should be */
  5. /* attached to the FatFs via a glue function rather than modifying it. */
  6. /* This is an example of glue functions to attach various exsisting */
  7. /* storage control modules to the FatFs module with a defined API. */
  8. /*-----------------------------------------------------------------------*/
  9. #include "diskio.h" /* FatFs lower layer API */
  10. #include "usbdisk.h" /* Example: USB drive control */
  11. #include "atadrive.h" /* Example: ATA drive control */
  12. #include "sdcard.h" /* Example: MMC/SDC contorl */
  13. /* Definitions of physical drive number for each drive */
  14. #define ATA 0 /* Example: Map ATA drive to drive number 0 */
  15. #define MMC 1 /* Example: Map MMC/SD card to drive number 1 */
  16. #define USB 2 /* Example: Map USB drive to drive number 2 */
  17. /*-----------------------------------------------------------------------*/
  18. /* Get Drive Status */
  19. /*-----------------------------------------------------------------------*/
  20. DSTATUS disk_status (
  21. BYTE pdrv /* Physical drive nmuber to identify the drive */
  22. )
  23. {
  24. DSTATUS stat;
  25. int result;
  26. switch (pdrv) {
  27. case ATA :
  28. result = ATA_disk_status();
  29. // translate the reslut code here
  30. return stat;
  31. case MMC :
  32. result = MMC_disk_status();
  33. // translate the reslut code here
  34. return stat;
  35. case USB :
  36. result = USB_disk_status();
  37. // translate the reslut code here
  38. return stat;
  39. }
  40. return STA_NOINIT;
  41. }
  42. /*-----------------------------------------------------------------------*/
  43. /* Inidialize a Drive */
  44. /*-----------------------------------------------------------------------*/
  45. DSTATUS disk_initialize (
  46. BYTE pdrv /* Physical drive nmuber to identify the drive */
  47. )
  48. {
  49. DSTATUS stat;
  50. int result;
  51. switch (pdrv) {
  52. case ATA :
  53. result = ATA_disk_initialize();
  54. // translate the reslut code here
  55. return stat;
  56. case MMC :
  57. result = MMC_disk_initialize();
  58. // translate the reslut code here
  59. return stat;
  60. case USB :
  61. result = USB_disk_initialize();
  62. // translate the reslut code here
  63. return stat;
  64. }
  65. return STA_NOINIT;
  66. }
  67. /*-----------------------------------------------------------------------*/
  68. /* Read Sector(s) */
  69. /*-----------------------------------------------------------------------*/
  70. DRESULT disk_read (
  71. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  72. BYTE *buff, /* Data buffer to store read data */
  73. DWORD sector, /* Sector address in LBA */
  74. UINT count /* Number of sectors to read */
  75. )
  76. {
  77. DRESULT res;
  78. int result;
  79. switch (pdrv) {
  80. case ATA :
  81. // translate the arguments here
  82. result = ATA_disk_read(buff, sector, count);
  83. // translate the reslut code here
  84. return res;
  85. case MMC :
  86. // translate the arguments here
  87. result = MMC_disk_read(buff, sector, count);
  88. // translate the reslut code here
  89. return res;
  90. case USB :
  91. // translate the arguments here
  92. result = USB_disk_read(buff, sector, count);
  93. // translate the reslut code here
  94. return res;
  95. }
  96. return RES_PARERR;
  97. }
  98. /*-----------------------------------------------------------------------*/
  99. /* Write Sector(s) */
  100. /*-----------------------------------------------------------------------*/
  101. #if _USE_WRITE
  102. DRESULT disk_write (
  103. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  104. const BYTE *buff, /* Data to be written */
  105. DWORD sector, /* Sector address in LBA */
  106. UINT count /* Number of sectors to write */
  107. )
  108. {
  109. DRESULT res;
  110. int result;
  111. switch (pdrv) {
  112. case ATA :
  113. // translate the arguments here
  114. result = ATA_disk_write(buff, sector, count);
  115. // translate the reslut code here
  116. return res;
  117. case MMC :
  118. // translate the arguments here
  119. result = MMC_disk_write(buff, sector, count);
  120. // translate the reslut code here
  121. return res;
  122. case USB :
  123. // translate the arguments here
  124. result = USB_disk_write(buff, sector, count);
  125. // translate the reslut code here
  126. return res;
  127. }
  128. return RES_PARERR;
  129. }
  130. #endif
  131. /*-----------------------------------------------------------------------*/
  132. /* Miscellaneous Functions */
  133. /*-----------------------------------------------------------------------*/
  134. #if _USE_IOCTL
  135. DRESULT disk_ioctl (
  136. BYTE pdrv, /* Physical drive nmuber (0..) */
  137. BYTE cmd, /* Control code */
  138. void *buff /* Buffer to send/receive control data */
  139. )
  140. {
  141. DRESULT res;
  142. int result;
  143. switch (pdrv) {
  144. case ATA :
  145. // Process of the command for the ATA drive
  146. return res;
  147. case MMC :
  148. // Process of the command for the MMC/SD card
  149. return res;
  150. case USB :
  151. // Process of the command the USB drive
  152. return res;
  153. }
  154. return RES_PARERR;
  155. }
  156. #endif