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.

ff_gen_drv.c 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. ******************************************************************************
  3. * @file ff_gen_drv.c
  4. * @author MCD Application Team
  5. * @brief FatFs generic low level driver.
  6. *****************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics. All rights reserved.
  10. *
  11. * This software component is licensed by ST under BSD 3-Clause license,
  12. * the "License"; You may not use this file except in compliance with the
  13. * License. You may obtain a copy of the License at:
  14. * opensource.org/licenses/BSD-3-Clause
  15. *
  16. ******************************************************************************
  17. **/
  18. /* Includes ------------------------------------------------------------------*/
  19. #include "ff_gen_drv.h"
  20. /* Private typedef -----------------------------------------------------------*/
  21. /* Private define ------------------------------------------------------------*/
  22. /* Private variables ---------------------------------------------------------*/
  23. Disk_drvTypeDef disk = {{0},{0},{0},0};
  24. /* Private function prototypes -----------------------------------------------*/
  25. /* Private functions ---------------------------------------------------------*/
  26. /**
  27. * @brief Links a compatible diskio driver/lun id and increments the number of active
  28. * linked drivers.
  29. * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits.
  30. * @param drv: pointer to the disk IO Driver structure
  31. * @param path: pointer to the logical drive path
  32. * @param lun : only used for USB Key Disk to add multi-lun management
  33. else the parameter must be equal to 0
  34. * @retval Returns 0 in case of success, otherwise 1.
  35. */
  36. uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, uint8_t lun)
  37. {
  38. uint8_t ret = 1;
  39. uint8_t DiskNum = 0;
  40. if(disk.nbr < _VOLUMES)
  41. {
  42. disk.is_initialized[disk.nbr] = 0;
  43. disk.drv[disk.nbr] = drv;
  44. disk.lun[disk.nbr] = lun;
  45. DiskNum = disk.nbr++;
  46. path[0] = DiskNum + '0';
  47. path[1] = ':';
  48. path[2] = '/';
  49. path[3] = 0;
  50. ret = 0;
  51. }
  52. return ret;
  53. }
  54. /**
  55. * @brief Links a compatible diskio driver and increments the number of active
  56. * linked drivers.
  57. * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits
  58. * @param drv: pointer to the disk IO Driver structure
  59. * @param path: pointer to the logical drive path
  60. * @retval Returns 0 in case of success, otherwise 1.
  61. */
  62. uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path)
  63. {
  64. return FATFS_LinkDriverEx(drv, path, 0);
  65. }
  66. /**
  67. * @brief Unlinks a diskio driver and decrements the number of active linked
  68. * drivers.
  69. * @param path: pointer to the logical drive path
  70. * @param lun : not used
  71. * @retval Returns 0 in case of success, otherwise 1.
  72. */
  73. uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
  74. {
  75. uint8_t DiskNum = 0;
  76. uint8_t ret = 1;
  77. if(disk.nbr >= 1)
  78. {
  79. DiskNum = path[0] - '0';
  80. if(disk.drv[DiskNum] != 0)
  81. {
  82. disk.drv[DiskNum] = 0;
  83. disk.lun[DiskNum] = 0;
  84. disk.nbr--;
  85. ret = 0;
  86. }
  87. }
  88. return ret;
  89. }
  90. /**
  91. * @brief Unlinks a diskio driver and decrements the number of active linked
  92. * drivers.
  93. * @param path: pointer to the logical drive path
  94. * @retval Returns 0 in case of success, otherwise 1.
  95. */
  96. uint8_t FATFS_UnLinkDriver(char *path)
  97. {
  98. return FATFS_UnLinkDriverEx(path, 0);
  99. }
  100. /**
  101. * @brief Gets number of linked drivers to the FatFs module.
  102. * @param None
  103. * @retval Number of attached drivers.
  104. */
  105. uint8_t FATFS_GetAttachedDriversNbr(void)
  106. {
  107. return disk.nbr;
  108. }
  109. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/