📄 ncufnpdd.c
字号:
/******************************************************************************
Copyright (C) 2003, NetChip Technology, Inc. (http://www.netchip.com)
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
NCUFNPDD.C
NcUfnPdd combined with NetChip's Firmware API forms the PDD layer in
Microsoft's WinCE 5.0 USB Function Controller Driver Stack.
The Firmware API is composed of NcFwApi.c, NcDevice.c, NcHal.c, System.c,
and NcDebug.c.
******************************************************************************/
///////////////////////////////////////////////////////////////////////////////
//#include <conio.h>
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <NcCommon.H> // Collection of common NetChip header files
#include <plx.h>
#include <nkintr.h>
#include <ceddk.h>
#include <giisr.h>
#include <ddkreg.h>
#include <dbgapi.h>
#include <windef.h>
#define __USB200_H__
#include <usbfn.h>
#include <NcUfnPdd.h>
///////////////////////////////////////////////////////////////////////////////
#define DEBUGMASK(bit) (1 << (bit))
#define MASK_ERROR DEBUGMASK(0)
#define MASK_WARN DEBUGMASK(1)
#define MASK_INIT DEBUGMASK(2)
#define MASK_FUNCTION DEBUGMASK(3)
#define MASK_IOCTL DEBUGMASK(4)
#define MASK_DEVICE DEBUGMASK(5)
#define MASK_ACTIVITY DEBUGMASK(6)
///////////////////////////////////////////////////////////////////////////////
DBGPARAM dpCurSettings = {
_T("Transfer"),
{
_T("Errors"), _T("Warnings"), _T("Init"), _T("Function"),
_T("Ioctl"), _T("Device"), _T("Activity"), _T(""),
_T(""),_T(""),_T(""),_T(""),
_T(""),_T(""),_T(""),_T("")
},
MASK_ERROR | MASK_WARN | MASK_INIT | MASK_IOCTL | MASK_DEVICE
};
///////////////////////////////////////////////////////////////////////////////
NCSTATUS
NcUfnPdd_SetConfigurationHandler(
PNC_DEVICE_OBJECT DeviceObject
)
{ // USB host is configuring (or de-configuring) our device (See USB 2.0: 9.4.7)
// - If the configuration is non-zero, create and start endpoint transfers
// - This routine runs in an interrupt context, so it should return quickly
switch (DeviceObject->SetupPacket.wValue.Word)
{ // Set Configuration:
// - Action depends on the host's requested configuration number:
case 0: // Configuration 0: (De-configuration)
// Let the API's default handler process de-configuration
// - Return More Processing Required indicating to the API that it is to apply its
// default Set Configuration handler:
return NCSTATUS_MORE_PROCESSING_REQUIRED;
case 1: // Configuration 1:
// Since the MDD is handling all of the setup packets, and not the NetChip Firmware API
// we must calle NcApi_UpdateHsFsConfigurations so that it can update its internal
// configuration variables
NcApi_UpdateHsFsConfigurations(DeviceObject);
// Configure our device:
// Call API function to count and initialize all endpoints specified in the configuration
// - On return, endpoints can be created and transfers started
NcApi_SetConfiguration(DeviceObject);
NCPRINTF(DEFAULT_PRINT, ("CeUfnPdd_SetConfigurationHandler(): Configured!\n"));
// Return Success to indicate that the request has been completely handled. The API
// will not attempt to handle this request
return NCSTATUS_SUCCESS;
default:
// Assert: This firmware model does not support more than one
// configuration. If a device is to support more configurations
// (e.g. configuration 2, 3, ...), HS and FS configurations in
// the Device Object would need to be adjusted before calling
// the API Set Configuration routine
ASSERT(DeviceObject->DeviceDescriptor->bNumConfigurations == 1);
return NCSTATUS_UNSUCCESSFUL;
}
return NCSTATUS_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
NCSTATUS
NcUfnPdd_ClientUsbDeviceRequestHandler(
PNC_DEVICE_OBJECT DeviceObject
)
{ // Client's USB device request handler
// - This handler is called on every USB Device Request, but only a few "client
// specific" requests need to be handled here. The rest are handled by the API.
//ASSERT(DeviceObject->EventCode == NC_DEVICE_EVENT_USB_DEVICE_REQUEST);
PCEUFNPDD_CONTEXT pContext = (PCEUFNPDD_CONTEXT)DeviceObject->ClientContext1;
HISTO(DEFAULT_HISTORY, "DRqH", pContext->SpeedReported, DeviceObject->SetupPacket.bmRequestType, DeviceObject->SetupPacket.bRequest);
// If we haven't reported the bus speed to the MDD, do so now
if (!pContext->SpeedReported)
{
DWORD dwParam;
pContext->SpeedReported = TRUE;
// Update Bus Speed
NcApi_UpdateHsFsConfigurations(DeviceObject);
switch (DeviceObject->BusSpeed)
{
case NC_BUS_SPEED_HIGH:
dwParam = BS_HIGH_SPEED;
break;
case NC_BUS_SPEED_FULL:
dwParam = BS_FULL_SPEED;
break;
default:
dwParam = BS_UNKNOWN_SPEED;
break;
}
LeaveCriticalSection(&pContext->csInterrupt);
pContext->pfnNotify(pContext->pvMddContext, UFN_MSG_BUS_SPEED, dwParam);
EnterCriticalSection(&pContext->csInterrupt);
HISTO(DEFAULT_HISTORY, "SpRe", dwParam, 0, 0);
}
// If this is a SET_CONFIGURATION request, we need to do a little bit before we notify the MDD
if (
(DeviceObject->SetupPacket.bmRequestType == (HOST_TO_DEVICE | STANDARD | RECIPIENT_DEVICE)) &&
(DeviceObject->SetupPacket.bRequest == SET_CONFIGURATION)
)
{
HISTO(DEFAULT_HISTORY, "SeCo", 0, 0, 0);
// Host request is a "Set Configuration" request
// - See USB 2.0: 9.4.7 and table 9-4
NcUfnPdd_SetConfigurationHandler(DeviceObject);
}
// Notify the MDD of the Setup Packet
LeaveCriticalSection(&pContext->csInterrupt);
pContext->pfnNotify(pContext->pvMddContext, UFN_MSG_SETUP_PACKET, (DWORD)&DeviceObject->SetupPacket);
EnterCriticalSection(&pContext->csInterrupt);
// On a SET_ADDRESS, we allow the FirmwareAPI to set the USB address
// So we tell the lower level that we didn't handle it.
if (
(DeviceObject->SetupPacket.bmRequestType == (HOST_TO_DEVICE | STANDARD | RECIPIENT_DEVICE)) &&
(DeviceObject->SetupPacket.bRequest == SET_ADDRESS)
)
{ // Host request is a "Set Address" request
// - See USB 2.0: 9.4.6 and table 9-4
return NCSTATUS_MORE_PROCESSING_REQUIRED;
}
return NCSTATUS_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
NCSTATUS
NcUfnPdd_DeviceEventHandler(
PNC_DEVICE_OBJECT pDeviceObject
)
{
PCEUFNPDD_CONTEXT pContext = (PCEUFNPDD_CONTEXT)pDeviceObject->ClientContext1;
DWORD dwMsg;
DWORD dwParam;
HISTO(DEFAULT_HISTORY, "DEvH", pDeviceObject->EventCode, 0, 0);
dwMsg = UFN_MSG_BUS_EVENTS;
if ((pDeviceObject->UsbPowerState == NC_USB_POWER_ON) && !pContext->ConnectionReported)
{
LeaveCriticalSection(&pContext->csInterrupt);
if (pContext->pfnNotify(pContext->pvMddContext, dwMsg, UFN_ATTACH))
{
pContext->ConnectionReported = TRUE;
}
EnterCriticalSection(&pContext->csInterrupt);
}
switch (pDeviceObject->EventCode)
{
case NC_DEVICE_EVENT_DEVICE_REQUEST:
return NcUfnPdd_ClientUsbDeviceRequestHandler(pDeviceObject);
case NC_DEVICE_EVENT_VBUS_TRUE: // Plug-in event
if (pContext->ConnectionReported)
{
// The connection message was sent just before the setup
// packet interrupt
return NCSTATUS_SUCCESS;
}
if (pContext->pfnNotify(pContext->pvMddContext, dwMsg, UFN_ATTACH))
{
pContext->ConnectionReported = TRUE;
}
return NCSTATUS_SUCCESS;
case NC_DEVICE_EVENT_VBUS_FALSE: // Unplug event
dwParam = UFN_DETACH;
pContext->SpeedReported = FALSE;
pContext->ConnectionReported = FALSE;
break;
case NC_DEVICE_EVENT_ROOT_PORT_RESET: // Reset signalling detected
dwParam = UFN_RESET;
pContext->SpeedReported = FALSE;
break;
case NC_DEVICE_EVENT_SUSPEND: // Suspend signalling detected
dwParam = UFN_SUSPEND;
break;
case NC_DEVICE_EVENT_RESUME: // Resume signalling detected
dwParam = UFN_RESUME;
break;
default:
return NCSTATUS_SUCCESS;
}
HISTO(DEFAULT_HISTORY, "UmDn", dwMsg, dwParam, 0);
LeaveCriticalSection(&pContext->csInterrupt);
pContext->pfnNotify(pContext->pvMddContext, dwMsg, dwParam);
EnterCriticalSection(&pContext->csInterrupt);
return NCSTATUS_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
DWORD
WINAPI
UfnPdd_Deinit(
PVOID pvPddContext
)
{
PCEUFNPDD_CONTEXT pContext = (PCEUFNPDD_CONTEXT) pvPddContext;
SetEvent(pContext->hKillEvent);
TerminateThread(pContext->hInterruptThread, 0);
LocalFree(pContext->pNcDeviceObject->DeviceQualifierDescriptor);
CloseHandle(pContext->hInterruptThread);
CloseHandle(pContext->hInterruptEvent);
LocalFree(pContext->pNcDeviceObject);
LocalFree(pContext);
return ERROR_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
DWORD
WINAPI
UfnPdd_IOControl(
PVOID pvPddContext,
IOCTL_SOURCE source,
DWORD dwCode,
PBYTE pbIn,
DWORD cbIn,
PBYTE pbOut,
DWORD cbOut,
PDWORD pcbActualOut
)
{
return ERROR_INVALID_PARAMETER;
}
///////////////////////////////////////////////////////////////////////////////
void
WINAPI
UfnPdd_PowerDown(
PVOID pvPddContext
)
{
UNREFERENCED_PARAMETER(pvPddContext);
}
///////////////////////////////////////////////////////////////////////////////
void
WINAPI
UfnPdd_PowerUp(
PVOID pvPddContext
)
{
UNREFERENCED_PARAMETER(pvPddContext);
}
///////////////////////////////////////////////////////////////////////////////
DWORD
WINAPI
UfnPdd_IsConfigurationSupportable(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -