📄 usbd_func.c
字号:
*/
LONG USBD_FuncReset(void)
{
LONG retValue,retIFValue;
#ifdef AUTO_SET_ADDRESS_DIS /* Countermeasure against AutoSetAddress */
UCHAR savePmState;
#endif /* AUTO_SET_ADDRESS_DIS */
retValue = STATUS_SUCCESS;
while (1) {
/* Initialization */
/* Initialize variables */
// PrvOpenCnt = 0;
#ifdef DEBUG_C
PrvSkipSetup = 0;
//PrvRcvSetupCnt = 0;
PrvSimpleTransferExecute = 0;
#ifdef SETUPLOG
PrvSetupLogCount = 0;
memset(PrvSetupLog,0x00,32 * 8);
#endif
#endif
PrvInitVariables();
#ifdef AUTO_SET_ADDRESS_DIS /* Countermeasure against AutoSetAddress */
/* Check power management state. */
PM_IFGetPMState( &savePmState );
if( savePmState != PM_IF_PMSTATE_ACT_DEVICE ) {
/* Set power management active all state. */
PM_IFSetPMState( PM_IF_PMSTATE_ACT_DEVICE );
}
#endif /* AUTO_SET_ADDRESS_DIS */
/* Reset of USB I/F */
retIFValue = USBD_IFReset();
#ifdef AUTO_SET_ADDRESS_DIS /* Countermeasure against AutoSetAddress */
/* Check power management state. */
if( savePmState != PM_IF_PMSTATE_ACT_DEVICE ) {
/* Set power management active all state. */
PM_IFSetPMState( savePmState );
}
#endif /* AUTO_SET_ADDRESS_DIS */
retValue = IFRET_TO_FUNCRET(retIFValue);
break;};
return retValue;
}
/* Unused */
/* =============================================================================
// Function_Name: USBD_FuncAllocID
// description : Allocate the ID used in USB Function layer
// argument : pId Return the assigned ID
// return : STATUS_SUCCESS Finished normally
// : STATUS_NOT_ALLOCATE_ID Failed to allocate the ID
// =============================================================================
*/
LONG USBD_FuncAllocID(USHORT *pId)
{
LONG retValue;
USHORT i;
retValue = STATUS_SUCCESS;
while (1) {
/* Find the Free ID */
for (i = 0;i < MAX_ID;i++) {
if (PrvIdTable[i] == PRV_ID_UNUSED) {
break;
}
}
if (i < MAX_ID) {
/* Succeeded to allocate the ID */
/* Set it to using, and return the ID */
PrvIdTable[i] = PRV_ID_USED;
*pId = i;
} else {
/* When all of the ID are on using */
retValue = STATUS_NOT_ALLOCATE_ID;
}
break;};
return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncFreeID
// description : Release the ID used in USB Function layer
// argument : id ID
// return : STATUS_SUCCESS Finished normally
// : STATUS_NOT_OPENED Not be opened yet
// : STATUS_INVALID_PARAMETER Parameter error
// =============================================================================
*/
LONG USBD_FuncFreeID(USHORT id)
{
LONG retValue;
retValue = STATUS_SUCCESS;
while (1) {
/* Clear the flag of ID */
PrvIdTable[id] = PRV_ID_UNUSED;
break;};
return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncStart
// description : Start the operation of USB
// argument : mode [in] Operation mode(Normal operation,Force FS operation)
// return : STATUS_SUCCESS Finished normally
// return : STATUS_UNSUCCESSFUL Finished abnormally
// return : STATUS_NOT_OPENED Not be opened yet
// return : STATUS_INVALID_PARAMETER Parameter error
// =============================================================================
*/
LONG USBD_FuncStart(UCHAR mode)
{
LONG retValue;
USBD_IF_FEATURE_MODE feature;
retValue = STATUS_SUCCESS;
while (1) {
/* Ckeck if it is on operating */
if (IS_START() == TRUE) {
/* Return error if being on operating */
retValue = STATUS_UNSUCCESSFUL;
break;
}
retValue = USBD_IFGetFeatureMode(&feature);
if (mode == USBD_FUNC_ATTACH_NORMAL) {
feature.DisableHS = 0;
} else if (mode == USBD_FUNC_ATTACH_FORCEFS) {
feature.DisableHS = 1;
} else {
/* Parameter error */
retValue = STATUS_INVALID_PARAMETER;
break;
}
retValue = USBD_IFSetFeatureMode(&feature);
/* Do process of Attach */
retValue = PrvUsbBusAttach();
if (retValue != STATUS_SUCCESS) {
retValue = STATUS_UNSUCCESSFUL;
break;
}
/* Set the flag of being on operating */
SET_BIT(PrvStatusInfo.dwInternalStatus,PRV_IS_STARTED);
break;};
return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncStop
// description : Stop the operation of USB
// argument : None
// return : STATUS_SUCCESS Finished normally
// return : STATUS_UNSUCCESSFUL Finished abnormally
// return : STATUS_NOT_OPENED Not be opened yet
// =============================================================================
*/
LONG USBD_FuncStop(void)
{
LONG retValue;
retValue = STATUS_SUCCESS;
while (1) {
/* Initialize the information for Configuration Descriptor */
memset(&PrvConfigInfo,0x00,sizeof (PRV_CONFIG_INFO));
/* Set all of Endpoints to Disable */
PrvDisableEndpoints();
/* Do process of Detach */
retValue = PrvUsbBusDetach();
if (retValue != STATUS_SUCCESS) {
break;
}
/* Clear the flag of being on operating */
CLR_BIT(PrvStatusInfo.dwInternalStatus,PRV_IS_STARTED);
break;};
return retValue;
}
/* Unused */
/* =============================================================================
// Function_Name: USBD_FuncGetDescriptorInfoAddress
// description : Return address of Descriptor information which is set in USB Function layer
// argument : speed [in] Type of Descriptor(FS,HS,common)
// argument : type [in] Type of Descriptor(Device,Config,String, etc.)
// argument : **ptr [out] Pointer to return address which saves the Descriptor
// return : STATUS_SUCCESS Finished normally
// return : STATUS_UNSUCCESSFUL Finished abnormally
// return : STATUS_NOT_OPENED Not be opened yet
// return : STATUS_INVALID_PARAMETER Parameter error
// =============================================================================
*/
LONG USBD_FuncGetDescriptorInfoAddress(UCHAR speed,USHORT type,UCHAR **ptr)
{
LONG retValue;
UCHAR descType,descIndex;
PRV_DESCINFOPTR descInfoPtr;
retValue = STATUS_SUCCESS;
while (1) {
descType = HIBYTE(type);
descIndex = LOBYTE(type);
retValue = PrvGetDescriptorInfoAddress(speed,descType,descIndex,&descInfoPtr);
if (retValue != STATUS_SUCCESS) {
/* Unable to get the address of Descriptor saving */
break;
}
/* Return the address of Descriptor saving */
*ptr = *descInfoPtr.ptr;
break;};
return retValue;
}
/* =============================================================================
// description : Set the address of Descriptor used in USB Function layer
// argument : speed [in] Type of Descriptor(FS,HS,common)
// argument : type [in] Type of Descriptor(Device,Config,String, etc.)
// argument : *ptr [in] Pointer of address for Descriptor saving
// return : STATUS_SUCCESS Finished normally
// return : STATUS_UNSUCCESSFUL Finished abnormally
// return : STATUS_NOT_OPENED Not be opened yet
// return : STATUS_INVALID_PARAMETER Parameter error
// =============================================================================
*/
LONG USBD_FuncSetDescriptorInfoAddress(UCHAR speed,USHORT type,UCHAR *ptr)
{
LONG retValue;
UCHAR descType,descIndex;
UCHAR *tempFsPtr,*tempHsPtr;
UCHAR tempFsFlag,tempHsFlag;
USHORT tempSize;
PRV_DESCINFOPTR fsDescInfoPtr;
PRV_DESCINFOPTR hsDescInfoPtr;
retValue = STATUS_SUCCESS;
while (1) {
/* Check the argument of speed */
if (!( speed == USBD_FUNC_SPEEDCOMMON ||
speed == USBD_FUNC_SPEEDFS ||
speed == USBD_FUNC_SPEEDHS)) {
retValue = STATUS_INVALID_PARAMETER;
break;
}
/* Check the Descriptor which is be set, and get the size */
retValue = PrvGetDescriptorSize(ptr,&tempSize);
if (retValue != STATUS_SUCCESS) {
/* Unidentified Descriptor */
break;
}
descType = HIBYTE(type);
descIndex = LOBYTE(type);
/* Get the address of Descriptor saving and the flag used by FS */
retValue = PrvGetDescriptorInfoAddress(USBD_FUNC_SPEEDFS,descType,descIndex,&fsDescInfoPtr);
if (retValue != STATUS_SUCCESS) {
/* When parameter is incorrect */
break;
}
/* Get the address of Descriptor saving and the flag used by HS */
retValue = PrvGetDescriptorInfoAddress(USBD_FUNC_SPEEDHS,descType,descIndex,&hsDescInfoPtr);
if (retValue != STATUS_SUCCESS) {
/* When parameter is incorrect */
break;
}
tempFsPtr = *fsDescInfoPtr.ptr;
tempFsFlag = *fsDescInfoPtr.flag;
tempHsPtr = *hsDescInfoPtr.ptr;
tempHsFlag = *hsDescInfoPtr.flag;
if (speed == USBD_FUNC_SPEEDFS || speed == USBD_FUNC_SPEEDCOMMON) {
/* Release the area of FS Descriptor */
/* Set the address */
tempFsPtr = ptr;
/* Set the flag */
SET_BIT(tempFsFlag,PRV_DESCINF_ADR);
/* Set the Descriptor Address,Flag */
*fsDescInfoPtr.ptr = tempFsPtr;
*fsDescInfoPtr.flag = tempFsFlag;
}
if (speed == USBD_FUNC_SPEEDHS || speed == USBD_FUNC_SPEEDCOMMON) {
/* Release the area of HS Descriptor */
/* Set the address */
tempHsPtr = ptr;
/* Set the flag */
SET_BIT(tempHsFlag,PRV_DESCINF_ADR);
/* Set the Descriptor Address,Flag */
*hsDescInfoPtr.ptr = tempHsPtr;
*hsDescInfoPtr.flag = tempHsFlag;
}
break;};
return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncGetParameter
// description : Get parameter used in USB Function layer
// argument : type [in] Type of parameter
// argument : ptr [out] Pointer of address to return parameter
// argument : count [in] Size of parameter to return
// return : STATUS_SUCCESS Finished normally
// return : STATUS_NOT_OPENED Not be opened yet
// return : STATUS_INVALID_PARAMETER Parameter error
// =============================================================================
*/
LONG USBD_FuncGetParameter(UCHAR type,void *ptr,USHORT count)
{
LONG retValue;
retValue = STATUS_SUCCESS;
while (1) {
switch (type) {
case USBD_FUNC_HWFEATURE_PARAM:
/* Get parameter used by hardware support function */
memcpy(ptr,&PrvHwFeatureParam,MIN(PrvHwFeatureParam.bLength,count));
break;
case USBD_FUNC_SWFEATURE_PARAM:
/* Get parameter used by software function */
memcpy(ptr,&PrvSwFeatureParam,MIN(PrvSwFeatureParam.bLength,count));
break;
case USBD_FUNC_FIFOAREA_PARAM:
/* Get parameter of FIFO Area */
memcpy(ptr,&PrvFifoAreaParam,MIN(PrvFifoAreaParam.bLength,count));
break;
case USBD_FUNC_BULKONLY_PARAM:
/* Get parameter of BulkOnly */
memcpy(ptr,&PrvBulkOnlyParam,MIN(PrvBulkOnlyParam.bLength,count));
break;
default:
retValue = STATUS_INVALID_PARAMETER;
}
break;};
return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncSetParameter
// description : Set parameter used in USB Function layer
// argument : *ptr [in] Address of parameter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -