📄 isp1581.cpp
字号:
{
volatile unsigned short *pIOBASE = (unsigned short *)pContext->pusTemIOBASE;
VirtualFree((PVOID)pIOBASE, 0, MEM_RELEASE);
pContext->pusTemIOBASE = 0;
}
//
//need to connect isr to system,find HW,io remmap,cs,
//
static
DWORD
FindUSBDeviceHardware(
LPCTSTR pszActiveKey,
HKEY hkDevice,
PUSBSLAVE_PDD_CONTEXT pContext
)
{
SETFNAME();
// DEBUGCHK(pszActiveKey);
// PREFAST_DEBUGCHK(pContext);
DWORD dwRet = ERROR_GEN_FAILURE;
//
//init the system intrruption
//
pContext->dwSysIntr = SYSINTR_USBSLAVE;
//
//re mmap IO memmory
//
InitIOMap(pContext);
//
//find the chip id
//
if(TestUSBChipID(pContext)==0)
goto EXIT;
//
//initialize DMA buffer (uncache and unbuffer)
//
//USBDMAinit(IOBASE);
// USBChipEnable(pContext);
dwRet = ERROR_SUCCESS;
EXIT:
return dwRet;
}
static
VOID
FreeUSBDeviceContext(
PUSBSLAVE_PDD_CONTEXT pContext
)
{
pContext->dwSig = GARBAGE_DWORD;
if (pContext->hBusAccess) CloseBusAccessHandle(pContext->hBusAccess);
ReleaseIOMap(pContext);
if(g_dma_enabled && pContext->pusDMAVirtualBASE)
{
FreePhysMem((LPVOID)pContext->pusDMAVirtualBASE);
}
if (pContext->dwSysIntr) {
KernelIoControl(IOCTL_HAL_DISABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
}
DeleteCriticalSection(&pContext->csSharedRegisterAccess);
LocalFree(pContext);
}
// **** Functions called by the MDD ****
// Deinitialize the ISP1581.
DWORD
WINAPI
UfnPdd_Deinit(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
FUNCTION_ENTER_MSG();
FreeUSBDeviceContext(pContext);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
DWORD Init_PDD_Int(PVOID pvPddContext)
{
SETFNAME();
FUNCTION_ENTER_MSG();
DWORD dwRet;
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
BOOL fIntInitialized = FALSE;
// Create the 1581 interrupt event
pContext->hevInterrupt = CreateEvent(0, FALSE, FALSE, NULL);
if (pContext->hevInterrupt == NULL) {
dwRet = GetLastError();
DEBUGMSG(ZONE_ERROR, (_T("%s Error creating ISP1581 interrupt event. Error = %d\r\n"),
pszFname, dwRet));
goto EXIT;
}
fIntInitialized = InterruptInitialize(pContext->dwSysIntr,
pContext->hevInterrupt, NULL, 0);
if (fIntInitialized == FALSE) {
dwRet = ERROR_GEN_FAILURE;
DEBUGMSG(ZONE_ERROR, (_T("%s ISP1581 interrupt initialization failed\r\n"),
pszFname));
goto EXIT;
}
pContext->fExitIST = FALSE;
pContext->hIST = CreateThread(NULL, 0, USBSlaveIntrThread, pContext, 0, NULL);
if (pContext->hIST == NULL) {
DEBUGMSG(ZONE_ERROR, (_T("%s IST creation failed\r\n"), pszFname));
dwRet = GetLastError();
goto EXIT;
}
pContext->fRunning = TRUE;
dwRet = ERROR_SUCCESS;
EXIT:
if (pContext->fRunning == FALSE)
{
DEBUGCHK(dwRet != ERROR_SUCCESS);
if (fIntInitialized) InterruptDisable(pContext->dwSysIntr);
if (pContext->hevInterrupt) CloseHandle(pContext->hevInterrupt);
pContext->hevInterrupt = NULL;
}
return dwRet;
}
//
// Start the 1581.
//
DWORD
WINAPI
UfnPdd_Start(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
DWORD dwRet;
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
volatile unsigned short *pIOBASE = (unsigned short *)pContext->pusTemIOBASE;
pIOBASE[HwUSBMode >> REG_ALIGN_OFFSET] |= 0x00;
Sleep(50);
// Plug-In
pIOBASE[HwUSBMode >> REG_ALIGN_OFFSET] |= USB_MODE_SOFT_CONNECT|USB_MODE_INT_ENABLE;
pIOBASE[HwUSBAddress >> REG_ALIGN_OFFSET] |= USB_ADDRESS_DEVICE_ENABLE;
dwRet=ERROR_SUCCESS;
//
//initialize the interrupt handler of PDD driver.
//
Init_PDD_Int(pContext);
FUNCTION_LEAVE_MSG();
return dwRet;
}
//
// Stop the 1581.
//
DWORD
WINAPI
UfnPdd_Stop(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
// Stop the IST
pContext->fExitIST = TRUE;
InterruptDisable(pContext->dwSysIntr);
SetEvent(pContext->hevInterrupt);
WaitForSingleObject(pContext->hIST, INFINITE);
CloseHandle(pContext->hevInterrupt);
CloseHandle(pContext->hIST);
pContext->hIST = NULL;
pContext->hevInterrupt = NULL;
pContext->fRunning = FALSE;
DEBUGMSG(ZONE_USB_EVENTS, (_T("%s Device has been disabled\r\n"),
pszFname));
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
//
//1581
//
DWORD
WINAPI
UfnPdd_RegisterDevice(
PVOID pvPddContext,
PCUSB_DEVICE_DESCRIPTOR pHighSpeedDeviceDesc,
PCUFN_CONFIGURATION pHighSpeedConfig,
PCUSB_CONFIGURATION_DESCRIPTOR pHighSpeedConfigDesc,
PCUSB_DEVICE_DESCRIPTOR pFullSpeedDeviceDesc,
PCUFN_CONFIGURATION pFullSpeedConfig,
PCUSB_CONFIGURATION_DESCRIPTOR pFullSpeedConfigDesc,
PCUFN_STRING_SET pStringSets,
DWORD cStringSets
)
{
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
// Nothing to do.
return ERROR_SUCCESS;
}
//
//1581
//
DWORD
WINAPI
UfnPdd_DeregisterDevice(
PVOID pvPddContext
)
{
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
// Nothing to do.
return ERROR_SUCCESS;
}
//
//1581
//
DWORD
WINAPI
UfnPdd_IsConfigurationSupportable(
PVOID pvPddContext,
UFN_BUS_SPEED Speed,
PUFN_CONFIGURATION pConfiguration
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
DWORD dwRet = ERROR_SUCCESS;
FUNCTION_LEAVE_MSG();
return dwRet;
}
//
// Is this endpoint supportable on the 1581
//.
DWORD
WINAPI
UfnPdd_IsEndpointSupportable(
PVOID pvPddContext,
DWORD dwEndpoint,
UFN_BUS_SPEED Speed,
PUSB_ENDPOINT_DESCRIPTOR pEndpointDesc,
BYTE bConfigurationValue,
BYTE bInterfaceNumber,
BYTE bAlternateSetting
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
DWORD dwRet = ERROR_INVALID_PARAMETER;
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
// Special case for endpoint 0
if (dwEndpoint == 0)
{
// Endpoint 0 only supports 64 byte packet size
if (pEndpointDesc->wMaxPacketSize < EP_0_PACKET_SIZE) {
DEBUGMSG(ZONE_ERROR, (_T("%s Endpoint 0 only supports %u byte packets\r\n"),
pszFname, EP_0_PACKET_SIZE));
goto EXIT;
}
pEndpointDesc->wMaxPacketSize = EP_0_PACKET_SIZE;
}
else {
BYTE bTransferType = pEndpointDesc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
// Validate and adjust packet size
WORD wPacketSize =
(pEndpointDesc->wMaxPacketSize & USB_ENDPOINT_MAX_PACKET_SIZE_MASK);
// The MDD should guarantee the following. All USB packet
// sizes can be supported for endpoints A-D.
if (Speed == BS_HIGH_SPEED)
{
switch(bTransferType)
{
case USB_ENDPOINT_TYPE_BULK:
DEBUGCHK(wPacketSize == 8 || wPacketSize == 16 || wPacketSize == 32 ||
wPacketSize == 64 || wPacketSize == 512);
break;
case USB_ENDPOINT_TYPE_INTERRUPT:
DEBUGCHK(wPacketSize <= 1024);
break;
case USB_ENDPOINT_TYPE_ISOCHRONOUS:
DEBUGCHK(wPacketSize <= 1024);
break;
}
}
else
{
DEBUGCHK(Speed == BS_FULL_SPEED);
switch(bTransferType) {
case USB_ENDPOINT_TYPE_BULK:
DEBUGCHK(wPacketSize == 8 || wPacketSize == 16 || wPacketSize == 32 ||
wPacketSize == 64);
break;
case USB_ENDPOINT_TYPE_INTERRUPT:
DEBUGCHK(wPacketSize <= 64);
break;
case USB_ENDPOINT_TYPE_ISOCHRONOUS:
DEBUGCHK(wPacketSize <= 1023);
break;
}
}
}
dwRet = ERROR_SUCCESS;
EXIT:
FUNCTION_LEAVE_MSG();
return dwRet;
}
//****************************************************************************
//
// USBStallEndpoint stalls or un-stalls the specified endpoint.
//
//****************************************************************************
void
USBEnableEndpoint( PUSBSLAVE_PDD_CONTEXT pContext,unsigned long ulEndpoint, unsigned long bEnable)
{
volatile unsigned short *pIOBASE = (unsigned short *)pContext->pusTemIOBASE;
pIOBASE[HwUSBEndpointIndex >> REG_ALIGN_OFFSET] = ( unsigned short ) (ulEndpoint);
if(bEnable ==1)
{
pIOBASE[HwUSBEndpointType >> REG_ALIGN_OFFSET] &= ~USB_EPTYPE_ENABLE;
pIOBASE[HwUSBEndpointType >> REG_ALIGN_OFFSET] |= USB_EPTYPE_ENABLE;
}
else
{
pIOBASE[HwUSBEndpointType >> REG_ALIGN_OFFSET] &= ~USB_EPTYPE_ENABLE;
}
}
DWORD
WINAPI
UfnPdd_InitEndpoint(
PVOID pvPddContext,
DWORD dwEndpoint,
UFN_BUS_SPEED Speed,
PUSB_ENDPOINT_DESCRIPTOR pEndpointDesc,
PVOID pvReserved,
BYTE bConfigurationValue,
BYTE bInterfaceNumber,
BYTE bAlternateSetting
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
volatile unsigned short *pIOBASE = (unsigned short *)pContext->pusTemIOBASE;
PEP_STATUS peps = GetEpStatus(pContext, dwEndpoint);
DEBUGCHK(!peps->fInitialized);
InitializeCriticalSection(&peps->cs);
peps->fInitialized = TRUE;
// If the target is endpoint 0, then only allow the function driver
// to register a notification function.
if (peps->dwEndpoint == 0)
{
peps->wMaxPacketSize = EP_0_PACKET_SIZE;
// Interrupts for endpoint 0 are enabled in ISTMain
}
else
{
peps->wMaxPacketSize =
(pEndpointDesc->wMaxPacketSize & USB_ENDPOINT_MAX_PACKET_SIZE_MASK);
peps->bmAttributes = pEndpointDesc->bmAttributes;
InitEndpoint(pvPddContext, pEndpointDesc, dwEndpoint);
}
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
// Deinitialize an endpoint.
DWORD
WINAPI
UfnPdd_DeinitEndpoint(
PVOID pvPddContext,
DWORD dwEndpoint
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -