⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fatsupport.c

📁 本程序为ST公司开发的源代码
💻 C
字号:
/************************************************** * * fatsupport.h * * CVS ID:   $Id: * Author:   Michal Chlapik [ MCH ] - STM * Date:     $Date: 2007/01/29 14:32:00 $ * Revision: $Revision: 1.14 $ * * Description: * *   <...> * *************************************************** * * COPYRIGHT (C) ST Microelectronics  2005 *            All Rights Reserved * **************************************************** * * STM CVS Log: * * $Log: FATsupport.c,v $ * Revision 1.14  2007/01/29 14:32:00  chlapik * support for USB devices with any block size (not only 512B) * * Revision 1.13  2006/09/18 09:55:22  belardi * Corrected CVS keyword usage * * Revision 1.12  2006/09/18 09:24:02  belardi * Added Log CVS keyword into file header * * ***************************************************/#include "configuration.h"#if (HAVE_FAT)#include "gendef.h"#include "apdevsys.h"#include "xfile.h"#include "filesys.h"#include "FATsupport.h"#include "FATtypes.h"#include "capture.h"#include "controller.h"GRESULT IO_Read_USB(uint8 *SectorBuffer, uint32 block_num, uint32 num_of_bytes, uint32 block_size){  GRESULT err;  PREPARE_IOREAD(FS_XFER_command_event,DEV_USB_ID,block_num,block_num+num_of_bytes/block_size,0,block_size,SectorBuffer,num_of_bytes,0);  err=IO_Read(IO_READ_IMMEDIATE);        if(err<0)    {      return err;    }         return S_OK;}#if (0 != HAVE_SDC)GRESULT IO_Read_SDC(uint8 *SectorBuffer, uint32 block_num, uint32 num_of_bytes, uint32 block_size){  GRESULT err;  PREPARE_IOREAD(FS_XFER_command_event, DEV_SDC_ID, block_num,           block_num + num_of_bytes/block_size, 0, block_size, SectorBuffer,           num_of_bytes, 0);  err = IO_Read(IO_READ_IMMEDIATE);  if(0 > err)  {    return err;  }  return S_OK;}#endif /* HAVE_SDC */uint32 get_val_log2(uint32 val){    uint32 i, log2;    i = val;    log2 = 0;    while (0 == (i & 1))    {        i >>= 1;        log2++;    }    if (i != 1)        return 0;    else        return log2;}GRESULT Get_SectorRel(uint8 *Sectorbuffer, uint32 sector_num, FS_DESCRIPTOR *fsd){     //static uint8 Sectorbuffer[4096];     uint32 block_num,Part_block_num;/*     uint32 DataRequired = fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec;     uint8 *Sectorbuffer_p = Sectorbuffer;*/     GRESULT ReturnCode;     if(fsd->PD.FAT_pd.FirstPassGetSector_FAT)     { //first call will certainly go through reading media       fsd->PD.FAT_pd.LastRequiredSector_rel = sector_num+1;       fsd->PD.FAT_pd.FirstPassGetSector_FAT = false;     }     if(sector_num != fsd->PD.FAT_pd.LastRequiredSector_rel)     {   //access media         //control variables for next for loop         block_num = ((fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec)/(fsd->LargeBlockSize));         Part_block_num = fsd->PartitionLBA;         //get Sector via blocks#if (0 != HAVE_SDC)         if(DEV_SDC_ID == SYS_DeviceType(fsd->did))         {           ReturnCode = IO_Read_SDC(Sectorbuffer,block_num*sector_num+Part_block_num,fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec,fsd->LargeBlockSize);         }         else         {           ReturnCode = IO_Read_USB(Sectorbuffer,block_num*sector_num+Part_block_num,fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec,fsd->LargeBlockSize);         }         if(S_OK != ReturnCode)#else           if((ReturnCode=IO_Read_USB(Sectorbuffer,block_num*sector_num+Part_block_num,fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec,fsd->LargeBlockSize)) != S_OK)#endif /* HAVE_SDC */             return ReturnCode;         fsd->PD.FAT_pd.LastRequiredSector_rel = sector_num;         return S_OK;     }     else     {   //don't access media         return S_OK;     }}GRESULT Get_Bytes(uint8 *buf, uint8 *SectorBuffer, Get_BytesParamsStruct *Get_BytesParams, FS_DESCRIPTOR *fsd){         //uint8 SectorBuffer[4096];         GRESULT ReturnCode;         if(Get_BytesParams->ClusterOffset >= fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec*fsd->PD.FAT_pd.BPB_boot_common.SecPerClust)           return E_PARAMETER_OUT_OF_RANGE;         if(Get_BytesParams->ClusterOffset+Get_BytesParams->num > fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec*fsd->PD.FAT_pd.BPB_boot_common.SecPerClust)           return E_PARAMETER_OUT_OF_RANGE;         if((ReturnCode=Get_SectorRel(SectorBuffer,Get_BytesParams->FirstSectorOfCluster+((Get_BytesParams->ClusterOffset)>>get_val_log2(fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec)),fsd))!=S_OK)           return ReturnCode;         memcpy(buf,SectorBuffer+((Get_BytesParams->ClusterOffset)&(fsd->PD.FAT_pd.BPB_boot_common.BytesPerSec-1)),Get_BytesParams->num);         return S_OK;}GRESULT Get_SectorAbs(uint8 *Sectorbuffer, uint32 sector_num, FS_DESCRIPTOR *fsd){     //static uint8 Sectorbuffer[512];     uint32 block_num;/*     uint32 DataRequired = 512;     uint8 *Sectorbuffer_p = Sectorbuffer;*/     GRESULT ReturnCode;     if(fsd->PD.FAT_pd.FirstPassGetSectorAbs_FAT)     { //first call will certainly go through reading media       fsd->PD.FAT_pd.LastRequiredSector_abs = sector_num+1;       fsd->PD.FAT_pd.FirstPassGetSectorAbs_FAT = false;     }     if(sector_num != fsd->PD.FAT_pd.LastRequiredSector_abs)     {   //access media         //control variables for next for loop         block_num = sector_num;         //get Sector via blocks#if (0 != HAVE_SDC)         if(DEV_SDC_ID == SYS_DeviceType(fsd->did))         {           ReturnCode = IO_Read_SDC(Sectorbuffer, block_num, 512,fsd->LargeBlockSize);         }         else         {           ReturnCode = IO_Read_USB(Sectorbuffer, block_num, 512,fsd->LargeBlockSize);         }         if(S_OK != ReturnCode)#else           if((ReturnCode=IO_Read_USB(Sectorbuffer,block_num,512,fsd->LargeBlockSize)) != S_OK)#endif /* HAVE_SDC */             return ReturnCode;         fsd->PD.FAT_pd.LastRequiredSector_abs = sector_num;         return S_OK;     }     else     {   //don't access media         return S_OK;     }}#endif /* (HAVE_FAT) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -