| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,151 @@ |
| 1 |
+/** |
|
| 2 |
+ ****************************************************************************** |
|
| 3 |
+ * @file ff_gen_drv.c |
|
| 4 |
+ * @author MCD Application Team |
|
| 5 |
+ * @version V1.4.1 |
|
| 6 |
+ * @date 14-February-2017 |
|
| 7 |
+ * @brief FatFs generic low level driver. |
|
| 8 |
+ ****************************************************************************** |
|
| 9 |
+ * @attention |
|
| 10 |
+ * |
|
| 11 |
+ * <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2> |
|
| 12 |
+ * |
|
| 13 |
+ * Redistribution and use in source and binary forms, with or without |
|
| 14 |
+ * modification, are permitted, provided that the following conditions are met: |
|
| 15 |
+ * |
|
| 16 |
+ * 1. Redistribution of source code must retain the above copyright notice, |
|
| 17 |
+ * this list of conditions and the following disclaimer. |
|
| 18 |
+ * 2. Redistributions in binary form must reproduce the above copyright notice, |
|
| 19 |
+ * this list of conditions and the following disclaimer in the documentation |
|
| 20 |
+ * and/or other materials provided with the distribution. |
|
| 21 |
+ * 3. Neither the name of STMicroelectronics nor the names of other |
|
| 22 |
+ * contributors to this software may be used to endorse or promote products |
|
| 23 |
+ * derived from this software without specific written permission. |
|
| 24 |
+ * 4. This software, including modifications and/or derivative works of this |
|
| 25 |
+ * software, must execute solely and exclusively on microcontroller or |
|
| 26 |
+ * microprocessor devices manufactured by or for STMicroelectronics. |
|
| 27 |
+ * 5. Redistribution and use of this software other than as permitted under |
|
| 28 |
+ * this license is void and will automatically terminate your rights under |
|
| 29 |
+ * this license. |
|
| 30 |
+ * |
|
| 31 |
+ * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" |
|
| 32 |
+ * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT |
|
| 33 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
|
| 34 |
+ * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY |
|
| 35 |
+ * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT |
|
| 36 |
+ * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
| 37 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
| 38 |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
|
| 39 |
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
| 40 |
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
| 41 |
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
| 42 |
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
| 43 |
+ * |
|
| 44 |
+ ****************************************************************************** |
|
| 45 |
+ */ |
|
| 46 |
+ |
|
| 47 |
+/* Includes ------------------------------------------------------------------*/ |
|
| 48 |
+#include "ff_gen_drv.h" |
|
| 49 |
+ |
|
| 50 |
+/* Private typedef -----------------------------------------------------------*/ |
|
| 51 |
+/* Private define ------------------------------------------------------------*/ |
|
| 52 |
+/* Private variables ---------------------------------------------------------*/ |
|
| 53 |
+Disk_drvTypeDef disk = {{0},{0},{0},0};
|
|
| 54 |
+ |
|
| 55 |
+/* Private function prototypes -----------------------------------------------*/ |
|
| 56 |
+/* Private functions ---------------------------------------------------------*/ |
|
| 57 |
+ |
|
| 58 |
+/** |
|
| 59 |
+ * @brief Links a compatible diskio driver/lun id and increments the number of active |
|
| 60 |
+ * linked drivers. |
|
| 61 |
+ * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits. |
|
| 62 |
+ * @param drv: pointer to the disk IO Driver structure |
|
| 63 |
+ * @param path: pointer to the logical drive path |
|
| 64 |
+ * @param lun : only used for USB Key Disk to add multi-lun management |
|
| 65 |
+ else the paramter must be equal to 0 |
|
| 66 |
+ * @retval Returns 0 in case of success, otherwise 1. |
|
| 67 |
+ */ |
|
| 68 |
+uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, uint8_t lun) |
|
| 69 |
+{
|
|
| 70 |
+ uint8_t ret = 1; |
|
| 71 |
+ uint8_t DiskNum = 0; |
|
| 72 |
+ |
|
| 73 |
+ if(disk.nbr <= _VOLUMES) |
|
| 74 |
+ {
|
|
| 75 |
+ disk.is_initialized[disk.nbr] = 0; |
|
| 76 |
+ disk.drv[disk.nbr] = drv; |
|
| 77 |
+ disk.lun[disk.nbr] = lun; |
|
| 78 |
+ DiskNum = disk.nbr++; |
|
| 79 |
+ path[0] = DiskNum + '0'; |
|
| 80 |
+ path[1] = ':'; |
|
| 81 |
+ path[2] = '/'; |
|
| 82 |
+ path[3] = 0; |
|
| 83 |
+ ret = 0; |
|
| 84 |
+ } |
|
| 85 |
+ |
|
| 86 |
+ return ret; |
|
| 87 |
+} |
|
| 88 |
+ |
|
| 89 |
+/** |
|
| 90 |
+ * @brief Links a compatible diskio driver and increments the number of active |
|
| 91 |
+ * linked drivers. |
|
| 92 |
+ * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits |
|
| 93 |
+ * @param drv: pointer to the disk IO Driver structure |
|
| 94 |
+ * @param path: pointer to the logical drive path |
|
| 95 |
+ * @retval Returns 0 in case of success, otherwise 1. |
|
| 96 |
+ */ |
|
| 97 |
+uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path) |
|
| 98 |
+{
|
|
| 99 |
+ return FATFS_LinkDriverEx(drv, path, 0); |
|
| 100 |
+} |
|
| 101 |
+ |
|
| 102 |
+/** |
|
| 103 |
+ * @brief Unlinks a diskio driver and decrements the number of active linked |
|
| 104 |
+ * drivers. |
|
| 105 |
+ * @param path: pointer to the logical drive path |
|
| 106 |
+ * @param lun : not used |
|
| 107 |
+ * @retval Returns 0 in case of success, otherwise 1. |
|
| 108 |
+ */ |
|
| 109 |
+uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun) |
|
| 110 |
+{
|
|
| 111 |
+ uint8_t DiskNum = 0; |
|
| 112 |
+ uint8_t ret = 1; |
|
| 113 |
+ |
|
| 114 |
+ if(disk.nbr >= 1) |
|
| 115 |
+ {
|
|
| 116 |
+ DiskNum = path[0] - '0'; |
|
| 117 |
+ if(disk.drv[DiskNum] != 0) |
|
| 118 |
+ {
|
|
| 119 |
+ disk.drv[DiskNum] = 0; |
|
| 120 |
+ disk.lun[DiskNum] = 0; |
|
| 121 |
+ disk.nbr--; |
|
| 122 |
+ ret = 0; |
|
| 123 |
+ } |
|
| 124 |
+ } |
|
| 125 |
+ |
|
| 126 |
+ return ret; |
|
| 127 |
+} |
|
| 128 |
+ |
|
| 129 |
+/** |
|
| 130 |
+ * @brief Unlinks a diskio driver and decrements the number of active linked |
|
| 131 |
+ * drivers. |
|
| 132 |
+ * @param path: pointer to the logical drive path |
|
| 133 |
+ * @retval Returns 0 in case of success, otherwise 1. |
|
| 134 |
+ */ |
|
| 135 |
+uint8_t FATFS_UnLinkDriver(char *path) |
|
| 136 |
+{
|
|
| 137 |
+ return FATFS_UnLinkDriverEx(path, 0); |
|
| 138 |
+} |
|
| 139 |
+ |
|
| 140 |
+/** |
|
| 141 |
+ * @brief Gets number of linked drivers to the FatFs module. |
|
| 142 |
+ * @param None |
|
| 143 |
+ * @retval Number of attached drivers. |
|
| 144 |
+ */ |
|
| 145 |
+uint8_t FATFS_GetAttachedDriversNbr(void) |
|
| 146 |
+{
|
|
| 147 |
+ return disk.nbr; |
|
| 148 |
+} |
|
| 149 |
+ |
|
| 150 |
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
|
| 151 |
+ |