📄 usb_otg_dev_setup.c
字号:
ep0State=EP0_STATE_INIT;
break;
case SET_FEATURE:
switch (descSetup.bmRequestType)
{
case DEVICE_RECIPIENT:
if (descSetup.bValueL == 1)
Rwuen = TRUE;
break;
case ENDPOINT_RECIPIENT:
if (descSetup.bValueL == 0)
{
if((descSetup.bIndexL & 0x7f) == 0x00){
StatusGet.Endpoint0= 1;
}
if((descSetup.bIndexL & 0x8f) == 0x81){
StatusGet.Endpoint1= 1;
}
if((descSetup.bIndexL & 0x8f) == 0x03){
StatusGet.Endpoint3= 1;
}
}
break;
default:
break;
}
ep0State=EP0_STATE_INIT;
break;
case SET_INTERFACE:
// not necessary because processed in OTG h/w
/*
InterfaceGet.AlternateSetting= descSetup.bValueL;
ep0State=EP0_STATE_INIT;
*/
break;
case SYNCH_FRAME:
//....
ep0State=EP0_STATE_INIT;
break;
//////////////////////////////////////////////////////////////
default:
ep0State=EP0_STATE_INIT;
break;
}
apOTG_TLI_DEV_S->OutEP[OTG_DEV_CTRL_ENDP].control |= OTG_DEV_RX_FIFOREADY;
}
else
{
apOTG_TLI_DEV_S->OutEP[OTG_DEV_CTRL_ENDP].control |= OTG_DEV_RX_FIFOREADY;
return;
}
}
void UsbOtg_Ep0TxHandler(void)
{
uint32 txStatus;
//* Read status
txStatus = apOTG_TLI_DEV_S->InEP[0].status;
if(txStatus & OTG_DEV_TX_GOOD_STATUS)
{
apOTG_TLI_DEV_S->InEP[OTG_DEV_CTRL_ENDP].control |= OTG_DEV_TX_FLUSHFIFO;
}
if((txStatus & OTG_DEV_TX_NAK_INTR) || (txStatus & OTG_DEV_TX_STATUS_INTR))
{
switch(ep0State)
{
case EP0_STATE_INIT:
apOTG_TLI_DEV_S->InEP[0].txCount = 0;
break;
//=== GET_DESCRIPTOR:DEVICE ===
case EP0_STATE_GD_DEV_0:
/* NOTE!!! txCount must be written before data are written to TxFifo */
apOTG_TLI_DEV_S->InEP[0].txCount = 8;
WrPktEp0((unsigned char *)&descDev+0,8); //OTG_CONTROL_PKT_SIZE
ep0State=EP0_STATE_GD_DEV_1;
break;
case EP0_STATE_GD_DEV_1:
apOTG_TLI_DEV_S->InEP[0].txCount = 8;
WrPktEp0((unsigned char *)&descDev+0x8,8);
ep0State=EP0_STATE_GD_DEV_2;
break;
case EP0_STATE_GD_DEV_2:
apOTG_TLI_DEV_S->InEP[0].txCount = 2;
WrPktEp0((unsigned char *)&descDev+0x10,2); //8+8+2=0x12
ep0State=EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:CONFIGURATION+INTERFACE+ENDPOINT0+ENDPOINT1 ===
//Windows98 gets these 4 descriptors all together by issuing only a request.
//Windows2000 gets each descriptor seperately.
case EP0_STATE_GD_CFG_0:
apOTG_TLI_DEV_S->InEP[0].txCount = 8;
WrPktEp0((unsigned char *)&descConf+0,8); //OTG_CONTROL_PKT_SIZE
ep0State=EP0_STATE_GD_CFG_1;
break;
case EP0_STATE_GD_CFG_1:
apOTG_TLI_DEV_S->InEP[0].txCount = 8;
WrPktEp0((unsigned char *)&descConf+8,1);
WrPktEp0((unsigned char *)&descIf+0,7);
ep0State=EP0_STATE_GD_CFG_2;
break;
case EP0_STATE_GD_CFG_2:
apOTG_TLI_DEV_S->InEP[0].txCount = 8;
WrPktEp0((unsigned char *)&descIf+7,2);
WrPktEp0((unsigned char *)&descEndpt0+0,6);
ep0State=EP0_STATE_GD_CFG_3;
break;
case EP0_STATE_GD_CFG_3:
apOTG_TLI_DEV_S->InEP[0].txCount = 8;
WrPktEp0((unsigned char *)&descEndpt0+6,1);
WrPktEp0((unsigned char *)&descEndpt1+0,7);
ep0State=EP0_STATE_GD_CFG_4;
break;
case EP0_STATE_GD_CFG_4:
//zero length data packit
ep0State=EP0_STATE_INIT;
apOTG_TLI_DEV_S->InEP[0].txCount = 0;
break;
//=== GET_DESCRIPTOR:CONFIGURATION ONLY===
case EP0_STATE_GD_CFG_ONLY_0:
apOTG_TLI_DEV_S->InEP[0].txCount = 8;
WrPktEp0((unsigned char *)&descConf+0,8); //OTG_CONTROL_PKT_SIZE
ep0State=EP0_STATE_GD_CFG_ONLY_1;
break;
case EP0_STATE_GD_CFG_ONLY_1:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&descConf+8,1);
ep0State=EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:INTERFACE ONLY===
case EP0_STATE_GD_IF_ONLY_0:
apOTG_TLI_DEV_S->InEP[0].txCount = 8;
WrPktEp0((unsigned char *)&descIf+0,8);
ep0State=EP0_STATE_GD_IF_ONLY_1;
break;
case EP0_STATE_GD_IF_ONLY_1:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&descIf+8,1);
ep0State=EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:ENDPOINT 0 ONLY===
case EP0_STATE_GD_EP0_ONLY_0:
apOTG_TLI_DEV_S->InEP[0].txCount = 7;
WrPktEp0((unsigned char *)&descEndpt0+0,7);
ep0State=EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:ENDPOINT 1 ONLY===
case EP0_STATE_GD_EP1_ONLY_0:
apOTG_TLI_DEV_S->InEP[0].txCount = 7;
WrPktEp0((unsigned char *)&descEndpt1+0,7);
ep0State=EP0_STATE_INIT;
break;
////////////////////////////////////////////
case EP0_INTERFACE_GET:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&InterfaceGet+0,1);
ep0State=EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:STRING ===
case EP0_STATE_GD_STR_I0:
apOTG_TLI_DEV_S->InEP[0].txCount = 4;
WrPktEp0((unsigned char *)descStr0, 4 );
ep0State=EP0_STATE_INIT;
ep0SubState=0;
break;
case EP0_STATE_GD_STR_I1:
if( (ep0SubState*OTG_CONTROL_PKT_SIZE+OTG_CONTROL_PKT_SIZE)<sizeof(descStr1) )
{
apOTG_TLI_DEV_S->InEP[0].txCount = OTG_CONTROL_PKT_SIZE;
WrPktEp0((unsigned char *)descStr1+(ep0SubState*OTG_CONTROL_PKT_SIZE),OTG_CONTROL_PKT_SIZE);
ep0State=EP0_STATE_GD_STR_I1;
ep0SubState++;
}
else
{
apOTG_TLI_DEV_S->InEP[0].txCount = sizeof(descStr1)-(ep0SubState*OTG_CONTROL_PKT_SIZE);
WrPktEp0((unsigned char *)descStr1+(ep0SubState*OTG_CONTROL_PKT_SIZE),
sizeof(descStr1)-(ep0SubState*OTG_CONTROL_PKT_SIZE));
apOTG_TLI_DEV_S->InEP[0].txCount = sizeof(descStr1)-(ep0SubState*OTG_CONTROL_PKT_SIZE);
ep0State=EP0_STATE_INIT;
ep0SubState=0;
}
break;
case EP0_STATE_GD_STR_I2:
if( (ep0SubState*OTG_CONTROL_PKT_SIZE+OTG_CONTROL_PKT_SIZE)<sizeof(descStr2) )
{
apOTG_TLI_DEV_S->InEP[0].txCount = OTG_CONTROL_PKT_SIZE;
WrPktEp0((unsigned char *)descStr2+(ep0SubState*OTG_CONTROL_PKT_SIZE),OTG_CONTROL_PKT_SIZE);
ep0State=EP0_STATE_GD_STR_I2;
ep0SubState++;
}
else
{
apOTG_TLI_DEV_S->InEP[0].txCount = sizeof(descStr2)-(ep0SubState*OTG_CONTROL_PKT_SIZE);
WrPktEp0((unsigned char *)descStr2+(ep0SubState*OTG_CONTROL_PKT_SIZE),
sizeof(descStr2)-(ep0SubState*OTG_CONTROL_PKT_SIZE));
ep0State=EP0_STATE_INIT;
ep0SubState=0;
}
break;
case EP0_CONFIG_SET:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&ConfigSet+0,1);
ep0State=EP0_STATE_INIT;
break;
case EP0_GET_STATUS0:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&StatusGet+0,1);
ep0State=EP0_STATE_INIT;
break;
case EP0_GET_STATUS1:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&StatusGet+1,1);
ep0State=EP0_STATE_INIT;
break;
case EP0_GET_STATUS2:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&StatusGet+2,1);
ep0State=EP0_STATE_INIT;
break;
case EP0_GET_STATUS3:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&StatusGet+3,1);
ep0State=EP0_STATE_INIT;
break;
case EP0_GET_STATUS4:
apOTG_TLI_DEV_S->InEP[0].txCount = 1;
WrPktEp0((unsigned char *)&StatusGet+4,1);
ep0State=EP0_STATE_INIT;
break;
default:
apOTG_TLI_DEV_S->InEP[0].txCount = 0;
break;
}
apOTG_TLI_DEV_S->InEP[OTG_DEV_CTRL_ENDP].control |= OTG_DEV_TX_FIFOREADY;
}
//* Clear interrupt
apOTG_TLI_DEV_S->InEP[OTG_DEV_CTRL_ENDP].status = ~0;
//* Initialize TxFifo0's pointer
ptrTxFifo0 = OTG_DEV_TX_FIFO(0);
}
void UsbOtg_Ep0RxHandler(void)
{
uint32 rxCount = 0;
//* Read rx transfer size
rxCount = (apOTG_TLI_DEV_G->rxStatus >> OTG_DEV_RX_COUNT_SHIFT) & OTG_DEV_RX_COUNT_MASK;
//* If zero-length data
if (rxCount != 0)
{
//* temporal code
//* we don't expect non-zero control write data
apOTG_TLI_DEV_S->OutEP[0].control |= OTG_DEV_RX_FLUSHFIFO;
}
apOTG_TLI_DEV_S->OutEP[OTG_DEV_CTRL_ENDP].control |= OTG_DEV_RX_FIFOREADY;
//* Clear interrupt
//apOTG_TLI_DEV_G->rxStatus |= 0x1f;
}
//->
//khs.050117
// modified for debug
#ifdef KHS_USBD_DEBUG
void PrintEp0Pkt(unsigned char *pt)
{
int i;
Usbd_Ep0_Data[count_Ep0_Data].state=ep0State;
Usbd_Ep0_Data[count_Ep0_Data].direction=0; //host->device
for(i=0;i<8;i++)
Usbd_Ep0_Data[count_Ep0_Data].data[i]=pt[i];
Usbd_Ep0_Data[count_Ep0_Data].cnt=8;
count_Ep0_Data++;
}
#endif
//<-
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -