/*-----------------------------------------------------------------------*/
DRESULT TM_FATFS_USB_disk_read (
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	UINT count		/* Number of sectors to read (1..128) */
)
{
	BYTE status = USBH_MSC_OK;

	if (!count) {
		return RES_PARERR;
	}
	if (USB_Stat & STA_NOINIT) {
		return RES_NOTRDY;
	}

	if (HCD_IsDeviceConnected(&USB_OTG_Core) && USBH_USR_MSC_IsReady()) {
		//USBH_MSC_Init(&USB_OTG_Core);
		do
		{
			status = USBH_MSC_Read10(&USB_OTG_Core, buff, sector, 512 * count);
			USBH_MSC_HandleBOTXfer(&USB_OTG_Core, &USB_Host);

			if (!HCD_IsDeviceConnected(&USB_OTG_Core)) { 
				return RES_ERROR;
			}
		} while (status == USBH_MSC_BUSY);
	}

	if (status == USBH_MSC_OK) {
		return RES_OK;
	}
	return RES_ERROR;
}
Exemple #2
0
/*-----------------------------------------------------------------------*/
DRESULT TM_FATFS_USB_disk_read (
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	UINT count		/* Number of sectors to read (1..128) */
)
{
	BYTE status = USBH_MSC_OK;
	uint32_t timeout;

	if (!count) {
		return RES_PARERR;
	}
	if (USB_Stat & STA_NOINIT) {
		return RES_NOTRDY;
	}

	if (HCD_IsDeviceConnected(&USB_OTG_Core) && TM_USB_MSCHOST_INT_Result == TM_USB_MSCHOST_Result_Connected) {
		timeout = FATFS_USB_TIMEOUT;
		do
		{
			status = USBH_MSC_Read10(&USB_OTG_Core, buff, sector, 512 * count);
			USBH_MSC_HandleBOTXfer(&USB_OTG_Core, &USB_Host);

			if (!HCD_IsDeviceConnected(&USB_OTG_Core)) { 
				return RES_ERROR;
			}
		} while (status == USBH_MSC_BUSY && timeout--);
	}

	if (status == USBH_MSC_OK) {
		return RES_OK;
	}
	return RES_ERROR;
}
Exemple #3
0
DRESULT disk_read (
                   BYTE drv,			/* Physical drive number (0) */
                   BYTE *buff,			/* Pointer to the data buffer to store read data */
                   DWORD sector,		/* Start sector number (LBA) */
                   BYTE count			/* Sector count (1..255) */
                     )
{
  BYTE status = USBH_MSC_OK;
  
  if (drv || !count) return RES_PARERR;
  if (Stat & STA_NOINIT) return RES_NOTRDY;
  
  
  if(HCD_IsDeviceConnected(&usbOTGHost))
  {  
    
    do
    {
      status = USBH_MSC_Read10(&usbOTGHost, buff, sector, 512*count);
      USBH_MSC_HandleBOTXfer(&usbOTGHost ,&usbHost);
      
      if(!HCD_IsDeviceConnected(&usbOTGHost))
      { 
        return RES_ERROR;
      }      
    }
    while(status == USBH_MSC_BUSY );
  }
  
  if(status == USBH_MSC_OK)
    return RES_OK;
  return RES_ERROR;
  
}
Exemple #4
0
/***********************************************************
* Function:       // 函数名称
* Description:    // 函数功能、性能等的描述
* Input:          // 1.输入参数1,说明,包括每个参数的作用、取值说明及参数间关系
* Input:          // 2.输入参数2,说明,包括每个参数的作用、取值说明及参数间关系
* Output:         // 1.输出参数1,说明
* Return:         // 函数返回值的说明
* Others:         // 其它说明
***********************************************************/
static rt_size_t msc_read( rt_device_t dev, rt_off_t sector, void* buff, rt_size_t count )
{
	__IO uint8_t status = USBH_MSC_OK;
	if( HCD_IsDeviceConnected( &USB_OTG_Core ) )
	{
		do
		{
			status = USBH_MSC_Read10( &USB_OTG_Core, buff, sector, 512 * count );
			USBH_MSC_HandleBOTXfer( &USB_OTG_Core, &USB_Host );

			if( !HCD_IsDeviceConnected( &USB_OTG_Core ) )
			{
				//return RES_ERROR;
				rt_kprintf( "\n%s error", __func__ );
				return USBH_MSC_FAIL;
			}
		}
		while( status == USBH_MSC_BUSY );
	}
	if( status == USBH_MSC_OK )
	{
		return count;
	}
	return 0xff;
}
BOOL USB_MSC_Driver::Read( void* context, ByteAddress Address, UINT32 NumBytes, BYTE * pSectorBuff ){

	USB_OTG_CORE_HANDLE *pDev = (USB_OTG_CORE_HANDLE*)context;
	BYTE status = USBH_MSC_OK;

	if(!HCD_IsDeviceConnected(pDev)){
		return FALSE;
	}
	//flat adressing
	SectorAddress startSector = Address / 512;
	if (Address % 512 != 0) {
		CLR_Debug::Printf( "USB_MSC_Driver::Read error: Adress must match a sector start, sector=%08x, Address=%08x, NumBytes %d\r\n", startSector, Address, NumBytes);
		return FALSE;
	}
	//CLR_Debug::Printf( "USB_MSC_Driver::Read() address=%lld, numBytes=%d sector=%d\r\n", Address, NumBytes, startSector);
	//CLR_Debug::Printf( "USB_MSC_Driver::Read offset=%d, StartSector=0x%08x, Address=%08x, NumBytes %d\r\n", offset, StartSector, Address, NumBytes);
	USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE;
	do {
		status = USBH_MSC_Read10(pDev, pSectorBuff, startSector, NumBytes);
		USBH_MSC_HandleBOTXfer(pDev ,&USB_Host);

		if(!HCD_IsDeviceConnected(pDev)) { 
			//CLR_Debug::Printf( "USB_MSC_Driver::Read() USB device disconnection when reading\r\n");
			return FALSE;
		}      
	} while(status == USBH_MSC_BUSY );

	if(status != USBH_MSC_OK)
		return FALSE;

	return TRUE;
}
int8_t if_readBuf(hwInterface* file,uint32_t address,uint8_t* buf)
{
  int8_t status = EFS_ERROR;
  if(HCD_IsDeviceConnected(&USB_OTG_FS_dev))
  {  
    
    do
    {
      status = USBH_MSC_Read10(buf,address,512);
      USBH_MSC_HandleBOTXfer();
    }
    while((status == USBH_MSC_BUSY ) && (HCD_IsDeviceConnected(&USB_OTG_FS_dev)));
    
  }
  
  return(status);
  
}