📄 usb.c.svn-base
字号:
case EP0_STATE_GD_IF_ONLY_0:
if (g_eSpeed == 1)
{
Outp32(BYTE_WRITE_CNT_REG, 9); // INTERFACE_DESC_SIZE
WrPktEp0((UINT8 *)&oDesc.oDescInterface+0, 9);
g_uEp0State = EP0_STATE_INIT;
}
else
{
Outp32(BYTE_WRITE_CNT_REG, 8); // INTERFACE_DESC_SIZE
WrPktEp0((UINT8 *)&oDesc.oDescInterface+0, 8);
g_uEp0State = EP0_STATE_GD_IF_ONLY_1;
}
break;
case EP0_STATE_GD_IF_ONLY_1:
Outp32(BYTE_WRITE_CNT_REG, 1);
WrPktEp0((UINT8 *)&oDesc.oDescInterface+8, 1);
g_uEp0State = EP0_STATE_INIT;
break;
// === GET_DESCRIPTOR:ENDPOINT 1 ONLY===
case EP0_STATE_GD_EP0_ONLY_0:
Outp32(BYTE_WRITE_CNT_REG, ENDPOINT_DESC_SIZE);
Inp32(SYS_STATUS_REG, usSysStatus);
WrPktEp0((UINT8 *)&oDesc.oDescEndpt1+0, ENDPOINT_DESC_SIZE);
g_uEp0State = EP0_STATE_INIT;
break;
// === GET_DESCRIPTOR:ENDPOINT 2 ONLY===
case EP0_STATE_GD_EP1_ONLY_0:
Outp32(BYTE_WRITE_CNT_REG, ENDPOINT_DESC_SIZE);
Inp32(SYS_STATUS_REG, usSysStatus);
WrPktEp0((UINT8 *)&oDesc.oDescEndpt3+0, ENDPOINT_DESC_SIZE);
g_uEp0State = EP0_STATE_INIT;
break;
// === GET_DESCRIPTOR:STRING ===
case EP0_STATE_GD_STR_I0:
Outp32(BYTE_WRITE_CNT_REG, 4);
//EdbgOutputDebugString("[GDS0_0]");
WrPktEp0((UINT8 *)aDescStr0, 4);
g_uEp0State = EP0_STATE_INIT;
break;
case EP0_STATE_GD_STR_I1:
//EdbgOutputDebugString("[GDS1_%d]", g_uEp0SubState);
if ((g_uEp0SubState*g_uEp0MaxPktSize+g_uEp0MaxPktSize)<sizeof(aDescStr1))
{
Outp32(BYTE_WRITE_CNT_REG, g_uEp0MaxPktSize);
WrPktEp0((UINT8 *)aDescStr1+(g_uEp0SubState*g_uEp0MaxPktSize), g_uEp0MaxPktSize);
g_uEp0State = EP0_STATE_GD_STR_I1;
g_uEp0SubState++;
}
else
{
Outp32(BYTE_WRITE_CNT_REG, sizeof(aDescStr1)-(g_uEp0SubState*g_uEp0MaxPktSize));
WrPktEp0((UINT8 *)aDescStr1+(g_uEp0SubState*g_uEp0MaxPktSize), sizeof(aDescStr1)-(g_uEp0SubState*g_uEp0MaxPktSize));
g_uEp0State = EP0_STATE_INIT;
g_uEp0SubState = 0;
}
break;
case EP0_STATE_GD_STR_I2:
//EdbgOutputDebugString("[GDS2_%d]", g_uEp0SubState);
if ((g_uEp0SubState*g_uEp0MaxPktSize+g_uEp0MaxPktSize)<sizeof(aDescStr2))
{
Outp32(BYTE_WRITE_CNT_REG, g_uEp0MaxPktSize);
WrPktEp0((UINT8 *)aDescStr2+(g_uEp0SubState*g_uEp0MaxPktSize), g_uEp0MaxPktSize);
g_uEp0State = EP0_STATE_GD_STR_I2;
g_uEp0SubState++;
}
else
{
//EdbgOutputDebugString("[E]");
Outp32(BYTE_WRITE_CNT_REG, sizeof(aDescStr2)-(g_uEp0SubState*g_uEp0MaxPktSize));
WrPktEp0((UINT8 *)aDescStr2+(g_uEp0SubState*g_uEp0MaxPktSize), sizeof(aDescStr2)-(g_uEp0SubState*g_uEp0MaxPktSize));
g_uEp0State = EP0_STATE_INIT;
g_uEp0SubState = 0;
}
break;
case EP0_STATE_GD_DEV_QUALIFIER:
Outp32(BYTE_WRITE_CNT_REG, 10);
WrPktEp0((UINT8 *)aDeviceQualifierDescriptor+0, 10);
g_uEp0State = EP0_STATE_INIT;
break;
case EP0_INTERFACE_GET:
Outp32(BYTE_WRITE_CNT_REG, 1);
WrPktEp0((UINT8 *)&oInterfaceGet+0, 1);
g_uEp0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS0:
Outp32(BYTE_WRITE_CNT_REG, 1);
WrPktEp0((UINT8 *)&oStatusGet+0, 1);
g_uEp0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS1:
Outp32(BYTE_WRITE_CNT_REG, 1);
WrPktEp0((UINT8 *)&oStatusGet+1, 1);
g_uEp0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS2:
Outp32(BYTE_WRITE_CNT_REG, 1);
WrPktEp0((UINT8 *)&oStatusGet+2, 1);
g_uEp0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS3:
Outp32(BYTE_WRITE_CNT_REG, 1);
WrPktEp0((UINT8 *)&oStatusGet+3, 1);
g_uEp0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS4:
Outp32(BYTE_WRITE_CNT_REG, 1);
WrPktEp0((UINT8 *)&oStatusGet+4, 1);
g_uEp0State = EP0_STATE_INIT;
break;
default:
break;
}
}
void HandleEvent_EP0(void)
{
UINT32 DeviceRequestLength;
UINT16 ep0csr;
UINT16 ReadCnt, i;
UINT16 ReadBuf[64]={0x0000, };
UINT8 setaddress;
UINT32 uRemoteWakeUp=0;
UINT16 usConfig=0;
Outp32(INDEX_REG, EP0);
Inp32(EP0_STATUS_REG, ep0csr);
//EdbgOutputDebugString(" Endpoint0 CSR Register = %x \n", ep0csr);
// EP0 CSR register status check
if (ep0csr & EP0_SENT_STALL) // SENT STALL : protocol stall.
{
//EdbgOutputDebugString(" Sent Stall \n");
Outp32(EP0_STATUS_REG, EP0_SENT_STALL);
if (ep0csr & EP0_RX_SUCCESS)
Outp32(EP0_STATUS_REG, EP0_RX_SUCCESS);
g_uEp0State = EP0_STATE_INIT;
return;
}
if (ep0csr & EP0_TX_SUCCESS)
{
//EdbgOutputDebugString(" EP0_TX_SUCCESS \n");
Outp32(EP0_STATUS_REG, EP0_TX_SUCCESS);
}
//EdbgOutputDebugString(" g_uEp0State = %x \n", g_uEp0State);
// if ((ep0csr & EP0_RX_SUCCESS) & (g_uEp0State == EP0_STATE_INIT))
if (g_uEp0State == EP0_STATE_INIT)
{
Inp32(BYTE_READ_CNT_REG, ReadCnt);
for(i=0;i<4;i++) Inp32(EP0_FIFO, ReadBuf[i]);
Outp32(EP0_STATUS_REG, EP0_RX_SUCCESS);
g_oDeviceRequest.bmRequestType=(UINT8)ReadBuf[0];
g_oDeviceRequest.bRequest=ReadBuf[0]>>8;
g_oDeviceRequest.wValue_L=(UINT8)ReadBuf[1];
g_oDeviceRequest.wValue_H=ReadBuf[1]>>8;
g_oDeviceRequest.wIndex_L=(UINT8)ReadBuf[2];
g_oDeviceRequest.wIndex_H=ReadBuf[2]>>8;
g_oDeviceRequest.wLength_L=(UINT8)ReadBuf[3];
g_oDeviceRequest.wLength_H=ReadBuf[3]>>8;
PrintEp0Pkt((UINT8 *)&g_oDeviceRequest, 8);
switch (g_oDeviceRequest.bRequest)
{
case STANDARD_SET_ADDRESS:
setaddress = (g_oDeviceRequest.wValue_L); // Set Address Update bit
//EdbgOutputDebugString("Func_ADDR_Setaddr : %d \n", setaddress);
g_uEp0State = EP0_STATE_INIT;
break;
case STANDARD_SET_DESCRIPTOR:
//EdbgOutputDebugString("\n MCU >> Set Descriptor \n");
break;
case STANDARD_SET_CONFIGURATION:
// EdbgOutputDebugString("\n MCU >> Set Configuration \n");
usConfig = g_oDeviceRequest.wValue_L; // Configuration value in configuration descriptor
// m_uEnumerationDone = 1;
break;
case STANDARD_GET_CONFIGURATION:
// Uart_Printf("\n MCU >> Get Configruation \n");
Outp32(BYTE_WRITE_CNT_REG, 1);
Outp32(EP0_FIFO, usConfig);
break;
case STANDARD_GET_DESCRIPTOR:
switch (g_oDeviceRequest.wValue_H)
{
case DEVICE_DESCRIPTOR:
//EdbgOutputDebugString("\n MCU >> Get Device Descriptor \n");
g_uEp0State = EP0_STATE_GD_DEV_0;
break;
case CONFIGURATION_DESCRIPTOR:
//EdbgOutputDebugString("\n MCU >> Get Configuration Descriptor \n");
DeviceRequestLength = (UINT32)((g_oDeviceRequest.wLength_H << 8) |
g_oDeviceRequest.wLength_L);
if (DeviceRequestLength > CONFIG_DESC_SIZE){
// === GET_DESCRIPTOR:CONFIGURATION+INTERFACE+ENDPOINT0+ENDPOINT1 ===
// Windows98 gets these 4 descriptors all together by issuing only a request.
// Windows2000 gets each descriptor seperately.
// m_uEpZeroTransferLength = CONFIG_DESC_TOTAL_SIZE;
// m_uEpZeroTransferdata = 0;
g_uEp0State = EP0_STATE_GD_CFG_0;
}
else
g_uEp0State = EP0_STATE_GD_CFG_ONLY_0; // for win2k
break;
case STRING_DESCRIPTOR :
switch(g_oDeviceRequest.wValue_L)
{
case 0:
g_uEp0State = EP0_STATE_GD_STR_I0;
break;
case 1:
g_uEp0State = EP0_STATE_GD_STR_I1;
break;
case 2:
g_uEp0State = EP0_STATE_GD_STR_I2;
break;
default:
break;
}
break;
case ENDPOINT_DESCRIPTOR:
switch(g_oDeviceRequest.wValue_L&0xf)
{
case 0:
g_uEp0State=EP0_STATE_GD_EP0_ONLY_0;
break;
case 1:
g_uEp0State=EP0_STATE_GD_EP1_ONLY_0;
break;
default:
break;
}
break;
case DEVICE_QUALIFIER:
//EdbgOutputDebugString("\n MCU >> Get Device Qualifier Descriptor \n");
g_uEp0State = EP0_STATE_GD_DEV_QUALIFIER;
break;
}
break;
case STANDARD_CLEAR_FEATURE:
//EdbgOutputDebugString("\n MCU >> Clear Feature \n");
switch (g_oDeviceRequest.bmRequestType)
{
case DEVICE_RECIPIENT:
if (g_oDeviceRequest.wValue_L == 1)
uRemoteWakeUp = FALSE;
break;
case ENDPOINT_RECIPIENT:
if (g_oDeviceRequest.wValue_L == 0)
{
if ((g_oDeviceRequest.wIndex_L & 0x7f) == 0x00)
oStatusGet.Endpoint0= 0;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x01) // IN Endpoint 1
oStatusGet.Endpoint1= 0;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x03) // OUT Endpoint 3
oStatusGet.Endpoint3= 0;
}
break;
default:
break;
}
g_uEp0State = EP0_STATE_INIT;
break;
case STANDARD_SET_FEATURE:
//EdbgOutputDebugString("\n MCU >> Set Feature \n");
switch (g_oDeviceRequest.bmRequestType)
{
case DEVICE_RECIPIENT:
if (g_oDeviceRequest.wValue_L == 1)
uRemoteWakeUp = TRUE;
break;
case ENDPOINT_RECIPIENT:
if (g_oDeviceRequest.wValue_L == 0)
{
if ((g_oDeviceRequest.wIndex_L & 0x7f) == 0x00)
oStatusGet.Endpoint0= 1;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x01)
oStatusGet.Endpoint1= 1;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x03)
oStatusGet.Endpoint3= 1;
}
break;
default:
break;
}
g_uEp0State = EP0_STATE_INIT;
break;
case STANDARD_GET_STATUS:
switch(g_oDeviceRequest.bmRequestType)
{
case (0x80):
oStatusGet.Device=((UINT8)uRemoteWakeUp<<1)|0x1; // SelfPowered
g_uEp0State = EP0_GET_STATUS0;
break;
case (0x81):
oStatusGet.Interface=0;
g_uEp0State = EP0_GET_STATUS1;
break;
case (0x82):
if ((g_oDeviceRequest.wIndex_L & 0x7f) == 0x00)
g_uEp0State = EP0_GET_STATUS2;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x01)
g_uEp0State = EP0_GET_STATUS3;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x03)
g_uEp0State = EP0_GET_STATUS4;
break;
default:
break;
}
break;
case STANDARD_GET_INTERFACE:
g_uEp0State = EP0_INTERFACE_GET;
break;
case STANDARD_SET_INTERFACE:
oInterfaceGet.AlternateSetting= g_oDeviceRequest.wValue_L;
g_uEp0State = EP0_STATE_INIT;
break;
case STANDARD_SYNCH_FRAME:
g_uEp0State = EP0_STATE_INIT;
break;
default:
break;
}
}
TransferEp0();
}
void PrepareEp1Fifo(UINT32 BaseAddr)
{
// int i;
// UINT32 in_csr1;
UINT8* BulkInBuf = (UINT8*)BaseAddr;
if (g_uBulkInCount > g_uEp1MaxPktSize)
{
Outp32(INDEX_REG, EP1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -