static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t * const MSInterfaceInfo, const bool IsDataRead)
{
uint32_t BlockAddress;
uint16_t TotalBlocks;
uint16_t Remainder;
uint32_t RemainderAddress;
int32_t status = 0;
...
BlockAddress = (MSInterfaceInfo->State.CommandBlock.SCSICommandData[2] << 24)
+ (MSInterfaceInfo->State.CommandBlock.SCSICommandData[3] << 16)
+ (MSInterfaceInfo->State.CommandBlock.SCSICommandData[4] << 8)
+ (MSInterfaceInfo->State.CommandBlock.SCSICommandData[5]);
TotalBlocks = (MSInterfaceInfo->State.CommandBlock.SCSICommandData[7] << 8)
+ MSInterfaceInfo->State.CommandBlock.SCSICommandData[8];
Remainder = TotalBlocks - 128;
RemainderAddress = BlockAddress + 128;
...
if (IsDataRead == DATA_READ)
{
if (TotalBlocks <= 128)
{
status = Chip_SDMMC_ReadBlocks((void*) disk_cache, BlockAddress,TotalBlocks);
while (!Endpoint_IsINReady(MSInterfaceInfo->Config.PortNumber));
Endpoint_Streaming(MSInterfaceInfo->Config.PortNumber, (uint8_t*) disk_cache, VIRTUAL_MEMORY_BLOCK_SIZE, TotalBlocks,0);
}
else
{
// first 128
status = Chip_SDMMC_ReadBlocks((void*) disk_cache, BlockAddress,128);
while (!Endpoint_IsINReady(MSInterfaceInfo->Config.PortNumber));
Endpoint_Streaming(MSInterfaceInfo->Config.PortNumber, (uint8_t*) disk_cache, VIRTUAL_MEMORY_BLOCK_SIZE, 128,0);
// remainder
status = Chip_SDMMC_ReadBlocks((void*) disk_cache, RemainderAddress,Remainder);
while (!Endpoint_IsINReady(MSInterfaceInfo->Config.PortNumber));
Endpoint_Streaming(MSInterfaceInfo->Config.PortNumber, (uint8_t*) disk_cache, VIRTUAL_MEMORY_BLOCK_SIZE, Remainder,0);
}
}
else
{
if (TotalBlocks <= 128)
{
Endpoint_Streaming(MSInterfaceInfo->Config.PortNumber,(uint8_t*) disk_cache, VIRTUAL_MEMORY_BLOCK_SIZE, TotalBlocks,0);
while (!Endpoint_IsOUTReceived(MSInterfaceInfo->Config.PortNumber));
debug("Write %d @ 0x%08x\n", TotalBlocks, BlockAddress);
status = Chip_SDMMC_WriteBlocks((void*) disk_cache, BlockAddress,TotalBlocks);
}
else
{
// first 128
Endpoint_Streaming(MSInterfaceInfo->Config.PortNumber,(uint8_t*) disk_cache, VIRTUAL_MEMORY_BLOCK_SIZE, 128,0);
while (!Endpoint_IsOUTReceived(MSInterfaceInfo->Config.PortNumber));
status = Chip_SDMMC_WriteBlocks((void*) disk_cache, BlockAddress,128);
// remainder
Endpoint_Streaming(MSInterfaceInfo->Config.PortNumber,(uint8_t*) disk_cache, VIRTUAL_MEMORY_BLOCK_SIZE, Remainder,0);
while (!Endpoint_IsOUTReceived(MSInterfaceInfo->Config.PortNumber));
status = Chip_SDMMC_WriteBlocks((void*) disk_cache, RemainderAddress,Remainder);
}
}
...
} |