DRESULT disk_write (BYTE drv,const BYTE* buff,DWORD sector,BYTE count) { u8 res; if (drv || !count) { return RES_PARERR; //仅支持单磁盘操作,count不能等于0,否则返回参数错误 } if(SD_Insert_Status()) { return RES_NOTRDY; //没有检测到SD卡,报NOT READY错误 } // 读写操作 if(count == 1) { res = SD_WriteSingleBlock(sector, buff); } else { res = SD_WriteMultiBlock(sector, buff, count); } // 返回值转换 if(res == 0) { return RES_OK; } else { return RES_ERROR; } }
DRESULT disk_write ( BYTE pdrv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address (LBA) */ UINT count /* Number of sectors to write (1..128) */ ) { DRESULT res; // int result; switch (pdrv) { case SD_CARD : // translate the arguments here SD_WriteMultiBlock(sector, buff, count); res = RES_OK; return res; } return RES_PARERR; }
DRESULT disk_write ( BYTE pdrv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to write (1..128) */ ) { U8_T res; if (pdrv || !count) { return RES_PARERR; } #if 0 if(SD_ChkCard() != 1) { return RES_NOTRDY; } #endif // 读写操作 if(count == 1) { res = SD_WriteBlock(sector, buff); } else { res = SD_WriteMultiBlock(sector,count, buff); } // 返回值转换 if(res == 0) { return RES_OK; } else { return RES_ERROR; } }
DRESULT disk_write ( BYTE drv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to write (1..255) */ ) { u8 res; 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 } */ // Read and write operations if(count == 1) { res = SD_WriteSingleBlock(sector, buff); } else { res = SD_WriteMultiBlock(sector, buff, count); } // Return value to if(res == 0) { return RES_OK; } else { return RES_ERROR; } }
DRESULT disk_write ( BYTE drv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to write (1..255) */ ) { u8 res; if (drv || !count) { return RES_PARERR; //仅支持单磁盘操作,count不能等于0,否则返回参数错误 } if(!SD_DET()) { return RES_NOTRDY; //没有检测到SD卡,报NOT READY错误 } // 读写操作 if(count == 1) { res = SD_WriteSingleBlock(sector, buff); } else { res = SD_WriteMultiBlock(sector, buff, count); } // 返回值转换 if(res == 0) { return RES_OK; } else { return RES_ERROR; } }
DRESULT MMC_disk_write(u32 sector, const u8 *buff, u8 count) { return ((DRESULT)(SD_WriteMultiBlock(sector,buff,count))); }
/*-----------------------------------*/ static int WriteSectors(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("Write but not Initialized \r\n"); MSDC_PDNControl(KAL_TRUE); return FS_MSDC_WRITE_SECTOR_ERROR; } retry++; MSDC_PDNControl(KAL_FALSE); #ifndef LSD_SINGLE_WRITE if(Sectors > 1) { if(gMSDC_Handle->mMSDC_type == SD_CARD) SD_SetPreEraseBlk(Sectors); status = SD_WriteMultiBlock((kal_uint32)adrs,(kal_uint32*)Buffer,(kal_uint32)Sectors); } else status = SD_WriteSingleBlock((kal_uint32)adrs,(kal_uint32*)Buffer); #else while(Sectors) { status = SD_WriteSingleBlock((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_w++; if(kal_query_systemInit()== KAL_TRUE) { MSDC_PDNControl(KAL_TRUE); return FS_MSDC_WRITE_SECTOR_ERROR; } //dbg_print("write retry:%d,status:%d,total %d\r\n",retry,status,sd_w); 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]:SD re-mount (write fail)"); gMSDC_Handle->mIsInitialized = KAL_FALSE; retry = 0; if(SD_Initialize() != NO_ERROR) { MSDC_PDNControl(KAL_TRUE); return FS_MSDC_WRITE_SECTOR_ERROR; } } if(retry >= SD_MAX_RETRY) { MSDC_PDNControl(KAL_TRUE); return FS_MSDC_WRITE_SECTOR_ERROR; } else { // kal_prompt_trace(MOD_AUD,"CRC write Error retry %d",retry); goto start; } } MSDC_PDNControl(KAL_TRUE); return FS_NO_ERROR; }