You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

226 regels
4.9 KiB

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