diskio.c 5.2 KB

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