📄 isp1581.cpp
字号:
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
PEP_STATUS peps = GetEpStatus(pContext, dwEndpoint);
LOCK_ENDPOINT(peps);
DEBUGCHK(peps->fInitialized);
DEBUGCHK(peps->pTransfer == NULL);
if (dwEndpoint != 0) {
// Disable the endpoint
USBEnableEndpoint( pContext,peps->dwEndpoint,0);
// after a call to UfnPdd_Stop.
// Disable endpoint interrupts
DisableEndpointInterrupt(pContext, peps->dwEndpoint);
// Clear endpoint interrupts
}
peps->fInitialized = FALSE;
UNLOCK_ENDPOINT(peps);
DeleteCriticalSection(&peps->cs);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
// Stall an endpoint.1581
DWORD
WINAPI
UfnPdd_StallEndpoint(
PVOID pvPddContext,
DWORD dwEndpoint
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
PEP_STATUS peps = GetEpStatus(pContext, dwEndpoint);
LOCK_ENDPOINT(peps);
DEBUGCHK(peps->fInitialized);
USBStallEndpoint(pContext,peps->dwEndpoint,1);
UNLOCK_ENDPOINT(peps);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
// Clear an endpoint stall.1581
DWORD
WINAPI
UfnPdd_ClearEndpointStall(
PVOID pvPddContext,
DWORD dwEndpoint
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
PEP_STATUS peps = GetEpStatus(pContext, dwEndpoint);
LOCK_ENDPOINT(peps);
DEBUGCHK(peps->fInitialized);
USBStallEndpoint(pContext,peps->dwEndpoint,0);
UNLOCK_ENDPOINT(peps);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
// Send the control status handshake.
DWORD
WINAPI
UfnPdd_SendControlStatusHandshake(
PVOID pvPddContext,
DWORD dwEndpoint
)
{
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);
LOCK_ENDPOINT(peps);
DEBUGCHK(peps->fInitialized);
pIOBASE[HwUSBEndpointIndex >> REG_ALIGN_OFFSET] = (USB_ENDPOINT_0<<1) | USB_ENDPOINT_DIR_IN;
pIOBASE[HwUSBEndpointControl >> REG_ALIGN_OFFSET] |= USB_EPCONTROL_STATUS_ACK;
UNLOCK_ENDPOINT(peps);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
// Set the address of the 1581 on the USB.
DWORD
WINAPI
UfnPdd_SetAddress(
PVOID pvPddContext,
BYTE bAddress
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
volatile unsigned short *pIOBASE = (unsigned short *)pContext->pusTemIOBASE;
//
// Configure our UBS controller for the USB address assigned by the host.
//
pIOBASE[HwUSBAddress >> REG_ALIGN_OFFSET] = (USB_ADDRESS_DEVICE_ENABLE |bAddress);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
// Is endpoint halted?
DWORD
WINAPI
UfnPdd_IsEndpointHalted(
PVOID pvPddContext,
DWORD dwEndpoint,
PBOOL pfHalted
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
volatile unsigned short *pIOBASE = (unsigned short *)pContext->pusTemIOBASE;
unsigned long ulEndpointStatus;
PEP_STATUS peps = GetEpStatus(pContext, dwEndpoint);
LOCK_ENDPOINT(peps);
DEBUGCHK(peps->fInitialized);
//
// Select the appropriate endpoint.
//
pIOBASE[HwUSBEndpointIndex >> REG_ALIGN_OFFSET] = (unsigned short)(peps->dwEndpoint) ;
//
// Send the Validate buffer command so that the endpoint can send
// the packet.
//
ulEndpointStatus = pIOBASE[HwUSBEndpointControl >> REG_ALIGN_OFFSET] ;
*pfHalted = ulEndpointStatus&0x1;
UNLOCK_ENDPOINT(peps);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
//
//Now we do not support the feature
//
DWORD
WINAPI
UfnPdd_InitiateRemoteWakeup(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
volatile unsigned short *pIOBASE = (unsigned short *)pContext->pusTemIOBASE;
pIOBASE[HwUSBMode >> REG_ALIGN_OFFSET] |= USB_MODE_WAKE_UP_CS;
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
VOID
WINAPI
UfnPdd_PowerDown(
PVOID pvPddContext
)
{
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
// Nothing to do.
}
VOID
WINAPI
UfnPdd_PowerUp(
PVOID pvPddContext
)
{
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
// Nothing to do.
}
DWORD
WINAPI
UfnPdd_IOControl(
PVOID pvPddContext,
IOCTL_SOURCE source,
DWORD dwCode,
PBYTE pbIn,
DWORD cbIn,
PBYTE pbOut,
DWORD cbOut,
PDWORD pcbActualOut
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
DWORD dwRet = ERROR_INVALID_PARAMETER;
switch (dwCode) {
case IOCTL_UFN_GET_PDD_INFO:
if ( source != BUS_IOCTL || pbOut == NULL ||
cbOut != sizeof(UFN_PDD_INFO) ) {
break;
}
// Not currently supported.
break;
}
FUNCTION_LEAVE_MSG();
return dwRet;
}
DWORD InitializeDMA(PVOID pvPddContext)
{
PUSBSLAVE_PDD_CONTEXT pContext = (PUSBSLAVE_PDD_CONTEXT) pvPddContext;
pContext->pusDMAVirtualBASE = (ULONG) AllocPhysMem(
4*1024,
PAGE_READWRITE | PAGE_NOCACHE,
0,
0,
&pContext->pusDMAPhysicalBASE
);
*CSC_SYSLOCK = 0xAA;
*CSC_PWRCNT |= PWRCNT_DMAM2MCH1;
*CSC_SYSLOCK = 0xAA;
*CSC_DEVCFG |= DEVCFG_D1ONG;
return 0;
}
// Initialize the ISP1581.
DWORD
WINAPI
UfnPdd_Init(
LPCTSTR pszActiveKey,
PVOID pvMddContext,
PUFN_MDD_INTERFACE_INFO pMddInterfaceInfo,
PUFN_PDD_INTERFACE_INFO pPddInterfaceInfo
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
static const UFN_PDD_INTERFACE_INFO sc_PddInterfaceInfo = {
UFN_PDD_INTERFACE_VERSION,
(UFN_PDD_CAPS_SUPPORTS_FULL_SPEED | UFN_PDD_CAPS_SUPPORTS_HIGH_SPEED),
ENDPOINT_COUNT,
NULL, // UfnPdd_Init corrects this later
&UfnPdd_Deinit,
&UfnPdd_IsConfigurationSupportable,
&UfnPdd_IsEndpointSupportable,
&UfnPdd_InitEndpoint,
&UfnPdd_RegisterDevice,
&UfnPdd_DeregisterDevice,
&UfnPdd_Start,
&UfnPdd_Stop,
&UfnPdd_IssueTransfer,
&UfnPdd_AbortTransfer,
&UfnPdd_DeinitEndpoint,
&UfnPdd_StallEndpoint,
&UfnPdd_ClearEndpointStall,
&UfnPdd_SendControlStatusHandshake,
&UfnPdd_SetAddress,
&UfnPdd_IsEndpointHalted,
&UfnPdd_InitiateRemoteWakeup,
&UfnPdd_PowerDown,
&UfnPdd_PowerUp,
&UfnPdd_IOControl,
};
DWORD cbData;
DWORD dwType;
PUSBSLAVE_PDD_CONTEXT pContext = NULL;
DWORD dwRet;
HKEY hkDevice = NULL;
hkDevice = OpenDeviceKey(pszActiveKey);
if (!hkDevice) {
dwRet = GetLastError();
DEBUGMSG(ZONE_ERROR, (_T("%s Could not open device key. Error: %d\r\n"),
pszFname, dwRet));
goto EXIT;
}
pContext = (PUSBSLAVE_PDD_CONTEXT) LocalAlloc(LPTR, sizeof(*pContext));
if (pContext == NULL) {
dwRet = GetLastError();
DEBUGMSG(ZONE_ERROR, (_T("%s LocalAlloc failed. Error: %d\r\n"), pszFname, dwRet));
goto EXIT;
}
pContext->pvMddContext = pvMddContext;
pContext->cpsCurrent = D4;
pContext->pfnNotify = pMddInterfaceInfo->pfnNotify;
InitializeCriticalSection(&pContext->csSharedRegisterAccess);
pContext->hBusAccess = CreateBusAccessHandle(pszActiveKey);
if (pContext->hBusAccess == NULL) {
// This is not a failure.
DEBUGMSG(ZONE_WARNING, (_T("%s Could not create bus access handle\r\n"),
pszFname));
}
// Initialize some of the endpoint structures.
memcpy(pContext->rgEpStatus, g_rgEpStatus, sizeof(pContext->rgEpStatus));
//
//find the usb device controller HW,and map......
//FindUSBDeviceHardware
//
dwRet = FindUSBDeviceHardware(pszActiveKey, hkDevice, pContext);
if (dwRet != ERROR_SUCCESS) {
DEBUGMSG(ZONE_ERROR, (_T("%s Hardware Initialization failed\r\n"), pszFname));
goto EXIT;
}
//
// Read the IST priority
//
DWORD dwPriority;
cbData = sizeof(dwPriority);
dwRet = RegQueryValueEx(hkDevice, UDC_REG_PRIORITY_VAL, NULL, &dwType,
(LPBYTE) &dwPriority, &cbData);
if ( (dwRet != ERROR_SUCCESS) || (dwType != REG_DWORD) ) {
dwPriority = DEFAULT_PRIORITY;
}
DEBUGMSG(ZONE_INIT, (_T("%s Setting IST priority to %u\r\n"),
pszFname, dwPriority));
pContext->dwISTPriority = dwPriority;
//
// Read the DMAEnable
//
DWORD dwDMAEnable;
cbData = sizeof(dwDMAEnable);
dwRet = RegQueryValueEx(hkDevice, UDC_DMA_ENABLE_VAL, NULL, &dwType,
(LPBYTE) &dwDMAEnable, &cbData);
if ( (dwRet != ERROR_SUCCESS) || (dwType != REG_DWORD) ) {
dwDMAEnable = 1;
}
DEBUGMSG(ZONE_INIT, (_T("%s Setting g_DMA_Enable to %u\r\n"),
pszFname, dwDMAEnable));
g_dma_enabled = dwDMAEnable;
//Reset the USB device controller chip
//
ResetDevice(pContext);
//
//initialize the driver.
//
if(g_dma_enabled)
InitializeDMA(pContext);
//
//initinal the PDD interface info to MDD
//
memcpy(pPddInterfaceInfo, &sc_PddInterfaceInfo, sizeof(sc_PddInterfaceInfo));
pPddInterfaceInfo->pvPddContext = pContext;
dwRet = ERROR_SUCCESS;
EXIT:
if (dwRet != ERROR_SUCCESS && pContext) {
FreeUSBDeviceContext(pContext);
}
if (hkDevice) RegCloseKey(hkDevice);
FUNCTION_LEAVE_MSG();
return dwRet;
}
// Called by MDD's DllEntry.
extern "C"
BOOL
UfnPdd_DllEntry(
HANDLE hDllHandle,
DWORD dwReason,
LPVOID lpReserved
)
{
// Nothing to do.
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -