📄 usb_core.c
字号:
ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
if (Length > save_wLength)
Length = save_wLength;
DataBuffer = (*pEPinfo->CopyData)(Length);
UserToPMABufferCopy(DataBuffer,GetEPTxAddr(ENDP0),Length);
SetEPTxCount(ENDP0, Length);
pEPinfo->Usb_wLength -= Length;
pEPinfo->Usb_wOffset += Length;
vSetEPTxStatus(EP_TX_VALID);
USB_StatusOut();/* Expect the host to abort the data IN stage */
Expect_Status_Out:
pInformation->ControlState = ControlState;
}
/*******************************************************************************
* Function Name : NoData_Setup0
* Description : Proceed the processing of setup request without data stage
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NoData_Setup0(void)
{
RESULT Result = USB_UNSUPPORT;
u32 RequestNo = pInformation->USBbRequest;
u32 ControlState;
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/* Device Request*/
/* SET_CONFIGURATION*/
if (RequestNo == SET_CONFIGURATION)
Result = Standard_SetConfiguration();
/*SET ADDRESS*/
else if (RequestNo == SET_ADDRESS){
if(pInformation->USBwValue0 > 127 || pInformation->USBwValue1!=0
||pInformation->USBwIndex!=0 || pInformation->Current_Configuration!=0) /* Device Address should be 127 or less*/
/*call Beck spec USB 2.0*/
{
ControlState = STALLED;
goto exit_NoData_Setup0;
}
else Result = USB_SUCCESS;
}
/*SET FEATURE for Device*/
else if (RequestNo == SET_FEATURE){
if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5))
Result = Standard_SetDeviceFeature();
else
Result = USB_UNSUPPORT;
}
/*Clear FEATURE for Device */
else if (RequestNo == CLEAR_FEATURE){
if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5))
Result = Standard_ClearFeature();
else
Result = USB_UNSUPPORT;
}
}
/* Interface Request*/
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) {
/*SET INTERFACE*/
if (RequestNo == SET_INTERFACE)
Result = Standard_SetInterface();
}
/* EndPoint Request*/
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {
/*CLEAR FEATURE for EndPoint*/
if (RequestNo == CLEAR_FEATURE)
Result = Standard_ClearFeature();
/* SET FEATURE for EndPoint*/
else if (RequestNo == SET_FEATURE){
Result = Standard_SetEndPointFeature();
}
}
else
Result = USB_UNSUPPORT;
if (Result != USB_SUCCESS) {
Result = (*pProperty->Class_NoData_Setup)(RequestNo);
if (Result == USB_NOT_READY) {
ControlState = PAUSE;
goto exit_NoData_Setup0;
}
}
if (Result != USB_SUCCESS) {
ControlState = STALLED;
goto exit_NoData_Setup0;
}
ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */
USB_StatusIn();
exit_NoData_Setup0:
pInformation->ControlState = ControlState;
return;
}
/*******************************************************************************
* Function Name : Data_Setup0
* Description : Proceed the processing of setup request with data stage
* Input :
* Output :
* Return :
*******************************************************************************/
void Data_Setup0(void)
{
u8 *(*CopyRoutine)(u16);
RESULT Result;
u32 Request_No = pInformation->USBbRequest;
u32 Related_Endpoint,Reserved;
u32 wOffset,Status;
CopyRoutine = NULL;
wOffset = 0;
if (Request_No == GET_DESCRIPTOR) {
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {
u8 wValue1 = pInformation->USBwValue1;
if (wValue1 == DEVICE_DESCRIPTOR)
CopyRoutine = pProperty->GetDeviceDescriptor;
else if (wValue1 == CONFIG_DESCRIPTOR)
CopyRoutine = pProperty->GetConfigDescriptor;
else if (wValue1 == STRING_DESCRIPTOR) {
CopyRoutine = pProperty->GetStringDescriptor;
} /* End of GET_DESCRIPTOR */
}
}
/*GET STATUS*/
else if (Request_No == GET_STATUS && pInformation->USBwValue==0 && pInformation->USBwLength == 0x0002 && pInformation->USBwIndex1==0) {
/* GET STATUS for Device*/
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) && pInformation->USBwIndex==0) {
CopyRoutine = Standard_GetStatus;
}
/* GET STATUS for Interface*/
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)){
if ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,0)==USB_SUCCESS && pInformation->Current_Configuration!=0)
CopyRoutine = Standard_GetStatus;
}
/* GET STATUS for EndPoint*/
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)){
Related_Endpoint = (pInformation->USBwIndex0 & 0x0f);
Reserved= pInformation->USBwIndex0 & 0x70;
if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/*Get Status of endpoint & stall the request if
the related_ENdpoint is Disabled*/
else Status =_GetEPRxStatus(Related_Endpoint);
if(Related_Endpoint < Device_Table.Total_Endpoint && Reserved==0 && Status != 0)
CopyRoutine = Standard_GetStatus;
}
}
/*GET CONFIGURATION*/
else if (Request_No == GET_CONFIGURATION) {
if ( Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) )
CopyRoutine = Standard_GetConfiguration;
}
/*GET INTERFACE*/
else if (Request_No == GET_INTERFACE) {
if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT) && pInformation->Current_Configuration!=0
&& pInformation->USBwValue==0 && pInformation->USBwIndex1==0 && pInformation->USBwLength == 0x0001
&& (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,0)==USB_SUCCESS)
CopyRoutine = Standard_GetInterface;
}
if (CopyRoutine) {
pInformation->Ctrl_Info.Usb_wOffset = wOffset;
pInformation->Ctrl_Info.CopyData = CopyRoutine;
/* sb in the original the cast to word was directly */
/* now the cast is made step by step */
(*CopyRoutine)(0);
Result = USB_SUCCESS;
}
else {
Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest);
if (Result == USB_NOT_READY) {
pInformation->ControlState = PAUSE;
return;
}
}
if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF) { /* Data is not ready, wait it */
pInformation->ControlState = PAUSE;
return;
}
if (Result == USB_UNSUPPORT || pInformation->Ctrl_Info.Usb_wLength == 0) {
/* Unsupported request */
pInformation->ControlState = STALLED;
return;
}
if (ValBit(pInformation->USBbmRequestType, 7)) {
/* Device ==> Host */
u32 wLength = pInformation->USBwLength;
/* Restrict the data length to be the one host asks */
if (pInformation->Ctrl_Info.Usb_wLength > wLength)
pInformation->Ctrl_Info.Usb_wLength = wLength;
pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
DataStageIn();
}
else {
pInformation->ControlState = OUT_DATA;
vSetEPRxStatus(EP_RX_VALID);/* enable for next data reception */
}
return;
} /* Data_Setup0 */
/*******************************************************************************
* Function Name : Setup0_Process
* Description : Get the device request data and dispatch to individual process
* Input :
* Output :
* Return :
*******************************************************************************/
u8 Setup0_Process(void)
{
#ifdef STR7xx /* STR7xx family*/
union {
u8* b;
u16* w;
} pBuf;
pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0)*2); /* *2 for 32 bits addr */
if (pInformation->ControlState != PAUSE) {
pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
pInformation->USBbRequest = *pBuf.b++; /* bRequest */
pBuf.w++; /* word not accessed because of 32 bits addressing */
pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
pBuf.w++; /* word not accessed because of 32 bits addressing */
pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */
pBuf.w++; /* word not accessed because of 32 bits addressing */
pInformation->USBwLength = *pBuf.w; /* wLength */
}
#endif/* End of STR7xx family*/
#ifdef STR91x /* STR91x family*/
u16* pBuf;
pBuf= (u16 *)(GetEPRxAddr(ENDP0)+PMAAddr);
if (pInformation->ControlState != PAUSE)
{
pInformation->USBbmRequestType = (*pBuf)&0xFF; /* bmRequestType */
pInformation->USBbRequest = ((*pBuf)&0xFF00)>>8; /* bRequest */
pInformation->USBwValue = ByteSwap(*(pBuf+1)); /* wValue */
pInformation->USBwIndex = ByteSwap(*(pBuf+2)); /* wIndex */
pInformation->USBwLength = *(pBuf+3); /* wLength */
}
#endif /* End of STR91x family*/
pInformation->ControlState = SETTING_UP;
if (pInformation->USBwLength == 0)
{
/* Setup with no data stage */
NoData_Setup0();
}
else
{
/* Setup with data stage */
Data_Setup0();
}
return Post0_Process();
}
/*******************************************************************************
* Function Name : In0_Process
* Description : Process the IN token on all default endpoint
* Input :
* Output :
* Return :
*******************************************************************************/
u8 In0_Process(void)
{
u32 ControlState = pInformation->ControlState;
if (ControlState == IN_DATA || ControlState == LAST_IN_DATA)
{
DataStageIn();
ControlState = pInformation->ControlState; /* may be changed outside the function */
}
else if (ControlState == WAIT_STATUS_IN) {
if (pInformation->USBbRequest == SET_ADDRESS &&
Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) )
{
SetDeviceAddress(pInformation->USBwValue0);
pUser_Standard_Requests->User_SetDeviceAddress();
}
(*pProperty->Process_Status_IN)();
ControlState = STALLED;
}
else
ControlState = STALLED;
pInformation->ControlState = ControlState;
return Post0_Process();
}
/*******************************************************************************
* Function Name : Out0_Process
* Description : Process the OUT token on all default endpoint
* Input :
* Output :
* Return :
*******************************************************************************/
u8 Out0_Process(void)
{
u32 ControlState = pInformation->ControlState;
if(ControlState == OUT_DATA || ControlState == LAST_OUT_DATA)
DataStageOut();
else if (ControlState == WAIT_STATUS_OUT) {
(*pProperty->Process_Status_OUT)();
ControlState = STALLED;
}
else if (ControlState == IN_DATA || ControlState == LAST_IN_DATA) {
/* host aborts the transfer before finish */
ControlState = STALLED;
}
/* Unexpect state, STALL the endpoint */
else {
ControlState = STALLED;
}
pInformation->ControlState = ControlState;
return Post0_Process();
} /* Out0_Process */
/*******************************************************************************
* Function Name : Post0_Process
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
u8 Post0_Process(void)
{
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
if (pInformation->ControlState == STALLED) {
vSetEPRxStatus(EP_RX_STALL);
vSetEPTxStatus(EP_TX_STALL);
}
return (pInformation->ControlState == PAUSE);
}
/*******************************************************************************
* Function Name : SetDeviceAddress
* Description : set the device and all the used Endpoints addresses
* Input : Val : device adress
* Output :
* Return :
*******************************************************************************/
void SetDeviceAddress(u8 Val)
{
u32 i;
u32 nEP = Device_Table.Total_Endpoint;
/* set address in every used endpoint */
for(i=0;i<nEP;i++)
{
_SetEPAddress((u8)i, (u8)i);
} /* for */
_SetDADDR(Val|DADDR_EF); /* set device address and enable function */
}
/*******************************************************************************
* Function Name : NOP_Process
* Description : no operation function.
* Input :
* Output :
* Return :
*******************************************************************************/
void NOP_Process(void)
{
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -