?? kitlusbser.c
字號:
OTGDEV_WrPktEp0((UINT8 *)aDescStr2+(oOtgDev.m_uEp0SubState*oOtgDev.m_uControlEPMaxPktSize), oOtgDev.m_uControlEPMaxPktSize);
oOtgDev.m_uEp0State = EP0_STATE_GD_STR_I2;
oOtgDev.m_uEp0SubState++;
}
else
{
if (oOtgDev.m_eSpeed == USB_HIGH)
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(0<<0)); //ep0 enable, clear nak, next ep0, 64byte
else
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(3<<0)); //ep0 enable, clear nak, next ep0, 8byte
DBGUSB("[E]");
OTGDEV_WrPktEp0((UINT8 *)aDescStr2+(oOtgDev.m_uEp0SubState*oOtgDev.m_uControlEPMaxPktSize), sizeof(aDescStr2)-(oOtgDev.m_uEp0SubState*oOtgDev.m_uControlEPMaxPktSize));
oOtgDev.m_uEp0State = EP0_STATE_INIT;
oOtgDev.m_uEp0SubState = 0;
}
break;
case EP0_STATE_GD_DEV_QUALIFIER:
OTGDEV_SetInEpXferSize(EP_TYPE_CONTROL, 1, 10);
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(0<<0)); //ep0 enable, clear nak, next ep0, 8byte
OTGDEV_WrPktEp0((UINT8 *)aDeviceQualifierDescriptor+0, 10);
oOtgDev.m_uEp0State = EP0_STATE_INIT;
break;
case EP0_STATE_INTERFACE_GET:
OTGDEV_SetInEpXferSize(EP_TYPE_CONTROL, 1, 1);
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(3<<0)); //ep0 enable, clear nak, next ep0, 8byte
OTGDEV_WrPktEp0((UINT8 *)&oInterfaceGet+0, 1);
oOtgDev.m_uEp0State = EP0_STATE_INIT;
break;
case EP0_STATE_GET_STATUS0:
OTGDEV_SetInEpXferSize(EP_TYPE_CONTROL, 1, 1);
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(3<<0)); //ep0 enable, clear nak, next ep0, 8byte
OTGDEV_WrPktEp0((UINT8 *)&oStatusGet+0, 1);
oOtgDev.m_uEp0State = EP0_STATE_INIT;
break;
case EP0_STATE_GET_STATUS1:
OTGDEV_SetInEpXferSize(EP_TYPE_CONTROL, 1, 1);
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(3<<0)); //ep0 enable, clear nak, next ep0, 8byte
OTGDEV_WrPktEp0((UINT8 *)&oStatusGet+1, 1);
oOtgDev.m_uEp0State = EP0_STATE_INIT;
break;
case EP0_STATE_GET_STATUS2:
OTGDEV_SetInEpXferSize(EP_TYPE_CONTROL, 1, 1);
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(3<<0)); //ep0 enable, clear nak, next ep0, 8byte
OTGDEV_WrPktEp0((UINT8 *)&oStatusGet+2, 1);
oOtgDev.m_uEp0State = EP0_STATE_INIT;
break;
case EP0_STATE_GET_STATUS3:
OTGDEV_SetInEpXferSize(EP_TYPE_CONTROL, 1, 1);
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(3<<0)); //ep0 enable, clear nak, next ep0, 8byte
OTGDEV_WrPktEp0((UINT8 *)&oStatusGet+3, 1);
oOtgDev.m_uEp0State = EP0_STATE_INIT;
break;
case EP0_STATE_GET_STATUS4:
OTGDEV_SetInEpXferSize(EP_TYPE_CONTROL, 1, 1);
Outp32(DIEPCTL0, (1u<<31)|(1<<26)|(BULK_IN_EP<<11)|(3<<0)); //ep0 enable, clear nak, next ep0, 8byte
OTGDEV_WrPktEp0((UINT8 *)&oStatusGet+4, 1);
oOtgDev.m_uEp0State = EP0_STATE_INIT;
break;
default:
break;
}
}
//////////
// Function Name : OTGDEV_HandleEvent_BulkIn
// Function Desctiption : This function handles bulk in transfer in CPU mode.
// Input : NONE
// Output : NONE
// Version :
UINT16 OTGDEV_HandleEvent_BulkIn(UINT8 *pch, UINT32 fifoCntByte)
{
UINT32 ucLen;
volatile UINT32 uGIntStatus,uDaint;
if (!pch )
{
fifoCntByte = 0;
return fifoCntByte;
}
// Don't try to send more than EP1 can handle.
if( fifoCntByte > oOtgDev.m_uBulkInEPMaxPktSize )
{
ucLen = oOtgDev.m_uBulkInEPMaxPktSize;
}
else
{
// If we end exactly on a packet boundary, the host doesn't
// realize there is no more data. So if we exactly fill the final
// packet, truncate it so we can send a short packet next frame
// indicating end of the transmission
if( fifoCntByte == oOtgDev.m_uBulkInEPMaxPktSize )
{
ucLen = oOtgDev.m_uBulkInEPMaxPktSize - 4;
}
else
{
ucLen = fifoCntByte;
}
}
while(1)
{
Inp32(GINTSTS, uGIntStatus); // System status read
if (uGIntStatus & INT_IN_EP)
{
Inp32(DAINT, uDaint);
if (uDaint & (1<<BULK_IN_EP))
{
break;
}
}
}
OTGDEV_SetInEpXferSize(EP_TYPE_BULK, 1, ucLen);
Outp32(bulkIn_DIEPCTL, 1<<31|1<<26|2<<18|1<<15|oOtgDev.m_uBulkInEPMaxPktSize<<0); //ep3 enable, clear nak, bulk, usb active, next ep3, max pkt 64
OTGDEV_WrPktBulkInEp(pch, ucLen);
return ucLen;
}
//////////
// Function Name : OTGDEV_HandleEvent_BulkOut
// Function Desctiption : This function handles bulk out transfer.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_HandleEvent_BulkOut(UINT8 *pch, UINT32 fifoCntByte)
{
if (oOtgDev.m_eOpMode == USB_CPU)
{
OTGDEV_RdPktBulkOutEp((UINT8 *)pch, fifoCntByte);
OTGDEV_SetOutEpXferSize(EP_TYPE_BULK, 1, oOtgDev.m_uBulkOutEPMaxPktSize);
Outp32(bulkOut_DOEPCTL, 1<<31|1<<26|2<<18|1<<15|oOtgDev.m_uBulkOutEPMaxPktSize<<0); //ep3 enable, clear nak, bulk, usb active, next ep3, max pkt 64
}
}
//#pragma optimize ("",off)
//////////
// Function Name : OTGDEV_InitPhyCon
// Function Desctiption : This function initializes OTG Phy.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_InitPhyCon(void)
{
Outp32(PHYPWR, 0x0);
Outp32(PHYCTRL, 0x20);
Outp32(RSTCON, 0x1);
delayLoop(10);
Outp32(RSTCON, 0x0);
delayLoop(10);
}
//#pragma optimize ("",on)
//////////
// Function Name : OTGDEV_SoftResetCore
// Function Desctiption : This function soft-resets OTG Core and then unresets again.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_SoftResetCore(void)
{
volatile UINT32 uTemp;
Outp32(GRSTCTL, CORE_SOFT_RESET);
do
{
Inp32(GRSTCTL, uTemp);
}while(!(uTemp & AHB_MASTER_IDLE));
}
//////////
// Function Name : OTGDEV_InitCore
// Function Desctiption : This function initializes OTG Link Core.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_InitCore(void)
{
Outp32(GAHBCFG, PTXFE_HALF|NPTXFE_HALF|MODE_SLAVE|BURST_SINGLE|GBL_INT_UNMASK);
Outp32(GUSBCFG, 0<<15 // PHY Low Power Clock sel
|1<<14 // Non-Periodic TxFIFO Rewind Enable
|0x5<<10 // Turnaround time
|0<<9|0<<8 // [0:HNP disable, 1:HNP enable][ 0:SRP disable, 1:SRP enable] H1= 1,1
|0<<7 // Ulpi DDR sel
|0<<6 // 0: high speed utmi+, 1: full speed serial
|0<<4 // 0: utmi+, 1:ulpi
|1<<3 // phy i/f 0:8bit, 1:16bit
|0x7<<0 // HS/FS Timeout*
);
}
//////////
// Function Name : OTGDEV_CheckCurrentMode
// Function Desctiption : This function checks the current mode.
// Input : pucMode, current mode(device or host)
// Output : NONE
// Version :
void OTGDEV_CheckCurrentMode(UINT8 *pucMode)
{
volatile UINT32 uTemp;
Inp32(GINTSTS, uTemp);
*pucMode = uTemp & 0x1;
}
//////////
// Function Name : OTGDEV_SetSoftDisconnect
// Function Desctiption : This function puts the OTG device core in the disconnected state.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_SetSoftDisconnect(void)
{
volatile UINT32 uTemp;
Inp32(DCTL, uTemp);
uTemp |= SOFT_DISCONNECT;
Outp32(DCTL, uTemp);
}
//////////
// Function Name : OTGDEV_ClearSoftDisconnect
// Function Desctiption : This function makes the OTG device core to exit from the disconnected state.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_ClearSoftDisconnect(void)
{
volatile UINT32 uTemp;
Inp32(DCTL, uTemp);
uTemp = uTemp & ~SOFT_DISCONNECT;
Outp32(DCTL, uTemp);
}
//////////
// Function Name : OTGDEV_InitDevice
// Function Desctiption : This function configures OTG Core to initial settings of device mode.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_InitDevice(void)
{
Outp32(DCFG, 1<<18|oOtgDev.m_eSpeed<<0); // [][1: full speed(30Mhz) 0:high speed]
Outp32(GINTMSK, INT_RESUME|INT_OUT_EP|INT_IN_EP|INT_ENUMDONE|INT_RESET
|INT_SUSPEND|INT_RX_FIFO_NOT_EMPTY); //gint unmask
}
//////////
// Function Name : OTGDEV_SetAllOutEpNak
// Function Desctiption : This function sets NAK bit of all EPs.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_SetAllOutEpNak(void)
{
UINT8 i;
volatile UINT32 uTemp;
for(i=0;i<16;i++)
{
Inp32(DOEPCTL0+0x20*i, uTemp);
uTemp |= DEPCTL_SNAK;
Outp32(DOEPCTL0+0x20*i, uTemp);
}
}
//////////
// Function Name : OTGDEV_ClearAllOutEpNak
// Function Desctiption : This function clears NAK bit of all EPs.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_ClearAllOutEpNak(void)
{
UINT8 i;
volatile UINT32 uTemp;
for(i=0;i<16;i++)
{
//uTemp = Inp32(DOEPCTL0+0x20*i);
Inp32(DOEPCTL0+0x20*i, uTemp);
uTemp |= DEPCTL_CNAK;
Outp32(DOEPCTL0+0x20*i, uTemp);
}
}
//////////
// Function Name : OTGDEV_SetMaxPktSizes
// Function Desctiption : This function sets the max packet sizes of USB transfer types according to the speed.
// Input : eSpeed, usb speed(high or full)
// Output : NONE
// Version :
void OTGDEV_SetMaxPktSizes(USB_SPEED eSpeed)
{
if (eSpeed == USB_HIGH)
{
oOtgDev.m_eSpeed = USB_HIGH;
oOtgDev.m_uControlEPMaxPktSize = HIGH_SPEED_CONTROL_PKT_SIZE;
oOtgDev.m_uBulkInEPMaxPktSize = HIGH_SPEED_BULK_PKT_SIZE;
oOtgDev.m_uBulkOutEPMaxPktSize = HIGH_SPEED_BULK_PKT_SIZE;
}
else
{
oOtgDev.m_eSpeed = USB_FULL;
oOtgDev.m_uControlEPMaxPktSize = FULL_SPEED_CONTROL_PKT_SIZE;
oOtgDev.m_uBulkInEPMaxPktSize = FULL_SPEED_BULK_PKT_SIZE;
oOtgDev.m_uBulkOutEPMaxPktSize = FULL_SPEED_BULK_PKT_SIZE;
}
}
//////////
// Function Name : OTGDEV_SetEndpoint
// Function Desctiption : This function sets the endpoint-specific CSRs.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_SetEndpoint(void)
{
// Unmask DAINT source
Outp32(DIEPINT0, 0xff);
Outp32(DOEPINT0, 0xff);
Outp32(bulkIn_DIEPINT, 0xff);
Outp32(bulkOut_DOEPINT, 0xff);
// Init For Ep0
if(oOtgDev.m_eSpeed == USB_HIGH)
{
Outp32(DIEPCTL0, (1u<<31)|((1<<26)|(BULK_IN_EP<<11)|(0<<0))); //MPS:64bytes
}
else
{
Outp32(DIEPCTL0, (1u<<31)|((1<<26)|(BULK_IN_EP<<11)|(3<<0))); //MPS:8bytes
}
OTGDEV_SetInEpXferSize(EP_TYPE_CONTROL, 1, oOtgDev.m_uControlEPMaxPktSize);
OTGDEV_SetOutEpXferSize(EP_TYPE_CONTROL, 1, oOtgDev.m_uControlEPMaxPktSize);
Outp32(DOEPCTL0, (0u<<31)|(1<<26)); //ep0 enable, clear nak
}
//////////
// Function Name : OTGDEV_SetDescriptorTable
// Function Desctiption : This function sets the standard descriptors.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_SetDescriptorTable(void)
{
// Standard device descriptor
oOtgDev.m_oDesc.oDescDevice.bLength=DEVICE_DESC_SIZE; //0x12
oOtgDev.m_oDesc.oDescDevice.bDescriptorType=DEVICE_DESCRIPTOR;
oOtgDev.m_oDesc.oDescDevice.bDeviceClass=0xFF; // 0x0
oOtgDev.m_oDesc.oDescDevice.bDeviceSubClass=0xFF;
oOtgDev.m_oDesc.oDescDevice.bDeviceProtocol=0xFF;
oOtgDev.m_oDesc.oDescDevice.bMaxPacketSize0=oOtgDev.m_uControlEPMaxPktSize;
oOtgDev.m_oDesc.oDescDevice.idVendorL=0x5E; //0x45;
oOtgDev.m_oDesc.oDescDevice.idVendorH=0x04; //0x53;
oOtgDev.m_oDesc.oDescDevice.idProductL=0xCE; //0x34;
oOtgDev.m_oDesc.oDescDevice.idProductH=0x00; //0x12;
oOtgDev.m_oDesc.oDescDevice.bcdDeviceL=0x00;
oOtgDev.m_oDesc.oDescDevice.bcdDeviceH=0x00;
oOtgDev.m_oDesc.oDescDevice.iManufacturer=0x0; // index of string descriptor
oOtgDev.m_oDesc.oDescDevice.iProduct=0x0; // index of string descriptor
oOtgDev.m_oDesc.oDescDevice.iSerialNumber=0x0;
oOtgDev.m_oDesc.oDescDevice.bNumConfigurations=0x1;
if (oOtgDev.m_eSpeed == USB_FULL) {
oOtgDev.m_oDesc.oDescDevice.bcdUSBL=0x10;
oOtgDev.m_oDesc.oDescDevice.bcdUSBH=0x01; // Ver 1.10
}
else {
oOtgDev.m_oDesc.oDescDevice.bcdUSBL=0x00;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -