diskio.c 3.5 KB

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