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.

diskio.c 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*-----------------------------------------------------------------------*/
  2. /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2017 */
  3. /* */
  4. /* Portions COPYRIGHT 2017 STMicroelectronics */
  5. /* Portions Copyright (C) 2017, ChaN, all right reserved */
  6. /*-----------------------------------------------------------------------*/
  7. /* If a working storage control module is available, it should be */
  8. /* attached to the FatFs via a glue function rather than modifying it. */
  9. /* This is an example of glue functions to attach various existing */
  10. /* storage control modules to the FatFs module with a defined API. */
  11. /*-----------------------------------------------------------------------*/
  12. /* Includes ------------------------------------------------------------------*/
  13. #include "diskio.h"
  14. #include "ff_gen_drv.h"
  15. #if defined ( __GNUC__ )
  16. #ifndef __weak
  17. #define __weak __attribute__((weak))
  18. #endif
  19. #endif
  20. /* Private typedef -----------------------------------------------------------*/
  21. /* Private define ------------------------------------------------------------*/
  22. /* Private variables ---------------------------------------------------------*/
  23. extern Disk_drvTypeDef disk;
  24. /* Private function prototypes -----------------------------------------------*/
  25. /* Private functions ---------------------------------------------------------*/
  26. /**
  27. * @brief Gets Disk Status
  28. * @param pdrv: Physical drive number (0..)
  29. * @retval DSTATUS: Operation status
  30. */
  31. DSTATUS disk_status (
  32. BYTE pdrv /* Physical drive number to identify the drive */
  33. )
  34. {
  35. DSTATUS stat;
  36. stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
  37. return stat;
  38. }
  39. /**
  40. * @brief Initializes a Drive
  41. * @param pdrv: Physical drive number (0..)
  42. * @retval DSTATUS: Operation status
  43. */
  44. DSTATUS disk_initialize (
  45. BYTE pdrv /* Physical drive nmuber to identify the drive */
  46. )
  47. {
  48. DSTATUS stat = RES_OK;
  49. if(disk.is_initialized[pdrv] == 0)
  50. {
  51. disk.is_initialized[pdrv] = 1;
  52. stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
  53. }
  54. return stat;
  55. }
  56. /**
  57. * @brief Reads Sector(s)
  58. * @param pdrv: Physical drive number (0..)
  59. * @param *buff: Data buffer to store read data
  60. * @param sector: Sector address (LBA)
  61. * @param count: Number of sectors to read (1..128)
  62. * @retval DRESULT: Operation result
  63. */
  64. DRESULT disk_read (
  65. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  66. BYTE *buff, /* Data buffer to store read data */
  67. DWORD sector, /* Sector address in LBA */
  68. UINT count /* Number of sectors to read */
  69. )
  70. {
  71. DRESULT res;
  72. res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
  73. return res;
  74. }
  75. /**
  76. * @brief Writes Sector(s)
  77. * @param pdrv: Physical drive number (0..)
  78. * @param *buff: Data to be written
  79. * @param sector: Sector address (LBA)
  80. * @param count: Number of sectors to write (1..128)
  81. * @retval DRESULT: Operation result
  82. */
  83. #if _USE_WRITE == 1
  84. DRESULT disk_write (
  85. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  86. const BYTE *buff, /* Data to be written */
  87. DWORD sector, /* Sector address in LBA */
  88. UINT count /* Number of sectors to write */
  89. )
  90. {
  91. DRESULT res;
  92. res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
  93. return res;
  94. }
  95. #endif /* _USE_WRITE == 1 */
  96. /**
  97. * @brief I/O control operation
  98. * @param pdrv: Physical drive number (0..)
  99. * @param cmd: Control code
  100. * @param *buff: Buffer to send/receive control data
  101. * @retval DRESULT: Operation result
  102. */
  103. #if _USE_IOCTL == 1
  104. DRESULT disk_ioctl (
  105. BYTE pdrv, /* Physical drive nmuber (0..) */
  106. BYTE cmd, /* Control code */
  107. void *buff /* Buffer to send/receive control data */
  108. )
  109. {
  110. DRESULT res;
  111. res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
  112. return res;
  113. }
  114. #endif /* _USE_IOCTL == 1 */
  115. /**
  116. * @brief Gets Time from RTC
  117. * @param None
  118. * @retval Time in DWORD
  119. */
  120. __weak DWORD get_fattime (void)
  121. {
  122. return 0;
  123. }
  124. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/