Huseyin Buyukesmeli / FatFS

Dependents:   DISCO-F746NG_uSD Active-WolfMan_V2-5-All-Frank-Board-Functions_copy DISCO-F746NG_uSD DISCO-F746NG_uSD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ff_gen_drv.c Source File

ff_gen_drv.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    ff_gen_drv.c 
00004   * @author  MCD Application Team
00005   * @version V1.4.0
00006   * @date    23-December-2016
00007   * @brief   FatFs generic low level driver.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without 
00014   * modification, are permitted, provided that the following conditions are met:
00015   *
00016   * 1. Redistribution of source code must retain the above copyright notice, 
00017   *    this list of conditions and the following disclaimer.
00018   * 2. Redistributions in binary form must reproduce the above copyright notice,
00019   *    this list of conditions and the following disclaimer in the documentation
00020   *    and/or other materials provided with the distribution.
00021   * 3. Neither the name of STMicroelectronics nor the names of other 
00022   *    contributors to this software may be used to endorse or promote products 
00023   *    derived from this software without specific written permission.
00024   * 4. This software, including modifications and/or derivative works of this 
00025   *    software, must execute solely and exclusively on microcontroller or
00026   *    microprocessor devices manufactured by or for STMicroelectronics.
00027   * 5. Redistribution and use of this software other than as permitted under 
00028   *    this license is void and will automatically terminate your rights under 
00029   *    this license. 
00030   *
00031   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 
00032   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 
00033   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
00034   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
00035   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 
00036   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00037   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00038   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
00039   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
00040   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
00041   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00042   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00043   *
00044   ******************************************************************************
00045   */ 
00046 
00047 /* Includes ------------------------------------------------------------------*/
00048 #include "ff_gen_drv.h"
00049 
00050 /* Private typedef -----------------------------------------------------------*/
00051 /* Private define ------------------------------------------------------------*/
00052 /* Private variables ---------------------------------------------------------*/
00053 Disk_drvTypeDef disk = {{0},{0},{0},0};
00054 
00055 /* Private function prototypes -----------------------------------------------*/
00056 /* Private functions ---------------------------------------------------------*/
00057 
00058 /**
00059   * @brief  Links a compatible diskio driver/lun id and increments the number of active
00060   *         linked drivers.
00061   * @note   The number of linked drivers (volumes) is up to 10 due to FatFs limits.
00062   * @param  drv: pointer to the disk IO Driver structure
00063   * @param  path: pointer to the logical drive path 
00064   * @param  lun : only used for USB Key Disk to add multi-lun management
00065             else the paramter must be equal to 0
00066   * @retval Returns 0 in case of success, otherwise 1.
00067   */
00068 uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, uint8_t lun)
00069 {
00070   uint8_t ret = 1;
00071   uint8_t DiskNum = 0;
00072   
00073   if(disk.nbr <= _VOLUMES)
00074   {
00075     disk.is_initialized[disk.nbr] = 0;
00076     disk.drv[disk.nbr] = drv;  
00077     disk.lun[disk.nbr] = lun;  
00078     DiskNum = disk.nbr++;
00079     path[0] = DiskNum + '0';
00080     path[1] = ':';
00081     path[2] = '/';
00082     path[3] = 0;
00083     ret = 0;
00084   }
00085   
00086   return ret;
00087 }
00088 
00089 /**
00090   * @brief  Links a compatible diskio driver and increments the number of active
00091   *         linked drivers.          
00092   * @note   The number of linked drivers (volumes) is up to 10 due to FatFs limits
00093   * @param  drv: pointer to the disk IO Driver structure
00094   * @param  path: pointer to the logical drive path 
00095   * @retval Returns 0 in case of success, otherwise 1.
00096   */
00097 uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path)
00098 {
00099   return FATFS_LinkDriverEx(drv, path, 0);
00100 }
00101 
00102 /**
00103   * @brief  Unlinks a diskio driver and decrements the number of active linked
00104   *         drivers.
00105   * @param  path: pointer to the logical drive path  
00106   * @param  lun : not used   
00107   * @retval Returns 0 in case of success, otherwise 1.
00108   */
00109 uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
00110 { 
00111   uint8_t DiskNum = 0;
00112   uint8_t ret = 1;
00113   
00114   if(disk.nbr >= 1)
00115   {    
00116     DiskNum = path[0] - '0';
00117     if(disk.drv[DiskNum] != 0)
00118     {
00119       disk.drv[DiskNum] = 0;
00120       disk.lun[DiskNum] = 0;
00121       disk.nbr--;
00122       ret = 0;
00123     }
00124   }
00125   
00126   return ret;
00127 }
00128 
00129 /**
00130   * @brief  Unlinks a diskio driver and decrements the number of active linked
00131   *         drivers.
00132   * @param  path: pointer to the logical drive path  
00133   * @retval Returns 0 in case of success, otherwise 1.
00134   */
00135 uint8_t FATFS_UnLinkDriver(char *path)
00136 { 
00137   return FATFS_UnLinkDriverEx(path, 0);
00138 }
00139 
00140 /**
00141   * @brief  Gets number of linked drivers to the FatFs module.
00142   * @param  None
00143   * @retval Number of attached drivers.
00144   */
00145 uint8_t FATFS_GetAttachedDriversNbr(void)
00146 {
00147   return disk.nbr;
00148 }
00149  
00150 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00151