DRESULT disk_read ( BYTE drv, /* Physical drive nmuber (0..) */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to read (1..255) */ ) { u8 res=0; if (drv || !count) { return RES_PARERR; // only supports single disk operation, count is not equal to 0, otherwise parameter error } // if(!SD_DET()) // { // return RES_NOTRDY; // does not detect SD card, NOT READY error reported // } if(count==1) // sector reads 1 { res = SD_ReadSingleBlock(sector, buff); } else // multiple sector read operations { res = SD_ReadMultiBlock(sector, buff, count); } /* do { if(SD_ReadSingleBlock(sector, buff)!=0) { res = 1; break; } buff+=512; }while(--count); */ // Process the return value, the return value of the SPI_SD_driver.c the return value turned into ff.c if(res == 0x00) { return RES_OK; } else { return RES_ERROR; } }
DRESULT disk_read ( BYTE drv, /* Physical drive nmuber (0..) */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to read (1..255) */ ) { u8 res=0; if (drv || !count) { return RES_PARERR; //仅支持单磁盘操作,count不能等于0,否则返回参数错误 } if(!SD_DET()) { return RES_NOTRDY; //没有检测到SD卡,报NOT READY错误 } if(count==1) //1个sector的读操作 { res = SD_ReadSingleBlock(sector, buff); } else //多个sector的读操作 { res = SD_ReadMultiBlock(sector, buff, count); } /* do { if(SD_ReadSingleBlock(sector, buff)!=0) { res = 1; break; } buff+=512; }while(--count); */ //处理返回值,将SPI_SD_driver.c的返回值转成ff.c的返回值 if(res == 0x00) { return RES_OK; } else { return RES_ERROR; } }
DRESULT disk_read (BYTE drv,BYTE* buff,DWORD sector,BYTE count)//哪个卡(一般为0),读出的数据存储的地方,块地址,块个数 { u8 res=0; if (drv || !count) { return RES_PARERR; //仅支持单磁盘操作,count不能等于0,否则返回参数错误 } if(SD_Insert_Status()) { return RES_NOTRDY; //没有检测到SD卡,报NOT READY错误 } if(count==1) //1个sector的读操作 { res = SD_ReadSingleBlock(sector, buff); } else //多个sector的读操作 { res = SD_ReadMultiBlock(sector, buff, count); } /* do { if(SD_ReadSingleBlock(sector, buff)!=0) { res = 1; break; } buff+=512; }while(--count); */ //处理返回值,将SPI_SD_driver.c的返回值转成ff.c的返回值 if(res == 0x00) { return RES_OK; } else { return RES_ERROR; } }
DRESULT disk_read ( BYTE pdrv, /* Physical drive nmuber (0..) */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ UINT count /* Number of sectors to read (1..128) */ ) { DRESULT res; // int result; switch (pdrv) { case SD_CARD : SD_ReadMultiBlock(sector, buff, count); res = RES_OK; return res; } return RES_PARERR; }
DRESULT disk_read ( BYTE pdrv, /* Physical drive nmuber (0..) */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to read (1..128) */ ) { U8_T res = 0; if (pdrv || !count) { return RES_PARERR; } #if 0 if(SD_ChkCard() != 1) { return RES_NOTRDY; } #endif if(count==1) //1个sector的读操作 { res = SD_ReadBlock(sector, buff); } else //多个sector的读操作 { res = SD_ReadMultiBlock(sector,count, buff); } //处理返回值,将SPI_SD_driver.c的返回值转成ff.c的返回值 if(res == 0x00) { return RES_OK; } else { return RES_ERROR; } }
DRESULT MMC_disk_read(u32 sector, u8 *buff, u8 count) { return ((DRESULT)(SD_ReadMultiBlock(sector,buff,count))); }
/*-----------------------------------*/ static int ReadSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer) { SDC_CMD_STATUS status; kal_uint8 retry = 0; kal_uint32 adrs; #if defined(__SIM_PLUS__) sd_select_enum sel; if((MSDC_HANDLE *)DriveData == &MSDC_Blk[0]) sel = SD_EXT; else sel = SD_SIM; MSDC_Switch_Card(sel); #endif #if defined(SD_MMC_HIGH_DENSITY_SUPPORT) if(gSD->flags & SD_FLAG_HCS_SUPPORT) adrs = Sector; else #endif adrs = Sector * SECTOR_SIZE; gMSDC_Handle->timeout_count = 0; start: if(!gMSDC_Handle->mIsInitialized) { //dbg_print("Read but not Initialized \r\n"); MSDC_PDNControl(KAL_TRUE); return FS_MSDC_READ_SECTOR_ERROR; } retry ++; MSDC_PDNControl(KAL_FALSE); #ifndef LSD_SINGLE_READ if(Sectors > 1) status = SD_ReadMultiBlock((kal_uint32)adrs,(kal_uint32*)Buffer,(kal_uint32)Sectors); else status = SD_ReadSingleBlock((kal_uint32)adrs,(kal_uint32*)Buffer); #else while(Sectors) { status = SD_ReadSingleBlock((kal_uint32)adrs,(kal_uint32*)Buffer); if(status != NO_ERROR ) break; (kal_uint8 *)Buffer += SECTOR_SIZE; Sector ++; #if defined(SD_MMC_HIGH_DENSITY_SUPPORT) if(gSD->flags & SD_FLAG_HCS_SUPPORT) adrs = Sector; else #endif adrs = Sector * SECTOR_SIZE; Sectors--; } #endif if(status != NO_ERROR ) { sd_r++; if(kal_query_systemInit()== KAL_TRUE) { MSDC_PDNControl(KAL_TRUE); return FS_MSDC_READ_SECTOR_ERROR; } //dbg_print("read retry:%d,status:%d,total %d\r\n",retry,status,sd_r); if(status == ERR_CMD_TIMEOUT || status == MSDC_GPT_TIMEOUT_ERR) gMSDC_Handle->timeout_count++; if(gMSDC_Handle->timeout_count++ == 3 && gMSDC_Handle->mIsPresent == KAL_TRUE) { kal_print("[MSDC]:re-mount(read fail)"); gMSDC_Handle->mIsInitialized = KAL_FALSE; retry = 0; if(SD_Initialize() != NO_ERROR) { MSDC_PDNControl(KAL_TRUE); return FS_MSDC_READ_SECTOR_ERROR; } } if(retry >= SD_MAX_RETRY) { MSDC_PDNControl(KAL_TRUE); return FS_MSDC_READ_SECTOR_ERROR; } else { // kal_prompt_trace(MOD_AUD,"CRC etry:%d,status:%d",retry,status); goto start; } } MSDC_PDNControl(KAL_TRUE); return FS_NO_ERROR; }