📄 usbh_storage_api.c
字号:
if( deviceNo >= USBH_STRG_MAX_DEVICE ){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check whether other ID is using Device. */
if(deviceStatus[deviceNo].id != id && deviceStatus[deviceNo].id != NO_ID ) {
/* Device is operating. */
return STATUS_EXECUTION_PORT;
}
result = USBH_STRG_IFGetStatus(deviceNo, pStatus, pTransferSize, pSenseData);
if(*pStatus == DRV_FUNC_CMD_COMP) {
*pStatus = deviceStatus[deviceNo].cmdStatus;
}
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncSyncCommand
//
// description : Send command to the specified device (fsSynchronous processing)
//
// Send command to the specified device.
// The control doesn't return to upper layer until all operation ends.
//
// argument : id (in)ID value
// deviceNo (in)Device No.
// transferMode (in)The transfer mode of the command
// *pTransferSize (in)Pointer that point to the number of bytes that could be
// transfered in the just finished 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 Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_EXECUTION_PORT The specified port is running
===============================================================================================*/
LONG USBH_STRG_FuncSyncCommand( USHORT id, USHORT deviceNo, UCHAR transferMode, DRIVEACCESS_FUNCCMDPARA *pCmdBlock, DRIVEACCESS_FUNCTRANPARA *pTranPara, ULONG *pStatus, UCHAR *pSenseData )
{
LONG result;
ULONG cmdStatus;
UCHAR detectUnitAtten;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check the ID value */
if((id - 1) > USBH_STRG_MAX_ID || (IdTable[id-1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check the DeviceNo */
if( deviceNo >= USBH_STRG_MAX_DEVICE ){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check whether Device is executing the data transfer. */
/* Check whether Device is executing the command. */
if(deviceStatus[deviceNo].cmdStatus == DRV_FUNC_CMD_EXEC) {
/* Device is operating. */
return STATUS_EXECUTION_PORT;
}
/* Check whether Device is transfering data. */
if(deviceStatus[deviceNo].dmaStatus == DRV_DMA_FUNC_EXEC) {
/* It is transfering the device data */
return STATUS_EXECUTION_PORT;
}
/* Check whether the transfer mode is DirectCopy Mode */
if(transferMode == FOR_HARD_DIRECTCOPY) {
/* It is DirectCopy Mode*/
return STATUS_INVALID_PARAMETER;
}
/* Command Status Set */
deviceStatus[deviceNo].id = id;
deviceStatus[deviceNo].cmdStatus = DRV_FUNC_CMD_EXEC;
detectUnitAtten = 0;
while(1){
LED_On(8);
result = USBH_STRG_IFSyncCommand(deviceNo, transferMode, pCmdBlock, pTranPara, &cmdStatus, pSenseData);
LED_Off(8);
if( result == STATUS_SUCCESS ){
break;
} else if( cmdStatus != DRV_FUNC_MC_ERR ){
detectUnitAtten = 0;
break;
}
detectUnitAtten = 1;
}
if( detectUnitAtten == 1 ){
*pStatus = DRV_FUNC_MC_ERR;
} else {
*pStatus = cmdStatus;
}
/* Command Status Clear */
deviceStatus[deviceNo].id = NO_ID;
deviceStatus[deviceNo].cmdStatus = DRV_FUNC_CMD_COMP;
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncRegisterCBRDMAComp
//
// description : Register the asynchronous data transfer completion CALL BACK.
//
// When an asynchronous data transfer ends, register a notification function.
//
// argument : id (in)ID value
// cbrID (in)CALLBACK identifier
// deviceNo (in)Device No.
// pfnNotifyDMAComp (in)Pointer of callback function
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_UNABLE_TO_REGISTER Unregistered
===============================================================================================*/
LONG USBH_STRG_FuncRegisterCBRDMAComp( USHORT id, USHORT cbrID, USHORT deviceNo, CALLBACK_PROC pfnNotifyDMAComp )
{
LONG result;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check the ID value */
if((id - 1) > USBH_STRG_MAX_ID || (IdTable[id-1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check the DeviceNo */
if( deviceNo >= USBH_STRG_MAX_DEVICE ){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check if the CALL BACK is registered */
if(USBH_STRG_DMACompCBR[deviceNo][id - 1] != NULL){
/* The CALL BACK has been registered. */
return STATUS_UNABLE_TO_REGISTER;
}
/* register the CALL BACK */
USBH_STRG_DMACompCBR[deviceNo][id -1] = pfnNotifyDMAComp;
USBH_STRG_DMACompCbrID[deviceNo][id - 1] = cbrID;
/* Register lower layer CALL BACK*/
result = USBH_STRG_IFRegisterCBRDMAComp( deviceNo, USBH_STRG_FuncNotifyDMAComp );
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncUnregisterCBRDMAComp
//
// description : Delete the asynchronous data transfer completion CALL BACK.
//
// Delete the notify function when the asynchronous data transfer ends.
//
// argument : id (in)ID value
// cbrID (in)CALLBACK identifier
// deviceNo (in)Device No.
// pfnNotifyDMAComp (in)Pointer of callback function
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_UNREGISTERED Unregistered
===============================================================================================*/
LONG USBH_STRG_FuncUnregisterCBRDMAComp( USHORT id, USHORT cbrID, USHORT deviceNo, CALLBACK_PROC pfnNotifyDMAComp )
{
LONG result;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check the ID value */
if((id - 1) > USBH_STRG_MAX_ID || (IdTable[id-1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check the DeviceNo */
if( deviceNo >= USBH_STRG_MAX_DEVICE ){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check if the CALL BACK is registered */
if(USBH_STRG_DMACompCBR[deviceNo][id - 1] != pfnNotifyDMAComp){
/* CALL BACK is not registered*/
return STATUS_UNREGISTERED;
}
/* Clear the CALL BACK */
USBH_STRG_DMACompCBR[deviceNo][id - 1] = NULL;
/* Clear the CALL BACK of the lower layer */
result = USBH_STRG_IFUnregisterCBRDMAComp( deviceNo, USBH_STRG_FuncNotifyDMAComp );
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncRegisterCBRIntrqComp
//
// description : Register the asynchronous data transfer completion CALL BACK.
//
// Register the notify function when the asynchronous data transfer ends.
//
// argument : id (in)ID value
// cbrID (in)CALLBACK identifier
// deviceNo (in)Device No.
// pfnNotifyDMAComp (in)Pointer of callback function
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_UNABLE_TO_REGISTER Unregistered
===============================================================================================*/
LONG USBH_STRG_FuncRegisterCBRIntrqComp( USHORT id, USHORT cbrID, USHORT deviceNo, CALLBACK_PROC pfnNotifyIntrqComp )
{
LONG result;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check the ID value */
if((id - 1) > USBH_STRG_MAX_ID || (IdTable[id - 1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check the DeviceNo */
if( deviceNo >= USBH_STRG_MAX_DEVICE ){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check if the CALL BACK is registered */
if(USBH_STRG_IntrqCompCBR[deviceNo][id - 1] != NULL){
/* The CALL BACK has been registered. */
return STATUS_UNABLE_TO_REGISTER;
}
/* Register the CALL BACK */
USBH_STRG_IntrqCompCBR[deviceNo][id - 1] = pfnNotifyIntrqComp;
USBH_STRG_IntrqCompCbrID[deviceNo][id - 1] = cbrID;
/* Register lower layer CALL BACK*/
result = USBH_STRG_IFRegisterCBRIntrqComp( deviceNo, USBH_STRG_FuncNotifyIntrqComp );
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncUnregisterCBRIntrqComp
//
// description : Delete the asynchronous command completion CALLBACK .
//
// When the asynchronous command complete, delete the function that used for notification.
//
// argument : id (in)ID value
// cbrID (in)Callback identifier
// deviceNo (in)Device No.
// pfnNotifyDMAComp (in)pointer that points to the CALL BACK function
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_UNREGISTERED Unregistered
===============================================================================================*/
LONG USBH_STRG_FuncUnregisterCBRIntrqComp( USHORT id, USHORT cbrID, USHORT deviceNo, CALLBACK_PROC pfnNotifyIntrqComp )
{
LONG result;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check the ID value */
if((id - 1) > USBH_STRG_MAX_ID || (IdTable[id - 1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check the DeviceNo */
if( deviceNo >= USBH_STRG_MAX_DEVICE ){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* CALL BACK register check*/
if(USBH_STRG_IntrqCompCBR[deviceNo][id - 1] != pfnNotifyIntrqComp){
/* CALL BACK is not registered*/
return STATUS_UNREGISTERED;
}
/* Clear the CALL BACK */
USBH_STRG_IntrqCompCBR[deviceNo][id - 1] = NULL;
/* Clear the CALL BACK of the lower layer */
result = USBH_STRG_IFUnregisterCBRIntrqComp( deviceNo, USBH_STRG_FuncNotifyIntrqComp );
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncNotifyDMAComp
//
// description : DATA transfer complete CALL BACK process
//
// DATA transfer complete CALL BACK process during DirectCopy.
//
// argument : deviceNo (in)Device No.
// ULONG result Result
// ULONG VOID *pReserve Reserved
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
===============================================================================================*/
LONG USBH_STRG_FuncNotifyDMAComp(ULONG deviceNo, ULONG result, VOID *pReserve )
{
if(USBH_STRG_DMACompCBR[deviceNo][deviceStatus[deviceNo].id - 1] != NULL){
deviceStatus[deviceNo].dmaStatus = DRV_DMA_FUNC_COMP;
/* Call the CALLBACK to the FileSystem.*/
storageCbrID.cbrID = USBH_STRG_DMACompCbrID[deviceNo][deviceStatus[deviceNo].id - 1];
storageCbrID.allocID = deviceStatus[deviceNo].id;
USBH_STRG_DMACompCBR[deviceNo][deviceStatus[deviceNo].id - 1]( deviceNo, result, (VOID *) &storageCbrID );
}
else {
return STATUS_UNSUCCESSFUL;
}
/* COMPLETE */
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncNotifyIntrqComp
//
// description : Process Intrq complete CALL BACK
//
// Process the command complete CALL BACK during DirectCopy.
//
// argument : deviceNo (in)Device No.
// ULONG result Result
// ULONG VOID *pReserve Reserved
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
===============================================================================================*/
LONG USBH_STRG_FuncNotifyIntrqComp(ULONG deviceNo, ULONG result, VOID *pReserve )
{
if(USBH_STRG_IntrqCompCBR[deviceNo][deviceStatus[deviceNo].id - 1] != NULL){
LED_Off(8);
deviceStatus[deviceNo].cmdStatus = DRV_FUNC_CMD_COMP;
/* Call the CALLBACK of the FileSystem.*/
storageCbrID.cbrID = USBH_STRG_IntrqCompCbrID[deviceNo][deviceStatus[deviceNo].id - 1];
storageCbrID.allocID = deviceStatus[deviceNo].id;
USBH_STRG_IntrqCompCBR[deviceNo][deviceStatus[deviceNo].id - 1]( deviceNo, result, (VOID *) &storageCbrID );
}
else {
return STATUS_UNSUCCESSFUL;
}
/* COMPLETE */
return STATUS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -