/******************************************************************************* * Function Name : MSD_ReadMultiBlock * Description : None * Input : - sector: * - buffer: * - NbrOfSector: * Output : None * Return : None * Attention : None *******************************************************************************/ uint8 AppSdReadBytesInBlk(uint32 BlkAddr, uint32 OffsetAddr, uint32 InBlkByteNum, uint8 *DataBuf) { uint32 sector = BlkAddr; if((OffsetAddr + InBlkByteNum) > MSD_BLOCKSIZE) //读范围不能垮块 { while(1); } if(OffsetAddr == 0 && InBlkByteNum == MSD_BLOCKSIZE) //读一整块 { if(MSD_ReadSingleBlock(sector, DataBuf) != 0) { return FALSE; } } else //读块的一部分 { if(MSD_ReadSingleBlock(sector, gSdRWBuf) != 0) { return FALSE; } memcpy(DataBuf, &gSdRWBuf[OffsetAddr], InBlkByteNum); } return TRUE; }
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) */ ) { int Status; if( !count ) { return RES_PARERR; /* count不能等于0,否则返回参数错误 */ } switch (drv) { case 0: if(count==1) /* 1个sector的读操作 */ { Status = MSD_ReadSingleBlock( sector ,buff ); } else /* 多个sector的读操作 */ { Status = MSD_ReadMultiBlock( sector , buff ,count); } if(Status == 0) { return RES_OK; } else { return RES_ERROR; } case 1: break; case 2: break; default: break; } return RES_ERROR; }