📄 usbh_ide_if.c
字号:
} else {
result = STATUS_UNSUCCESSFUL;
}
// Free the message buffer
OS_RelMpf( pMsg->msgHead.useMpfId, pMsg );
return result;
}
/*=============================================================================================
// Function_Name: USBH_IDE_IFGetDeviceParameter
//
// description : It informs the detailed information of the device to the upper layer
//
// It informs the detailed information of the device to the upper layer
// Can use Identify (Packet) Device to get the device information.Device inforamation is 256 words data.
//
// argument : deviceNo (in)Device No.
// *pDataPtr (out)Pointer of the device information
//
// return : STATUS_SUCCESS Complete the process normally
// STATUS_UNSUCCESSFUL Error occured during the process
===============================================================================================*/
LONG USBH_IDE_IFGetDeviceParameter( USHORT deviceNo, UCHAR *pDataPtr)
{
UCHAR inqData[INQUIRY_LENGTH], rdFormCapaData[RDFORMCAPA_LENGTH];
LONG result;
PARAM_MSG_REQ_IDE_CMD IdeCmd, *pIdeCmd; // The structure used to send command to IDE
OS_FLGPTN flgPtn;
USBH_SAMPLE_MSG *pMsg;
pIdeCmd = &IdeCmd;
/* Command Block Initialize */
memset(pIdeCmd->IDECmd, 0x00, sizeof(pIdeCmd->IDECmd));
/* Execute INQUIRY */
USBH_IDE_MakeIdeCmd(deviceNo, INQUIRY, pIdeCmd);
pIdeCmd->xferMode = IDE_XFER_SPIO;
pIdeCmd->reqDataLen = INQUIRY_LENGTH;
pIdeCmd->bufferPtr = inqData;
/* Send message to IDE Task */
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_CMD, sizeof(*pIdeCmd), pIdeCmd );
// Waiting for the message from the IDETask
OS_WaiFlg( FLGID_USBH_SAMPLE, FLG_EVENT_MSG_USBH_SAMPLE, OS_TWF_ORW, &flgPtn );
// Clear flag
OS_ClrFlg( FLGID_USBH_SAMPLE, ~(FLG_EVENT_MSG_USBH_SAMPLE) );
// Receive message from mailbox.
OS_PRcvMbx( FLGID_USBH_SAMPLE, ( T_MSG** )&pMsg );
if( ((PARAM_MSG_NTFY_IDE_CMD *)pMsg->msgData)->result == IDE_REQ_OK) {
result = STATUS_SUCCESS;
} else {
result = STATUS_UNSUCCESSFUL;
}
// Free the message buffer
OS_RelMpf( pMsg->msgHead.useMpfId, pMsg );
/*** Generate Identify Data ***/
/* Device Type Set */
devicePara[deviceNo].identifyData[0] = inqData[0] & 0x1F;
/* Removable Set */
if( (inqData[1] & 0x80) != 0) {
devicePara[deviceNo].identifyData[1] = inqData[1];
} else {
/* Removal Bit is turned on at non-Removable device. */
devicePara[deviceNo].identifyData[1] = (~inqData[1]) & 0x40;
}
/* Vendor ID Set */
devicePara[deviceNo].identifyData[54] = inqData[8];
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];
/* Command Block Initialize */
memset(pIdeCmd->IDECmd, 0x00, sizeof(pIdeCmd->IDECmd));
/* Execute READ CAPACITY */
USBH_IDE_MakeIdeCmd(deviceNo, READ_CAPACITY, pIdeCmd);
pIdeCmd->xferMode = IDE_XFER_SPIO;
pIdeCmd->reqDataLen = RDCAPA_LENGTH;
pIdeCmd->bufferPtr = devicePara[deviceNo].rdCapaData;
/* Send message to IDE Task */
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_CMD, sizeof(*pIdeCmd), pIdeCmd );
// Waiting for the mesage from the IDETask
OS_WaiFlg( FLGID_USBH_SAMPLE, FLG_EVENT_MSG_USBH_SAMPLE, OS_TWF_ORW, &flgPtn );
// Clear flag
OS_ClrFlg( FLGID_USBH_SAMPLE, ~(FLG_EVENT_MSG_USBH_SAMPLE) );
// Receive message from mailbox.
OS_PRcvMbx( FLGID_USBH_SAMPLE, ( T_MSG** )&pMsg );
if( ((PARAM_MSG_NTFY_IDE_CMD *)pMsg->msgData)->result == IDE_REQ_OK) {
result = STATUS_SUCCESS;
} else {
result = STATUS_UNSUCCESSFUL;
}
// Free the message buffer
OS_RelMpf( pMsg->msgHead.useMpfId, pMsg );
/* Command Block Initialize */
memset(pIdeCmd->IDECmd, 0x00, sizeof(pIdeCmd->IDECmd));
/* Execute READ FORMAT CAPACITY */
USBH_IDE_MakeIdeCmd(deviceNo, READ_FORMAT_CAPACITY, pIdeCmd);
pIdeCmd->xferMode = IDE_XFER_SPIO;
pIdeCmd->reqDataLen = RDFORMCAPA_LENGTH;
pIdeCmd->bufferPtr = rdFormCapaData;
/* Send message to IDE Task */
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_CMD, sizeof(*pIdeCmd), pIdeCmd );
// Waiting for the mesage from the IDETask
OS_WaiFlg( FLGID_USBH_SAMPLE, FLG_EVENT_MSG_USBH_SAMPLE, OS_TWF_ORW, &flgPtn );
// Clear flag
OS_ClrFlg( FLGID_USBH_SAMPLE, ~(FLG_EVENT_MSG_USBH_SAMPLE) );
// Receive message from mailbox.
OS_PRcvMbx( FLGID_USBH_SAMPLE, ( T_MSG** )&pMsg );
if( ((PARAM_MSG_NTFY_IDE_CMD *)pMsg->msgData)->result == IDE_REQ_OK) {
result = STATUS_SUCCESS;
} else {
result = STATUS_UNSUCCESSFUL;
}
// Free the message buffer
OS_RelMpf( pMsg->msgHead.useMpfId, pMsg );
/* 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];
/* Set device information */
memcpy(pDataPtr, &devicePara[deviceNo].identifyData, sizeof(devicePara[deviceNo].identifyData));
result = STATUS_SUCCESS;
return result;
}
/*=============================================================================================
// Function_Name: USBH_IDE_IFCommandOut
//
// description : Send command to the specified device (Asyncronous (Asynchronous processing)
//
// Send command to the specified device.
// The issued command can be invalidated with USBH_IDE_FuncDMAStop.
// It does not do the data transfer with the device until USBH_IDE_IFDMAStartA is called.
//
// argument : deviceNo (in)Device No.
// transferMode (in)Transfer mode of commands
// *pCmdBlock (in)Pointer of the command parameter
//
// return : STATUS_SUCCESS Complete the process normally
// STATUS_UNSUCCESSFUL Error occured during the process
// USBH_IDE_STATUS_DMA_EXEC Specified device is transfering data
===============================================================================================*/
LONG USBH_IDE_IFCommandOut( USHORT deviceNo, UCHAR transferMode, DRIVEACCESS_FUNCCMDPARA *pCmdBlock )
{
#ifdef USBH_IDE_IF_COMMAND_PRINT
UCHAR i;
#endif
/* Save command. */
memcpy(&devicePara[deviceNo].commandBlock, pCmdBlock->commandBlock, sizeof(devicePara[deviceNo].commandBlock));
devicePara[deviceNo].commandStatus = WAIT_START;
devicePara[deviceNo].deviceStatus = DRV_FUNC_TRAN_READY;
#ifdef USBH_IDE_IF_COMMAND_PRINT
DBG_FlowStrPrint("\r\n[CMD[IDE(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 STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_IDE_IFCommandStop
//
// description : Force stop the on executing command of the specifed device
//
// It sets it while executing a specified device in the command.
// The command end notification is not done.
//
// argument : deviceNo (in)Device No.
//
// return : STATUS_SUCCESS Complete the process normally
// STATUS_UNSUCCESSFUL Error occured during the process
===============================================================================================*/
LONG USBH_IDE_IFCommandStop( USHORT deviceNo)
{
LONG result;
OS_FLGPTN flgPtn;
USBH_SAMPLE_MSG *pMsg;
/* Send message to IDE Task */
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_SRST, 0, NULL ); // IDE device reset request
// Waiting for the reset completion message from the IDEtask
OS_WaiFlg( FLGID_USBH_SAMPLE, FLG_EVENT_MSG_USBH_SAMPLE, OS_TWF_ORW, &flgPtn );
// Clear flag
OS_ClrFlg( FLGID_USBH_SAMPLE, ~(FLG_EVENT_MSG_USBH_SAMPLE) );
// Receive message from mailbox.
OS_PRcvMbx( FLGID_USBH_SAMPLE, ( T_MSG** )&pMsg );
if( ((PARAM_MSG_NTFY_IDE_SRST *)pMsg->msgData)->result == IDE_REQ_OK) {
result = STATUS_SUCCESS;
} else {
result = STATUS_UNSUCCESSFUL;
}
// Free the message buffer
OS_RelMpf( pMsg->msgHead.useMpfId, pMsg );
devicePara[deviceNo].commandStatus = NO_OP;
devicePara[deviceNo].deviceStatus = DRV_FUNC_CMD_STOP;
return result;
}
/*=============================================================================================
// Function_Name: USBH_IDE_IFDMAStartA
//
// description : Executes asyncronous data transfer with specified device.
//
// Executes asyncronous data transfer with specified device.
// Control is gave back to the caller when transfer is started.
//
// argument : deviceNo (in)Device No.
// transferMode (in)Transfer mode of command.
// *pTranPara (in)Pointer of data transfer parameters.
//
// return : STATUS_SUCCESS Complete the process normally
// STATUS_UNSUCCESSFUL Error occured during the process
// USBH_IDE_STATUS_DMA_EXEC Specified device is transfering data
===============================================================================================*/
LONG USBH_IDE_IFDMAStartA( USHORT deviceNo, UCHAR transferMode, DRIVEACCESS_FUNCTRANPARA *pTranPara )
{
PARAM_MSG_REQ_IDE_CMD IdeCmd; // Command structure to send to IDE
/* Join Clear AllMediaFIFO */
RegWrite( REG08_ClrAllMediaFIFO_Join,
( BIT_ClrJoinIDE |
BIT_ClrJoinDMA1 |
BIT_ClrJoinDMA0 |
BIT_ClrJoinCPU_Rd |
BIT_ClrJoinCPU_Wr ) );
/* Set direction of IDE */
if(pTranPara->direction == DRV_FUNC_IN) {
RegModify( REG08_IDE_Control, MASK_IDE_Dir, BIT_IDEtoFIFO);
} else {
RegModify( REG08_IDE_Control, MASK_IDE_Dir, BIT_FIFOtoIDE);
}
// Make IDE command.
memcpy( &IdeCmd.IDECmd, devicePara[deviceNo].commandBlock, sizeof(IdeCmd.IDECmd) );
USBH_IDE_MakeIdeCmd(deviceNo, devicePara[deviceNo].commandBlock[0], &IdeCmd);
IdeCmd.opeMode = IDE_CMD_MANUAL; /* Command MANUAL Mode */
IdeCmd.xferMode = IDE_XFER_DIRECT;
IdeCmd.reqDataLen = MAKEWORD(devicePara[deviceNo].commandBlock[8], devicePara[deviceNo].commandBlock[7]) * 512;
IdeCmd.pfnCallback = USBH_IDE_DirectCopyCallback;
RegWrite( REG08_IDE_IntStat, 0xF7 );
RegSet( REG08_MainIntEnb, BIT_EnIDE_IntStat );
/* Send message to IDE Task */
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_CMD, sizeof(IdeCmd), &IdeCmd );
devicePara[deviceNo].deviceStatus = DRV_FUNC_CMD_EXEC;
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_IDE_IFDMAStop
//
// description : Force stop the Asynchronous data transfer
//
// Force stop the Asynchronous data transfer.
// The command end notification is not done.
//
// argument : deviceNo (in)Device No.
//
// return : STATUS_SUCCESS Complete the process normally
// STATUS_UNSUCCESSFUL Error occured during the process
===============================================================================================*/
LONG USBH_IDE_IFDMAStop( USHORT deviceNo )
{
LONG result;
OS_FLGPTN flgPtn;
USBH_SAMPLE_MSG *pMsg;
/* Send message to IDE Task */
USBH_IDE_SendMessage( MBXID_IDE, MSG_REQ_IDE_SRST, 0, NULL ); // Request IDE device reset
// Waiting for the reset completion message from the IDEtask
OS_WaiFlg( FLGID_USBH_SAMPLE, FLG_EVENT_MSG_USBH_SAMPLE, OS_TWF_ORW, &flgPtn );
// Clear flag
OS_ClrFlg( FLGID_USBH_SAMPLE, ~(FLG_EVENT_MSG_USBH_SAMPLE) );
// Receive message from mailbox.
OS_PRcvMbx( FLGID_USBH_SAMPLE, ( T_MSG** )&pMsg );
if( ((PARAM_MSG_NTFY_IDE_SRST *)pMsg->msgData)->result == IDE_REQ_OK) {
result = STATUS_SUCCESS;
} else {
result = STATUS_UNSUCCESSFUL;
}
// Free the message buffer
OS_RelMpf( pMsg->msgHead.useMpfId, pMsg );
devicePara[deviceNo].commandStatus = NO_OP;
devicePara[deviceNo].deviceStatus = DRV_FUNC_CMD_STOP;
return result;
}
/*=============================================================================================
// Function_Name: USBH_IDE_IFGetStatus
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -