📄 usbh_storage_if.c
字号:
devicePara[deviceNo].identifyData[55] = inqData[9];
devicePara[deviceNo].identifyData[56] = inqData[10];
devicePara[deviceNo].identifyData[57] = inqData[11];
devicePara[deviceNo].identifyData[58] = inqData[12];
devicePara[deviceNo].identifyData[59] = inqData[13];
devicePara[deviceNo].identifyData[60] = inqData[14];
devicePara[deviceNo].identifyData[61] = inqData[15];
/* Product ID Set */
devicePara[deviceNo].identifyData[62] = inqData[16];
devicePara[deviceNo].identifyData[63] = inqData[17];
devicePara[deviceNo].identifyData[64] = inqData[18];
devicePara[deviceNo].identifyData[65] = inqData[19];
devicePara[deviceNo].identifyData[66] = inqData[20];
devicePara[deviceNo].identifyData[67] = inqData[21];
devicePara[deviceNo].identifyData[68] = inqData[22];
devicePara[deviceNo].identifyData[69] = inqData[23];
devicePara[deviceNo].identifyData[70] = inqData[24];
devicePara[deviceNo].identifyData[71] = inqData[25];
devicePara[deviceNo].identifyData[72] = inqData[26];
devicePara[deviceNo].identifyData[73] = inqData[27];
devicePara[deviceNo].identifyData[74] = inqData[28];
devicePara[deviceNo].identifyData[75] = inqData[29];
devicePara[deviceNo].identifyData[76] = inqData[30];
devicePara[deviceNo].identifyData[77] = inqData[31];
/* Product Rev. Set */
devicePara[deviceNo].identifyData[78] = inqData[32];
devicePara[deviceNo].identifyData[79] = inqData[33];
devicePara[deviceNo].identifyData[80] = inqData[34];
devicePara[deviceNo].identifyData[81] = inqData[35];
/* Execute READ CAPACITY */
result = USBH_STRG_PutCmd(deviceNo, &cmdBlock, READ_CAPACITY);
if(result != STATUS_SUCCESS) {
return STATUS_UNSUCCESSFUL;
}
tranPara.dataPointer = (ULONG) &rdCapaData[0];
result = USBH_STRG_IFSyncCommand(deviceNo, (UCHAR)devicePara[deviceNo].commandMode, &cmdBlock, &tranPara, &status, devicePara[deviceNo].reqSenseData);
if(result != STATUS_SUCCESS) {
return STATUS_UNSUCCESSFUL;
}
/* Execute READ FORMAT CAPACITY */
result = USBH_STRG_PutCmd(deviceNo, &cmdBlock, READ_FORMAT_CAPACITY);
if(result != STATUS_SUCCESS) {
return STATUS_UNSUCCESSFUL;
}
tranPara.dataPointer = (ULONG) &rdFormCapaData[0];
result = USBH_STRG_IFSyncCommand(deviceNo, (UCHAR)devicePara[deviceNo].commandMode, &cmdBlock, &tranPara, &status, devicePara[deviceNo].reqSenseData);
if(result != STATUS_SUCCESS) {
return STATUS_UNSUCCESSFUL;
}
/* Total LBA Sector Number Set */
devicePara[deviceNo].identifyData[120] = rdFormCapaData[4];
devicePara[deviceNo].identifyData[121] = rdFormCapaData[5];
devicePara[deviceNo].identifyData[122] = rdFormCapaData[6];
devicePara[deviceNo].identifyData[123] = rdFormCapaData[7];
}
/* Send device information */
for(i = 0; i < IDENTIFY_LENGTH; i++) {
*pDataPtr = devicePara[deviceNo].identifyData[i];
pDataPtr++;
}
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_IFCommandOut
//
// description : The command is issued to the specified device. (Asynchronous processing)
//
// The command is issued to the specified device.
// The issued command can be invalidated by USBH_STRG_IFDMAStop.
// The data transfer of the device is not done until USBH_STRG_IFDMAStartA is called.
//
// argument : deviceNo (in)Device No.
// transferMode (in)Transfer mode of the command
// *pCmdBlock (in)Pointer that points to the command parameter
//
// return : STATUS_SUCCESS Completed successfully
// STATUS_UNSUCCESSFUL Completed with error
===============================================================================================*/
LONG USBH_STRG_IFCommandOut( USHORT deviceNo, UCHAR transferMode, DRIVEACCESS_FUNCCMDPARA *pCmdBlock, CALLBACK_PROC pfnNotifyIntrqComp )
{
#ifdef USBH_STRG_IF_COMMAND_PRINT
UCHAR i;
#endif
LONG result;
DRIVEACCESS_FUNCTRANPARA tranPara;
/* Only made the URB */
result = USBH_STRG_MakeStorageURB(deviceNo, transferMode, pCmdBlock, &tranPara, &cbwUrb[deviceNo]);
if(result != STATUS_SUCCESS) {
return STATUS_UNSUCCESSFUL;
}
devicePara[deviceNo].commandStatus = WAIT_START;
devicePara[deviceNo].deviceStatus = DRV_FUNC_TRAN_READY;
#ifdef USBH_STRG_IF_COMMAND_PRINT
DBG_FlowStrPrint("\r\n[CMD[USB(DirectCopy)] :", 1);
for( i = 0; i < 12; i++ ){
DBG_FlowStrPrint(" ", 1);
DBG_FlowValPrint(PRINT_HEXA_MODE, DBG_STORE_BYTE, pCmdBlock->commandBlock[i], 1);
}
DBG_FlowStrPrint("]\r\n", 1);
#endif
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_IFCommandStop
//
// description : Force cancel the executing command of the specified device.
//
// Force cancel the executing command of the specified device.
// The command complete notification is not done.
//
// argument : deviceNo (in)Device No.
//
// return : STATUS_SUCCESS Completed successfully
// STATUS_UNSUCCESSFUL Completed with error
===============================================================================================*/
LONG USBH_STRG_IFCommandStop( USHORT deviceNo)
{
OS_FLGPTN flgPtn;
/* Cancel if the command is on executing */
switch(devicePara[deviceNo].commandStatus) {
case URB_LINK:
case WAIT_START:
USBH_USBD_UnlinkURB(&cbwUrb[deviceNo], classid, USBH_STRG_UnlinkURBCallback);
break;
case CBW_CMP:
USBH_USBD_UnlinkURB(&cbwUrb[deviceNo], classid, USBH_STRG_UnlinkURBCallback);
break;
case DATA_CMP:
USBH_USBD_UnlinkURB(&cbwUrb[deviceNo], classid, USBH_STRG_UnlinkURBCallback);
break;
case CSW_CMP:
devicePara[deviceNo].commandStatus = NO_OP;
break;
default:
break;
}
if(devicePara[deviceNo].commandStatus != NO_OP) {
/* Waiting for the completion of UnlinkURB */
OS_WaiFlg(FLGID_USBH_SAMPLE, FLG_EVENT_UNLINKURB_CMP_USBH_SAMPLE, OS_TWF_ORW, &flgPtn);
OS_ClrFlg(FLGID_USBH_SAMPLE, ~(FLG_EVENT_UNLINKURB_CMP_USBH_SAMPLE));
if(callbackPara.event != USBH_USBD_MSG_UNLINK_OK) {
return STATUS_UNSUCCESSFUL;
} else {
devicePara[deviceNo].commandStatus = NO_OP;
}
}
devicePara[deviceNo].deviceStatus = FOR_HARD_DIRECTCOPY;
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_IFDMAStartA
//
// description : An asynchronous data transfer is done between specified devices.
//
// An asynchronous data transfer is done between specified devices.
// When the transfer begins, the control is returned to a upper layer at once.
//
// argument : deviceNo (in)Device No.
// transferMode (in)Transfer mode of the command
// *pTranPara (in)Pointer that points to the data transfer parameter
//
// return : STATUS_SUCCESS Completed successfully
// STATUS_UNSUCCESSFUL Completed with error
===============================================================================================*/
LONG USBH_STRG_IFDMAStartA( USHORT deviceNo, UCHAR transferMode, DRIVEACCESS_FUNCTRANPARA *pTranPara, CALLBACK_PROC pfnNotifyDMAComp )
{
LONG result;
OS_FLGPTN flgPtn;
/* The URB that prepared with USBH_STRG_IFCommandOut() is registered. */
result = USBH_USBD_SubmitURB(&cbwUrb[deviceNo], classid, USBH_STRG_SubmitURBCallback);
if(result != STATUS_SUCCESS) {
return STATUS_UNSUCCESSFUL;
}
/* Waiting for the completion of URB registration*/
OS_WaiFlg(FLGID_USBH_SAMPLE, FLG_EVENT_SUBMITURB_CMP_USBH_SAMPLE, OS_TWF_ORW, &flgPtn);
OS_ClrFlg(FLGID_USBH_SAMPLE, ~(FLG_EVENT_SUBMITURB_CMP_USBH_SAMPLE));
if(callbackPara.event != USBH_USBD_MSG_SUBMIT_OK) {
return STATUS_UNSUCCESSFUL;
}
devicePara[deviceNo].deviceStatus = DRV_FUNC_CMD_EXEC;
devicePara[deviceNo].commandStatus = URB_LINK;
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_IFDMAStop
//
// description : Force cancel the asynchronous transfer of the specified device.
//
// Force cancel the asynchronous transfer of the specified device.
// The command complete notification is not done.
//
// argument : deviceNo (in)Device No.
//
// return : STATUS_SUCCESS Completed successfully
// STATUS_UNSUCCESSFUL Completed with error
===============================================================================================*/
LONG USBH_STRG_IFDMAStop( USHORT deviceNo )
{
OS_FLGPTN flgPtn;
switch(devicePara[deviceNo].commandStatus) {
case URB_LINK:
case WAIT_START:
USBH_USBD_UnlinkURB(&cbwUrb[deviceNo], classid, USBH_STRG_UnlinkURBCallback);
devicePara[deviceNo].commandStatus = NO_OP;
break;
case CBW_CMP:
USBH_USBD_UnlinkURB(&cbwUrb[deviceNo], classid, USBH_STRG_UnlinkURBCallback);
devicePara[deviceNo].commandStatus = NO_OP;
break;
case DATA_CMP:
USBH_USBD_UnlinkURB(&cbwUrb[deviceNo], classid, USBH_STRG_UnlinkURBCallback);
devicePara[deviceNo].commandStatus = NO_OP;
break;
case CSW_CMP:
devicePara[deviceNo].commandStatus = NO_OP;
break;
default:
break;
}
if(devicePara[deviceNo].commandStatus != NO_OP) {
/* Waiting for the completion of UnlinkURB */
OS_WaiFlg(FLGID_USBH_SAMPLE, FLG_EVENT_UNLINKURB_CMP_USBH_SAMPLE, OS_TWF_ORW, &flgPtn);
OS_ClrFlg(FLGID_USBH_SAMPLE, ~(FLG_EVENT_UNLINKURB_CMP_USBH_SAMPLE));
if(callbackPara.event != USBH_USBD_MSG_UNLINK_OK) {
return STATUS_UNSUCCESSFUL;
} else {
devicePara[deviceNo].commandStatus = NO_OP;
}
}
devicePara[deviceNo].deviceStatus = FOR_HARD_DIRECTCOPY;
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_IFGetStatus
//
// description : It informs the upper layer of the status of the connected device.
//
// It informs the upper layer of the status of the connected device.
// Get the request sense data automatically and notify the upper layer.
//
// argument : deviceNo (in)Device No.
// *pStatus (in)Pointer that points to the status.
// *pTransferSize (in)Pointer that point to the number of bytes that could be
// transfered in the previous data transfer process.
// *pSenseData (in)Pointer that points to the request sense data
//
// return : STATUS_SUCCESS Completed successfully
// STATUS_UNSUCCESSFUL Completed with error
===============================================================================================*/
LONG USBH_STRG_IFGetStatus( USHORT deviceNo, ULONG *pStatus, ULONG *pTransferSize, UCHAR *pSenseData )
{
UCHAR i;
*pStatus = DRV_FUNC_CMD_COMP;
/* Request Sense Data Set */
for(i = 0; i < REQSENSE_LENGTH; i++) {
*pSenseData = devicePara[deviceNo].reqSenseData[i];
pSenseData++;
}
/* Set the actual trnasfered data size of the last execute. */
*pTransferSize = dataUrb[deviceNo].actualLength;
/* Set the status that corresponds to the Sence Key */
switch( (devicePara[deviceNo].reqSenseData[2] & 0x0F) ) {
case MEDIUM_ERROR:
*pStatus = DRV_FUNC_NM_ERR;
break;
case HARDWARE_ERROR:
*pStatus = DRV_FUNC_DEVICE_ERR;
break;
case UNIT_ATTENTION:
*pStatus = DRV_FUNC_MC_ERR;
break;
}
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_IFSyncCommand
//
// description : The command is send to the specified device. (Synchronous processing)
//
// The command is issued to the specified device.
// The control doesn't return to upper layer until all operation ends.
//
// argument : deviceNo (in)Device No.
// transferMode (in)Transfer mode of the command
// *pTransferSize (in)Pointer that point to the number of bytes that could be
// transfered in the previous data transfer process.
// *pCmdBlock (in)Pointer that points to the command parameter
// *pTranPara (in)Pointer that points to the data transfer parameter
// *pStatus (in)Pointer that points to the status
// *pSenseData (in)Pointer that points to the request sense data
//
// return : STATUS_SUCCESS Completed successfully
// STATUS_UNSUCCESSFUL Completed with error
===============================================================================================*/
LONG USBH_STRG_IFSyncCommand( USHORT deviceNo, UCHAR transferMode, DRIVEACCESS_FUNCCMDPARA *pCmdBlock, DRIVEACCESS_FUNCTRANPARA *pTranPara, ULONG *pStatus, UCHAR *pSenseData )
{
UCHAR i;
USBH_STRG_CTL_SETUP *pSetupData;
LONG result;
USBH_USBD_URB *pUrb;
DRIVEACCESS_FUNCTRANPARA sTranParaLocal;
DRIVEACCESS_FUNCTRANPARA *pTranParaLocal;
DRIVEACCESS_FUNCCMDPARA sRQSenseCmdBlock;
DRIVEACCESS_FUNCCMDPARA *pRQSenseCmdBlock;
OS_FLGPTN flgPtn;
UCHAR endpointAdrs;
*pStatus = DRV_FUNC_CMD_COMP;
/* Check if the device exists */
if( pDeviceList->deviceType[deviceNo] == NO_DEVICE ){
*pStatus = DRV_FUNC_NM_ERR ;
return STATUS_UNSUCCESSFUL ;
}
#ifdef USBH_STRG_IF_COMMAND_PRINT
DBG_FlowStrPrint("\r\n[CMD[USB] :", 1);
for( i = 0; i < 12; i++ ){
DBG_FlowStrPrint(" ", 1);
DBG_FlowValPrint(PRINT_HEXA_MODE, DBG_STORE_BYTE, pCmdBlock->commandBlock[i], 1);
}
DBG_FlowStrPrint("]\r\n", 1);
DBG_FlowStrPrint("[BufAdrs : ", 1);
DBG_FlowValPrint(PRINT_HEXA_MODE, DBG_STORE_DWORD, pTranPara->dataPointer, 1);
DBG_FlowStrPrint("]\r\n", 1);
#endif
/* Create URB */
pUrb = &cbwUrb[deviceNo];
result = USBH_STRG_MakeStorageURB(deviceNo, transferMode, pCmdBlock, pTranPara, pUrb);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -