Exemplo n.º 1
0
DRESULT disk_readp (
	void* dest,			/* Pointer to the destination object */
	DWORD sector,		/* Sector number (LBA) */
	WORD sofs,			/* Offset in the sector */
	WORD count			/* Byte count (bit15:destination) */
)
{
	DRESULT ErrorCode = RES_OK;
	uint8_t BlockTemp[512];

	if (USB_CurrentMode == USB_MODE_HOST)
	{
		#if defined(USB_CAN_BE_HOST)
		if (USB_HostState != HOST_STATE_Configured)
		  ErrorCode = RES_NOTRDY;
		else if (MS_Host_ReadDeviceBlocks(&DiskHost_MS_Interface, 0, sector, 1, 512, BlockTemp))
		  ErrorCode = RES_ERROR;

		MS_Host_ReadDeviceBlocks(&DiskHost_MS_Interface, 0, sector, 1, 512, BlockTemp);
		#endif
	}
	else
	{
		#if defined(USB_CAN_BE_DEVICE)
		DataflashManager_ReadBlocks_RAM(sector, 1, BlockTemp);
		#endif
	}

	memcpy(dest, &BlockTemp[sofs], count);

	return ErrorCode;
}
Exemplo n.º 2
0
/* Read sectors */
int FSUSB_DiskReadSectors(DISK_HANDLE_T *hDisk, void *buff, uint32_t secStart, uint32_t numSec)
{
	if (MS_Host_ReadDeviceBlocks(hDisk, 0, secStart, numSec, DiskCapacity.BlockSize, buff)) {
		DEBUGOUT("Error reading device block.\r\n");
		USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0);
		return 0;
	}
	return 1;
}