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