diskio.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*-----------------------------------------------------------------------*/
  2. /* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */
  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 "ff.h" /* Obtains integer types */
  10. #include "diskio.h" /* Declarations of disk functions */
  11. /* Definitions of physical drive number for each drive */
  12. #define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */
  13. #define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */
  14. #define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */
  15. /*-----------------------------------------------------------------------*/
  16. /* Get Drive Status */
  17. /*-----------------------------------------------------------------------*/
  18. DSTATUS disk_status (
  19. BYTE pdrv /* Physical drive nmuber to identify the drive */
  20. )
  21. {
  22. DSTATUS stat;
  23. int result;
  24. switch (pdrv) {
  25. case DEV_RAM :
  26. result = RAM_disk_status();
  27. // translate the reslut code here
  28. return stat;
  29. case DEV_MMC :
  30. result = MMC_disk_status();
  31. // translate the reslut code here
  32. return stat;
  33. case DEV_USB :
  34. result = USB_disk_status();
  35. // translate the reslut code here
  36. return stat;
  37. }
  38. return STA_NOINIT;
  39. }
  40. /*-----------------------------------------------------------------------*/
  41. /* Inidialize a Drive */
  42. /*-----------------------------------------------------------------------*/
  43. DSTATUS disk_initialize (
  44. BYTE pdrv /* Physical drive nmuber to identify the drive */
  45. )
  46. {
  47. DSTATUS stat;
  48. int result;
  49. switch (pdrv) {
  50. case DEV_RAM :
  51. result = RAM_disk_initialize();
  52. // translate the reslut code here
  53. return stat;
  54. case DEV_MMC :
  55. result = MMC_disk_initialize();
  56. // translate the reslut code here
  57. return stat;
  58. case DEV_USB :
  59. result = USB_disk_initialize();
  60. // translate the reslut code here
  61. return stat;
  62. }
  63. return STA_NOINIT;
  64. }
  65. /*-----------------------------------------------------------------------*/
  66. /* Read Sector(s) */
  67. /*-----------------------------------------------------------------------*/
  68. DRESULT disk_read (
  69. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  70. BYTE *buff, /* Data buffer to store read data */
  71. LBA_t sector, /* Start sector in LBA */
  72. UINT count /* Number of sectors to read */
  73. )
  74. {
  75. DRESULT res;
  76. int result;
  77. switch (pdrv) {
  78. case DEV_RAM :
  79. // translate the arguments here
  80. result = RAM_disk_read(buff, sector, count);
  81. // translate the reslut code here
  82. return res;
  83. case DEV_MMC :
  84. // translate the arguments here
  85. result = MMC_disk_read(buff, sector, count);
  86. // translate the reslut code here
  87. return res;
  88. case DEV_USB :
  89. // translate the arguments here
  90. result = USB_disk_read(buff, sector, count);
  91. // translate the reslut code here
  92. return res;
  93. }
  94. return RES_PARERR;
  95. }
  96. /*-----------------------------------------------------------------------*/
  97. /* Write Sector(s) */
  98. /*-----------------------------------------------------------------------*/
  99. #if FF_FS_READONLY == 0
  100. DRESULT disk_write (
  101. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  102. const BYTE *buff, /* Data to be written */
  103. LBA_t sector, /* Start sector in LBA */
  104. UINT count /* Number of sectors to write */
  105. )
  106. {
  107. DRESULT res;
  108. int result;
  109. switch (pdrv) {
  110. case DEV_RAM :
  111. // translate the arguments here
  112. result = RAM_disk_write(buff, sector, count);
  113. // translate the reslut code here
  114. return res;
  115. case DEV_MMC :
  116. // translate the arguments here
  117. result = MMC_disk_write(buff, sector, count);
  118. // translate the reslut code here
  119. return res;
  120. case DEV_USB :
  121. // translate the arguments here
  122. result = USB_disk_write(buff, sector, count);
  123. // translate the reslut code here
  124. return res;
  125. }
  126. return RES_PARERR;
  127. }
  128. #endif
  129. /*-----------------------------------------------------------------------*/
  130. /* Miscellaneous Functions */
  131. /*-----------------------------------------------------------------------*/
  132. DRESULT disk_ioctl (
  133. BYTE pdrv, /* Physical drive nmuber (0..) */
  134. BYTE cmd, /* Control code */
  135. void *buff /* Buffer to send/receive control data */
  136. )
  137. {
  138. DRESULT res;
  139. int result;
  140. switch (pdrv) {
  141. case DEV_RAM :
  142. // Process of the command for the RAM drive
  143. return res;
  144. case DEV_MMC :
  145. // Process of the command for the MMC/SD card
  146. return res;
  147. case DEV_USB :
  148. // Process of the command the USB drive
  149. return res;
  150. }
  151. return RES_PARERR;
  152. }