//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
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.
Module Name:
SX2.CPP
Abstract:
Cypress SX2 USB Function Platform-Dependent Driver.
--*/
/*************************************************************************************************
Copyright (2004), Cypress Semiconductor Corporation
This software is owned by Cypress Semiconductor Corporation (Cypress) and is
protected by United States copyright laws and international treaty provisions. Cypress
hereby grants to Licensee a personal, non-exclusive, non-transferable license to copy,
use, modify, create derivative works of, and compile the Cypress Source Code and
derivative works for the sole purpose of creating custom software in support of Licensee
product ("Licensee Product") to be used only in conjunction with a Cypress integrated
circuit. Any reproduction, modification, translation, compilation, or representation of this
software except as specified above is prohibited without the express written permission of
Cypress.
Disclaimer: Cypress makes no warranty of any kind, express or implied, with regard to
this material, including, but not limited to, the implied warranties of merchantability and
fitness for a particular purpose. Cypress reserves the right to make changes without
further notice to the materials described herein. Cypress does not assume any liability
arising out of the application or use of any product or circuit described herein. Cypress�
products described herein are not authorized for use as components in life-support
devices.
This software is protected by and subject to worldwide patent coverage, including U.S.
and foreign patents. Use may be limited by and subject to the Cypress Software License
Agreement.
Module Name:
sx2.cpp
Created:
4/6/2004
Description:
Cypress SX2+ USB Function Platform-Dependent Driver.
Notes:
*************************************************************************************************/
// TODO: The Following are TODO items
// 1)Determine if there is somewhere in the enumeration sequence where the
// FIFO Can be Flushed. Start/Stop Naking routines may help.
// 2) Optimize Wait States
#include "sx2.h"
#include "cyp_hw.h"
#include <nkintr.h>
#include <oalintr.h>
#include <devload.h>
#define UDC_REG_PROTOCOL_VAL _T("Protocol")
//#include <windev.h>
//
// Data message. All Offset fields contain byte offsets from the beginning
// of the RNDIS_PACKET structure. All Length fields are in bytes.
// VcHandle is set to 0 for connectionless data, otherwise it
// contains the VC handle.
//
#include <pshpack1.h>
typedef struct _RNDIS_PACKET
{
UINT32 DataOffset;
UINT32 DataLength;
UINT32 OOBDataOffset;
UINT32 OOBDataLength;
UINT32 NumOOBDataElements;
UINT32 PerPacketInfoOffset;
UINT32 PerPacketInfoLength;
UINT32 * VcHandle;
UINT32 Reserved;
} RNDIS_PACKET, *PRNDIS_PACKET;
#include <poppack.h>
#define IS_VALID_SX2_CONTEXT(ptr) \
( (ptr != NULL) && (ptr->dwSig == SX2_SIG) )
#define UDC_REG_PRIORITY_VAL _T("Priority256")
#define ENDPOINT_COUNT 9
#define EP_VALID(x) ((x) < ENDPOINT_COUNT)
#define EP0_PACKET_SIZE 0x40
#define EP1_PACKET_SIZE 0x40
#define EP2_PACKET_SIZE 512
#define EP6_PACKET_SIZE 512
#define EP_FIFO_CAPACITY 1024
#define UED_BI 3
static EP_STATUS g_rgEpStatus[ENDPOINT_COUNT] = {
{ 0, // End Point Number
USB_ENDPOINT_TYPE_CONTROL, // type supported
UED_BI, // direction supported
EP0_PACKET_SIZE, // packet size supported
0x00, // packet size assigned
FALSE, // fInitialized
EP_STATE_IDLE
},
{ 1, // End Point Number
USB_ENDPOINT_TYPE_INTERRUPT, // Interrupt
USB_IN_TRANSFER, // IN
EP1_PACKET_SIZE, // packet size supported
0x00,
FALSE, // fInitialized
EP_STATE_IDLE
},
{ 2, // End Point Number
USB_ENDPOINT_TYPE_BULK, // BULK
USB_OUT_TRANSFER, // OUT
EP2_PACKET_SIZE, // packet size supported
0x00,
FALSE, // fInitialized
EP_STATE_IDLE
},
{ 3, // End Point Number
0, // BULK
0, // OUT
0, // packet size supported
0x00,
FALSE, // fInitialized
EP_STATE_IDLE
},
{ 4, // End Point Number
0, // type supported
0, // direction supported
0, // packet size supported
0x00, // packet size assigned
FALSE, // fInitialized
EP_STATE_IDLE
},
{ 5, // End Point Number
0, // BULK
0, // OUT
0, // packet size supported
0x00,
FALSE, // fInitialized
EP_STATE_IDLE
},
{ 6, // End Point Number
USB_ENDPOINT_TYPE_BULK , // BULK
USB_IN_TRANSFER, // IN
EP6_PACKET_SIZE, // packet size supported
0x00,
FALSE, // fInitialized
EP_STATE_IDLE
},
{ 7, // End Point Number
0 , // BULK
0, // IN
0, // packet size supported
0x00,
FALSE, // fInitialized
EP_STATE_IDLE
},
{ 8, // End Point Number
0, // type supported
0, // direction supported
0, // packet size supported
0x00, // packet size assigned
FALSE, // fInitialized
EP_STATE_IDLE
},
};
#define DEFAULT_PRIORITY 108
#define IN_TRANSFER_INTERRUPTS DATA_PKT_TX_INT_MASK
#define OUT_TRANSFER_INTERRUPTS DATA_PKT_RX_INT_MASK
static PBYTE g_pRxBuffer = NULL;
static PBYTE g_pTxBuffer = NULL;
// Surround calls with cs on both the endpoint and the transfer.
static
VOID
CompleteTransfer(
PSX2_CONTEXT pContext,
PEP_STATUS peps,
DWORD dwUsbError
)
{
SETFNAME(_T("CompleteTransfer"));
FUNCTION_ENTER_MSG();
PSTransfer pTransfer = peps->pTransfer;
peps->pTransfer = NULL;
pTransfer->dwUsbError = dwUsbError;
pTransfer->fComplete = TRUE;
UfnMdd_TransferComplete(pContext->pvMddContext, pTransfer);
FUNCTION_LEAVE_MSG();
}
static BYTE
GetEndpointCfgReg (
DWORD dwEndpoint
)
{
BYTE bReg;
switch (dwEndpoint) {
// EP1 - OUT
case 1:
bReg = SX2_REG_EP1INCFG;
break;
case 2:
bReg = SX2_REG_EP2CFG;
break;
case 6:
bReg = SX2_REG_EP6CFG;
break;
default:
DEBUGC