UsbDbgPdd_Init (Compact 2013)
10/16/2014
Implement this function to initialize the hardware and fill the function table with device driver service-provider interface (DDSI) functions.
Syntax
extern "C" DWORD UsbDbgPdd_Init(
USBDBG_MDD_INTERFACE_INFO* pMddIfc,
USBDBG_PDD_INTERFACE_INFO* pPddIfc,
USBDBG_DEVICE_DESCRIPTOR* pDeviceDesc
)
Parameters
- pMddIfc
[in] Pointer to the model device driver (MDD) interface information structure.
- pPddIfc
[in] Pointer to the platform-dependent device driver (PDD) interface information structure.
- pDeviceDesc
[in] Pointer to the USB device descriptor.
Return Value
Implement this function so that it returns ERROR_SUCCESS if successful; otherwise, return the appropriate error code from the values defined in Winerror.h.
Remarks
You must implement this function in the PDD because the MDD calls it during initialization.
Example
The following example shows a typical implementation of the UsbDbgPdd_Init function.
Important
For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.
extern "C" DWORD UsbDbgPdd_Init(
USBDBG_MDD_INTERFACE_INFO* pMddIfc,
USBDBG_PDD_INTERFACE_INFO* pPddIfc,
USBDBG_DEVICE_DESCRIPTOR* pDeviceDesc
)
{
DWORD rc = (DWORD)E_FAIL;
USBFN_PDD *pPdd;
CSP_USB_REGS *pUSBDRegs;
PHYSICAL_ADDRESS pa;
DWORD qhHead;
USBDBGMSG(USBDBG_ZONE_FUNC, (L"usbdbgpdd: +UsbDbgPdd_Init\r\n"));
// PDD object pointer
pPdd = (USBFN_PDD *)&usbfn_pdd;
memset(pPdd, 0, sizeof(USBFN_PDD));
pPdd->devState = 0;
// Map the USB registers
pPdd->memBase = CSP_BASE_REG_PA_USBOTG;
pa.QuadPart = pPdd->memBase;
pUSBDRegs = (CSP_USB_REGS *)OALPAtoVA( CSP_BASE_REG_PA_USBOTG, FALSE);
if (pUSBDRegs == NULL)
{
USBDBGMSG(USBDBG_ZONE_ERROR, (L"UsbDbgPdd_Init::Controller registers mapping failed\r\n"));
rc=ERROR_NOT_ENOUGH_MEMORY;
goto clean;
}
pPdd->pUSBDRegs = pUSBDRegs;
//Setup the endpoint addresses
{
int i;
for (i=0;i<USBD_EP_COUNT;i++)
pPdd->ep[i]=&pPdd->eph[i];
}
//Setup Clock and initialize the transceiver.
if (HardwareInitialize(pPdd->pUSBDRegs)==FALSE)
{
USBDBGMSG(USBDBG_ZONE_ERROR, (L"UsbDbgPdd_Init:: fail to HardwareInitialize\r\n"));
goto clean;
}
//Clear all interurrpts
OUTREG32(&pUSBDRegs->OTG.USBINTR, 0);
// Reset all interrupts
{
USB_USBSTS_T temp;
DWORD *t=(DWORD*)&temp;
*t=0;
temp.UI=1; temp.UEI=1; temp.PCI=1; temp.FRI=1;
temp.SEI=1; temp.AAI=1; temp.URI=1; temp.SRI=1;
temp.SLI=1; temp.ULPII=1;
OUTREG32(&pUSBDRegs->OTG.USBSTS, *t);
}
qhHead = IMAGE_SHARE_USBKITL_RAM_PA_START;
pPdd->qhbuf_phy = ((qhHead + 0x1000 - 1) & 0xFFFFF000);
pPdd->qhbuffer = (USBFN_QH_BUF_T *)OALPAtoVA(pPdd->qhbuf_phy, FALSE);
memset(pPdd->qhbuffer, 0, sizeof(USBFN_QH_BUF_T));
//Initialize the ENDPOINTLISTADDR register with physicall address of qhbuffer.
OUTREG32(&pUSBDRegs->OTG.T_158H.ENDPOINTLISTADDR,pPdd->qhbuf_phy);
// allocate Recv and Transmit buffer from the USBKITL reserved memory area
USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"UsbDbgPdd_Init:: pPdd->qhbuffer 0x%x, size 0x%x\r\n", pPdd->qhbuffer, sizeof(USBFN_QH_BUF_T)));
//Calculte the endpoint buffer addresses
pPdd->EndPointBufferBasePhysical = pPdd->qhbuf_phy + sizeof(USBFN_QH_BUF_T);
pPdd->EndPointBufferBasePhysical = (pPdd->EndPointBufferBasePhysical + 0x1000 - 1) & 0xFFFFF000; // Align it to the next 4K boundary
if (InitializeEndPoints(pPdd, pDeviceDesc))
{
USBDBGMSG(USBDBG_ZONE_ERROR, (L"UsbDbgPdd_Init::InitializeEndPoints failed\r\n"));
goto clean;
}
//Do not run the controller here, it will be done when MDD calls connect
USBControllerRun(pUSBDRegs, FALSE);
pPddIfc->version = 2;
pPddIfc->pfnDeinit = UsbDbgPdd_DeInit;
pPddIfc->pfnConnect = UsbDbgPdd_Connect;
pPddIfc->pfnDisconnect = UsbDbgPdd_Disconnect;
pPddIfc->pfnIoctl = UsbDbgPdd_Ioctl;
pPddIfc->pfnEventHandler = UsbDbgPdd_EventHandler;
pPddIfc->pfnRecvData = UsbDbgPdd_RecvData;
pPddIfc->pfnSendData = UsbDbgPdd_SendData;
pPddIfc->pfnSendCmd = UsbDbgPdd_SendCmd;
pPddIfc->pfnSetPower = UsbDbgPdd_SetPower;
g_dwLastPktStatus = 0;
rc = ERROR_SUCCESS;
clean:
USBDBGMSG(USBDBG_ZONE_FUNC, (L"usbdbgpdd: -UsbDbgPdd_Init\r\n"));
return rc;
}
Requirements
Header |
UsbDbgDdsi.h |
See Also
Reference
USBDBG PDD Functions
USBDBG_MDD_INTERFACE_INFO
USBDBG_PDD_INTERFACE_INFO
USBDBG_DEVICE_DESCRIPTOR