USB端点0为控制模式,端点1批量发送,端点2为批量接受,枚举正常,可以读写,问题在于读写的速度太慢了,1M的文件需要20s。请高手帮忙
usb_endp.c中
void EP2_OUT_Callback(void)
{
Mass_Storage_Out();
}
usb_bot.c中
void Mass_Storage_Out (void) //对电脑来说,是out,主要是对批量传输中用到的CBW命令封装包的一些解析
{
u8 CMD;
CMD = CBW.CB[0];
Data_Len = GetEPRxCount(ENDP2);
PMAToUserBufferCopy(Bulk_Data_Buff, ENDP2_RXADDR, Data_Len);// CBW才31个字节,而ENDP2的Count有64个字节
switch (Bot_State) //Bot_State
{
case BOT_IDLE: //IDLE为空闲的意思
CBW_Decode();
break;
case BOT_DATA_OUT:
if (CMD == SCSI_WRITE10)
{
SCSI_Write10_Cmd();
break;
}
Bot_Abort(DIR_OUT);
Set_Scsi_Sense_Data(ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
Set_CSW (CSW_PHASE_ERROR, SEND_CSW_DISABLE);
break;
default:
Bot_Abort(BOTH_DIR);
Set_Scsi_Sense_Data(ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
Set_CSW (CSW_PHASE_ERROR, SEND_CSW_DISABLE);
break;
}
}
void CBW_Decode(void)
{
u32 Counter;
for (Counter = 0; Counter < Data_Len; Counter++) //取出CBW包
{
*((u8 *)&CBW + Counter) = Bulk_Data_Buff[Counter];
}
CSW.dTag = CBW.dTag;
CSW.dDataResidue = CBW.dDataLength;
if (Data_Len != BOT_CBW_PACKET_LENGTH) //CBW包的长度是否等于31个字节
{
Bot_Abort(BOTH_DIR);
/* reset the CBW.dSignature to desible the clear feature until receiving a Mass storage reset*/
CBW.dSignature = 0;
Set_Scsi_Sense_Data(ILLEGAL_REQUEST, PARAMETER_LIST_LENGTH_ERROR);
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
return;
}
if (CBW.dSignature == BOT_CBW_SIGNATURE) //判断CBW签名
{
/* Valid CBW */
if ((CBW.bLUN != 0) || (CBW.bCBLength < 1) || (CBW.bCBLength > 16))
//判断逻辑地址,和数据长度
{
Bot_Abort(BOTH_DIR);
Set_Scsi_Sense_Data(ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
}
else
{
switch (CBW.CB[0]) //分类处理CBW包中的命令。
{
case SCSI_REQUEST_SENSE:
SCSI_RequestSense_Cmd ();
break;
case SCSI_INQUIRY:
SCSI_Inquiry_Cmd();
break;
case SCSI_START_STOP_UNIT:
SCSI_Start_Stop_Unit_Cmd();
case SCSI_ALLOW_MEDIUM_REMOVAL:
SCSI_Start_Stop_Unit_Cmd();
break;
case SCSI_MODE_SENSE6:
SCSI_ModeSense6_Cmd ();
break;
case SCSI_MODE_SENSE10:
SCSI_ModeSense10_Cmd ();
break;
case SCSI_READ_FORMAT_CAPACITIES:
SCSI_ReadFormatCapacity_Cmd();
break;
case SCSI_READ_CAPACITY10:
SCSI_ReadCapacity10_Cmd();
break;
case SCSI_TEST_UNIT_READY:
SCSI_TestUnitReady_Cmd();
break;
case SCSI_READ10:
SCSI_Read10_Cmd(); //READ(10)命令用来读取实际的磁盘数据,操作码为0x28
break;
case SCSI_WRITE10:
SCSI_Write10_Cmd();
break;
case SCSI_VERIFY10:
SCSI_Verify10_Cmd();
break;
/*Unsupported command*/
case SCSI_MODE_SELECT10:
SCSI_Mode_Select10_Cmd();
break;
case SCSI_MODE_SELECT6:
SCSI_Mode_Select6_Cmd();
break;
case SCSI_FORMAT_UNIT:
SCSI_FormatUnit_Cmd();
break;
case SCSI_SEND_DIAGNOSTIC:
SCSI_Send_Diagnostic_Cmd();
break;
case SCSI_READ6:
SCSI_Read6_Cmd();
break;
case SCSI_READ12:
SCSI_Read12_Cmd();
break;
case SCSI_READ16:
SCSI_Read16_Cmd();
break;
case SCSI_READ_CAPACITY16:
SCSI_READ_CAPACITY16_Cmd();
break;
case SCSI_WRITE6:
SCSI_Write6_Cmd();
break;
case SCSI_WRITE12:
SCSI_Write12_Cmd();
break;
case SCSI_WRITE16:
SCSI_Write16_Cmd();
break;
case SCSI_VERIFY12:
SCSI_Verify12_Cmd();
break;
case SCSI_VERIFY16:
SCSI_Verify16_Cmd();
break;
default:
{
Bot_Abort(BOTH_DIR);
Set_Scsi_Sense_Data(ILLEGAL_REQUEST, INVALID_COMMAND);
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
}
}
}
}
else
{
/* Invalid CBW */
Bot_Abort(BOTH_DIR);
Set_Scsi_Sense_Data(ILLEGAL_REQUEST, INVALID_COMMAND);
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
}
}
此帖出自
小平头技术问答
一周热门 更多>