diskio.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. /**
  13. ******************************************************************************
  14. *
  15. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
  16. * All rights reserved.</center></h2>
  17. *
  18. * Redistribution and use in source and binary forms, with or without
  19. * modification, are permitted, provided that the following conditions are met:
  20. *
  21. * 1. Redistribution of source code must retain the above copyright notice,
  22. * this list of conditions and the following disclaimer.
  23. * 2. Redistributions in binary form must reproduce the above copyright notice,
  24. * this list of conditions and the following disclaimer in the documentation
  25. * and/or other materials provided with the distribution.
  26. * 3. Neither the name of STMicroelectronics nor the names of other
  27. * contributors to this software may be used to endorse or promote products
  28. * derived from this software without specific written permission.
  29. * 4. This software, including modifications and/or derivative works of this
  30. * software, must execute solely and exclusively on microcontroller or
  31. * microprocessor devices manufactured by or for STMicroelectronics.
  32. * 5. Redistribution and use of this software other than as permitted under
  33. * this license is void and will automatically terminate your rights under
  34. * this license.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  37. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  39. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  40. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  41. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  42. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  44. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  45. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  46. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  47. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48. *
  49. ******************************************************************************
  50. */
  51. /* Includes ------------------------------------------------------------------*/
  52. #include "diskio.h"
  53. #include "ff_gen_drv.h"
  54. #if defined ( __GNUC__ )
  55. #ifndef __weak
  56. #define __weak __attribute__((weak))
  57. #endif
  58. #endif
  59. /* Private typedef -----------------------------------------------------------*/
  60. /* Private define ------------------------------------------------------------*/
  61. /* Private variables ---------------------------------------------------------*/
  62. extern Disk_drvTypeDef disk;
  63. /* Private function prototypes -----------------------------------------------*/
  64. /* Private functions ---------------------------------------------------------*/
  65. /**
  66. * @brief Gets Disk Status
  67. * @param pdrv: Physical drive number (0..)
  68. * @retval DSTATUS: Operation status
  69. */
  70. DSTATUS disk_status (
  71. BYTE pdrv /* Physical drive number to identify the drive */
  72. )
  73. {
  74. DSTATUS stat;
  75. stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
  76. return stat;
  77. }
  78. /**
  79. * @brief Initializes a Drive
  80. * @param pdrv: Physical drive number (0..)
  81. * @retval DSTATUS: Operation status
  82. */
  83. DSTATUS disk_initialize (
  84. BYTE pdrv /* Physical drive nmuber to identify the drive */
  85. )
  86. {
  87. DSTATUS stat = RES_OK;
  88. if(disk.is_initialized[pdrv] == 0)
  89. {
  90. disk.is_initialized[pdrv] = 1;
  91. stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
  92. }
  93. return stat;
  94. }
  95. /**
  96. * @brief Reads Sector(s)
  97. * @param pdrv: Physical drive number (0..)
  98. * @param *buff: Data buffer to store read data
  99. * @param sector: Sector address (LBA)
  100. * @param count: Number of sectors to read (1..128)
  101. * @retval DRESULT: Operation result
  102. */
  103. DRESULT disk_read (
  104. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  105. BYTE *buff, /* Data buffer to store read data */
  106. DWORD sector, /* Sector address in LBA */
  107. UINT count /* Number of sectors to read */
  108. )
  109. {
  110. DRESULT res;
  111. res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
  112. return res;
  113. }
  114. /**
  115. * @brief Writes Sector(s)
  116. * @param pdrv: Physical drive number (0..)
  117. * @param *buff: Data to be written
  118. * @param sector: Sector address (LBA)
  119. * @param count: Number of sectors to write (1..128)
  120. * @retval DRESULT: Operation result
  121. */
  122. #if _USE_WRITE == 1
  123. DRESULT disk_write (
  124. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  125. const BYTE *buff, /* Data to be written */
  126. DWORD sector, /* Sector address in LBA */
  127. UINT count /* Number of sectors to write */
  128. )
  129. {
  130. DRESULT res;
  131. res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
  132. return res;
  133. }
  134. #endif /* _USE_WRITE == 1 */
  135. /**
  136. * @brief I/O control operation
  137. * @param pdrv: Physical drive number (0..)
  138. * @param cmd: Control code
  139. * @param *buff: Buffer to send/receive control data
  140. * @retval DRESULT: Operation result
  141. */
  142. #if _USE_IOCTL == 1
  143. DRESULT disk_ioctl (
  144. BYTE pdrv, /* Physical drive nmuber (0..) */
  145. BYTE cmd, /* Control code */
  146. void *buff /* Buffer to send/receive control data */
  147. )
  148. {
  149. DRESULT res;
  150. res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
  151. return res;
  152. }
  153. #endif /* _USE_IOCTL == 1 */
  154. /**
  155. * @brief Gets Time from RTC
  156. * @param None
  157. * @retval Time in DWORD
  158. */
  159. __weak DWORD get_fattime (void)
  160. {
  161. return 0;
  162. }
  163. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/