diskio.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "ff.h" /* Obtains integer types */
  10. #include "diskio.h" /* FatFs lower layer API */
  11. #include "sdcard.h"
  12. static DSTATUS m_status = STA_NOINIT;
  13. /*-----------------------------------------------------------------------*/
  14. /* Get Drive Status */
  15. /*-----------------------------------------------------------------------*/
  16. DSTATUS disk_status (
  17. BYTE pdrv /* Physical drive nmuber to identify the drive */
  18. )
  19. {
  20. return m_status;
  21. }
  22. /*-----------------------------------------------------------------------*/
  23. /* Inidialize a Drive */
  24. /*-----------------------------------------------------------------------*/
  25. DSTATUS disk_initialize (
  26. BYTE pdrv /* Physical drive nmuber to identify the drive */
  27. )
  28. {
  29. int result;
  30. if (platform_sdcard_init( 1, pdrv )) {
  31. m_status &= ~STA_NOINIT;
  32. }
  33. return m_status;
  34. }
  35. /*-----------------------------------------------------------------------*/
  36. /* Read Sector(s) */
  37. /*-----------------------------------------------------------------------*/
  38. DRESULT disk_read (
  39. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  40. BYTE *buff, /* Data buffer to store read data */
  41. DWORD sector, /* Sector address in LBA */
  42. UINT count /* Number of sectors to read */
  43. )
  44. {
  45. if (count == 1) {
  46. if (! platform_sdcard_read_block( pdrv, sector, buff )) {
  47. return RES_ERROR;
  48. }
  49. } else {
  50. if (! platform_sdcard_read_blocks( pdrv, sector, count, buff )) {
  51. return RES_ERROR;
  52. }
  53. }
  54. return RES_OK;
  55. }
  56. /*-----------------------------------------------------------------------*/
  57. /* Write Sector(s) */
  58. /*-----------------------------------------------------------------------*/
  59. #if FF_FS_READONLY == 0
  60. DRESULT disk_write (
  61. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  62. const BYTE *buff, /* Data to be written */
  63. DWORD sector, /* Sector address in LBA */
  64. UINT count /* Number of sectors to write */
  65. )
  66. {
  67. if (count == 1) {
  68. if (! platform_sdcard_write_block( pdrv, sector, buff )) {
  69. return RES_ERROR;
  70. }
  71. } else {
  72. if (! platform_sdcard_write_blocks( pdrv, sector, count, buff )) {
  73. return RES_ERROR;
  74. }
  75. }
  76. return RES_OK;
  77. }
  78. #endif
  79. /*-----------------------------------------------------------------------*/
  80. /* Miscellaneous Functions */
  81. /*-----------------------------------------------------------------------*/
  82. DRESULT disk_ioctl (
  83. BYTE pdrv, /* Physical drive nmuber (0..) */
  84. BYTE cmd, /* Control code */
  85. void *buff /* Buffer to send/receive control data */
  86. )
  87. {
  88. switch (cmd) {
  89. case CTRL_TRIM: /* no-op */
  90. case CTRL_SYNC: /* no-op */
  91. return RES_OK;
  92. default: /* anything else throws parameter error */
  93. return RES_PARERR;
  94. }
  95. }