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 diskio.c Source File

diskio.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------*/
00002 /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2014        */
00003 /*                                                                       */
00004 /*   Portions COPYRIGHT 2016 STMicroelectronics                          */
00005 /*   Portions Copyright (C) 2014, ChaN, all right reserved               */
00006 /*-----------------------------------------------------------------------*/
00007 /* If a working storage control module is available, it should be        */
00008 /* attached to the FatFs via a glue function rather than modifying it.   */
00009 /* This is an example of glue functions to attach various exsisting      */
00010 /* storage control modules to the FatFs module with a defined API.       */
00011 /*-----------------------------------------------------------------------*/
00012 
00013 /**
00014   ******************************************************************************
00015   * @file    diskio.c 
00016   * @author  MCD Application Team
00017   * @version V1.4.0
00018   * @date    23-December-2016
00019   * @brief   FatFs low level disk I/O module.
00020   ******************************************************************************
00021   * @attention
00022   *
00023   *
00024   * Redistribution and use in source and binary forms, with or without 
00025   * modification, are permitted, provided that the following conditions are met:
00026   *
00027   * 1. Redistribution of source code must retain the above copyright notice, 
00028   *    this list of conditions and the following disclaimer.
00029   * 2. Redistributions in binary form must reproduce the above copyright notice,
00030   *    this list of conditions and the following disclaimer in the documentation
00031   *    and/or other materials provided with the distribution.
00032   * 3. Neither the name of STMicroelectronics nor the names of other 
00033   *    contributors to this software may be used to endorse or promote products 
00034   *    derived from this software without specific written permission.
00035   * 4. This software, including modifications and/or derivative works of this 
00036   *    software, must execute solely and exclusively on microcontroller or
00037   *    microprocessor devices manufactured by or for STMicroelectronics.
00038   * 5. Redistribution and use of this software other than as permitted under 
00039   *    this license is void and will automatically terminate your rights under 
00040   *    this license. 
00041   *
00042   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 
00043   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 
00044   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
00045   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
00046   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 
00047   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00048   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00049   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
00050   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
00051   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
00052   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00053   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00054   *
00055   ******************************************************************************
00056   */
00057 
00058 /* Includes ------------------------------------------------------------------*/
00059 #include "diskio.h"
00060 #include "ff_gen_drv.h"
00061 
00062 /* Private typedef -----------------------------------------------------------*/
00063 /* Private define ------------------------------------------------------------*/
00064 /* Private variables ---------------------------------------------------------*/
00065 extern Disk_drvTypeDef  disk;
00066 
00067 /* Private function prototypes -----------------------------------------------*/
00068 /* Private functions ---------------------------------------------------------*/
00069 
00070 /**
00071   * @brief  Gets Disk Status 
00072   * @param  pdrv: Physical drive number (0..)
00073   * @retval DSTATUS: Operation status
00074   */
00075 DSTATUS disk_status (
00076     BYTE pdrv       /* Physical drive nmuber to identify the drive */
00077 )
00078 {
00079   DSTATUS stat;
00080   
00081   stat = disk.drv[pdrv]->disk_status (disk.lun[pdrv]);
00082   return stat;
00083 }
00084 
00085 /**
00086   * @brief  Initializes a Drive
00087   * @param  pdrv: Physical drive number (0..)
00088   * @retval DSTATUS: Operation status
00089   */
00090 DSTATUS disk_initialize (
00091     BYTE pdrv               /* Physical drive nmuber to identify the drive */
00092 )
00093 {
00094   DSTATUS stat = RES_OK;
00095   
00096   if(disk.is_initialized[pdrv] == 0)
00097   { 
00098     disk.is_initialized[pdrv] = 1;
00099     stat = disk.drv[pdrv]->disk_initialize (disk.lun[pdrv]);
00100   }
00101   return stat;
00102 }
00103 
00104 /**
00105   * @brief  Reads Sector(s) 
00106   * @param  pdrv: Physical drive number (0..)
00107   * @param  *buff: Data buffer to store read data
00108   * @param  sector: Sector address (LBA)
00109   * @param  count: Number of sectors to read (1..128)
00110   * @retval DRESULT: Operation result
00111   */
00112 DRESULT disk_read (
00113     BYTE pdrv,      /* Physical drive nmuber to identify the drive */
00114     BYTE *buff,     /* Data buffer to store read data */
00115     DWORD sector,           /* Sector address in LBA */
00116     UINT count      /* Number of sectors to read */
00117 )
00118 {
00119   DRESULT res;
00120  
00121   res = disk.drv[pdrv]->disk_read (disk.lun[pdrv], buff, sector, count);
00122   return res;
00123 }
00124 
00125 /**
00126   * @brief  Writes Sector(s)  
00127   * @param  pdrv: Physical drive number (0..)
00128   * @param  *buff: Data to be written
00129   * @param  sector: Sector address (LBA)
00130   * @param  count: Number of sectors to write (1..128)
00131   * @retval DRESULT: Operation result
00132   */
00133 #if _USE_WRITE == 1
00134 DRESULT disk_write (
00135     BYTE pdrv,      /* Physical drive nmuber to identify the drive */
00136     const BYTE *buff,   /* Data to be written */
00137     DWORD sector,       /* Sector address in LBA */
00138     UINT count          /* Number of sectors to write */
00139 )
00140 {
00141   DRESULT res;
00142   
00143   res = disk.drv[pdrv]->disk_write (disk.lun[pdrv], buff, sector, count);
00144   return res;
00145 }
00146 #endif /* _USE_WRITE == 1 */
00147 
00148 /**
00149   * @brief  I/O control operation  
00150   * @param  pdrv: Physical drive number (0..)
00151   * @param  cmd: Control code
00152   * @param  *buff: Buffer to send/receive control data
00153   * @retval DRESULT: Operation result
00154   */
00155 #if _USE_IOCTL == 1
00156 DRESULT disk_ioctl (
00157     BYTE pdrv,      /* Physical drive nmuber (0..) */
00158     BYTE cmd,       /* Control code */
00159     void *buff      /* Buffer to send/receive control data */
00160 )
00161 {
00162   DRESULT res;
00163 
00164   res = disk.drv[pdrv]->disk_ioctl (disk.lun[pdrv], cmd, buff);
00165   return res;
00166 }
00167 #endif /* _USE_IOCTL == 1 */
00168 
00169 /**
00170   * @brief  Gets Time from RTC 
00171   * @param  None
00172   * @retval Time in DWORD
00173   */
00174 __weak DWORD get_fattime (void)
00175 {
00176   return 0;
00177 }
00178 
00179 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00180