⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bvd_udc_hw.c

📁 自制PDA系列之usb驱动(处理器PXA270)
💻 C
📖 第 1 页 / 共 5 页
字号:
/* 
** INTEL CONFIDENTIAL
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** The source code contained or described herein and all documents
** related to the source code (Material) are owned by Intel Corporation
** or its suppliers or licensors.  Title to the Material remains with
** Intel Corporation or its suppliers and licensors. The Material contains
** trade secrets and proprietary and confidential information of Intel
** or its suppliers and licensors. The Material is protected by worldwide
** copyright and trade secret laws and treaty provisions. No part of the
** Material may be used, copied, reproduced, modified, published, uploaded,
** posted, transmitted, distributed, or disclosed in any way without Intel抯
** prior express written permission.
**
** No license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise. Any license under such intellectual property rights
** must be express and approved by Intel in writing.
*/

/*
Module Name:  $Workfile: bvd_udc_hw.c $
$Date: 9/09/03 7:14p $
   
Abstract:  
 Contains the Bulverde implementation of 
 the USB Function Driver.
   
Notes: 
*/

#include <windows.h>
#include <types.h>
#include <ceddk.h>
#include <memory.h>
#include <serhw.h>
#undef ZONE_INIT
#include <serdbg.h>
#include "Bvd1.h"

//#include "xllp_udc.h"
#include "bvd_udc_hw.h"
#include "bvd_udc_ser.h"
#include "BVD_UDC_Bits.h"
#include "xllp_defs.h"
#include "xllp_serialization.h"
#include "xllp_clkmgr.h"


// Local prototypes for forward references.
void sendCommandDone(PSER_INFO);
void SA_USB_UDC_ReInit(PSER_INFO pHWHead);

#define DISABLE_DOUBLE_BUFFER 1

/* This driver defines a simple BULK FIFO device. It supports only one
 * interface with one alternate setting, as shown below.  
 *
 *  Endpoint    Setting 0
 *------------------------
 *  EP0         Control
 *  EP1 In      Bulk       
 *  EP2 Out     Bulk   
 */

/* Steal the useless IR zone from MDD and use it as EP0 & USB specific stuff
 */
#define ZONE_USB	ZONE_IR
#define ZONE_INT	ZONE_USR_READ

/* Define the configuration descriptor length
 */
#define CFGLEN 32
#define iCONF 18
#define TLEN   (CFGLEN + 18) 

// String Descriptor Indexes
#define languagesStringIndex        0
#define manufactureStringIndex      1
#define productStringIndex          2
#define configurationStringIndex    3
#define interfaceStringIndex        4
#define SerialNumberStringIndex     5
#define lastStringIndex             SerialNumberStringIndex

#define STRING_DESCRIPTOR			0x03

#define USBData_HighByte(x)         (((x) >> 8) & 0xff)         /* get high byte from the (usb) little endian */
#define USBData_LowByte(x)          ((x) & 0xff)                /* get low byte from the (usb) little endian */

// Languages Supported by the Device
const XLLP_UINT8_T LanguagesStringDescriptor[] =
{
    // String index zero for all languages returns a string descriptor taht
    // contains an 
    // array to two-byte LANGID codes supported by the device.  LANGID is
    // defined by the 
    // Microsoft for Windows as described in Developing International
    // Software for Windows.

    4,                 		// Length of descriptor  
    STRING_DESCRIPTOR, 		// Descriptor Type   
    0x09, 0x04         		// LANGID (English) 
};


// Manufacture String Descriptor - "Intel."
const XLLP_UINT8_T ManufactureStringDescriptor[] =
{
    14,                         // Length of descriptor 
    STRING_DESCRIPTOR,          // Descriptor Type
    'I', 0x00,                  // String in unicode
    'n', 0x00,
    't', 0x00,
    'e', 0x00,
    'l', 0x00,
    '.', 0x00,
};

// "PocketPC" and/or "Smartphone"
const  XLLP_UINT8_T ProductStringDescriptor[] =
{
    40,                       	// Length of descriptor
    STRING_DESCRIPTOR,      	// Descriptor Type
    'P',  0x00,               	// String in unicode
    'o',  0x00,
    'c',  0x00,
    'k',  0x00,
    'e',  0x00,
    't',  0x00,
    'P',  0x00,
    'C',  0x00,
	' ',  0x00,
    'S',  0x00,              	 // String in unicode
    'm',  0x00,
    'a',  0x00,
    'r',  0x00,
    't',  0x00,
    'P',  0x00,
    'h',  0x00,
    'o',  0x00,
    'n',  0x00,
    'e',  0x00,
};

/* Define the configuration descriptor itself
 */
const BYTE uStd[TLEN]=  {
    18,                 // bLength
    DEVICE,             // bDescriptorType
    1, 1,               // bcdUSB (compliant with V1.1)
    0xff,               // bDeviceClass (0xFF = Vendor Specific)
    0xff,               // bDeviceSubClass
    0xff,               // bDeviceProtocol
    EP0Len,             // bMaxPacketSize0
    0x5E, 0x04,         // idVendor (Microsoft's VID - 0x045E)
    0xCE, 0x00,         // idProduct (Microsoft's PID - 0x00CE)
    0, 0,               // bcdDevice
//	0,
//	0,
    manufactureStringIndex,  // iManufacturer - index of Manf String Descriptor
    productStringIndex, // iProduct - index of Product String Descriptor
    0,                  // iSerialNumber - Index of Serial Number String
    1,                  // bNumConfigurations
// std_config
    9,                  // bLength
    CONFIGURATION,      // bDescriptorType
    CFGLEN%256,CFGLEN/256,  // wTotalLength
    1,                  // bNumInterfaces
    1,                  // bConfigurationValue
    0,                  // iConfiguration
    0xC0,               // bmAttributes (although remote wakeup capable, not supported)
    1,                  // MaxPower (x2 mA)  (Is this correct?)
// std_inter
    9,                  // bLength
    INTERFACE,          // bDescriptorType
    0,                  // bInterfaceNumber
    0,                  // bAlternateSetting
    2,                  // bNumEndpoints (number endpoints used, excluding EP0)
    0xff,               // bInterfaceClass
    0xff,               // bInterfaceSubClass
    0xff,               // bInterfaceProtocol
    0,                  // ilInterface  (Index of this interface string desc.)
// endpoint1 - IN
    7,                  // bLength
    ENDPOINT,           // bDescriptorType
    0x81,               // bEndpointAddress (10000010 = IN, EP 1)
    2,                  // bmAttributes  (Bulk)
    EP1Len, 0,          // wMaxPacketSize
    0,                  // bInterval (ignored for Bulk)
// endpoint2 - Out
    7,                  // bLength
    ENDPOINT,           // bDescriptorType
    2,                  // bEndpointAddress (00000010 = OUT, EP 2)
    2,                  // bmAttributes  (Bulk)
    EP2Len, 0,          // wMaxPacketSize
    0                   // bInterval (ignored for Bulk)
};

/* EP1/EP2 packet size. For polling this can not be greater than 16
 */
static unsigned int maxOutPacketSize = EP2Len;
static unsigned int maxInPacketSize = EP1Len;
/*----------------------------------------------------------------------
 * Statistics
 */
typedef struct Udc_Stats_S {
  /* General stats
   */
  int usbIntCount;

  /* Endpoint 0 (Command) stats
   */
  int commandCount;

  int sendCount;
  int sendFailCount;
  int reSendCount;

  int readCount;
  int readFailCount;
  int reReadCount;

  int writeCount;
  int reWriteCount;

  /* DMA stats
   */
  int rcvDmaCount;
  int xmitDmaCount;

  /* Loopback stats
   */
  int loopCount;
  int rxCompareCount;
  int rxCompareError;

  /* Endpoint 1 (IN) stats
   */
  int writePacketCount;
  int missedTIR;
  int badWrPacketCount;
  int goodWrPacketCount;
  int noDMA;

  /* Endpoint 2 (OUT) stats
   */
  int readPacketCount;
  int acceptPacketCount;
  int extraFIFOReads;
  int fifoReadOverrun;
  int missedRIR;
  int badRdPacketCount;
  int dmaReadPending;
  int noRPC;
  int rejectPacket;


  /* UDCCR bit write stats
   */
  int uddWrites;
  int uddRewrites;
  int rimWrites;
  int rimRewrites;
  int eimWrites;
  int eimRewrites;
  int timWrites;
  int timRewrites;

  /* UDCOMP bit write stats
   */
  int compWrites;
  int compRewrites;

  /* UDCIMP bit write stats
   */
  int cimpWrites;
  int cimpRewrites;

  /* UDCCS0 bit write stats
   */
  int sseWrites;
  int sseRewrites;
  int soWrites;
  int soRewrites;
  int sstWrites;
  int sstRewrites;
  int fstWrites;
  int fstRewrites;
  int iprWrites;
  int iprRewrites;

  /* UDCCS1 bit write stats
   */
  int rpcWrites;
  int rpcRewrites;
  int fst1Writes;
  int fst1Rewrites;
  int sst1Writes;
  int sst1Rewrites;

  /* UDCCS2 bit write stats
   */
  int tpcWrites;
  int tpcRewrites;
  int fst2Writes;
  int fst2Rewrites;
  int sst2Writes;
  int sst2Rewrites;

  /* UDCSR bit write stats
   */
  int eirWrites;
  int eirRewrites;
  int rirWrites;
  int rirRewrites;
  int tirWrites;
  int tirRewrites;
  int rstirWrites;
  int rstirRewrites;
  int susirWrites;
  int susirRewrites;
  int resirWrites;
  int resirRewrites;
} Udc_Stats_T;

static Udc_Stats_T udcStats;

// Uncomment the next line to enable tracing.
//#define UDC_TRACE 1
//#define UDC_DEBUG 1
#define PAGE_NUM 8

//#ifdef UDC_DEBUG
//#ifdef BSP_MAINSTONE
//volatile BLR_REGS *g_pBLReg = NULL;
//volatile XLLP_BCR_T *g_pBLReg = NULL;
//#endif
//#endif

PDWORD	g_pTraceBuffer = NULL;

#ifdef UDC_TRACE

// Trace buffer pointer used in UDCTrace.
// Check the region being used with config.bib to rule out conflicts 
// with other allocated memory areas. Memory can be allocated from UNUSED_BUF region. 
// Address being used defined in header file - UDC_PHYSICAL_TRACE_BUFFER  
//

void UDCTrace( PSER_INFO pHWHead, DWORD dwType, DWORD dwData )
{
	DWORD dwFrame, dwIndex;
	if( g_pTraceBuffer == NULL )
		return;

	dwIndex = g_pTraceBuffer[0];

	g_pTraceBuffer[dwIndex++] = dwType | 0x98760000;
	g_pTraceBuffer[dwIndex++] = dwData;
	g_pTraceBuffer[dwIndex++] = GetTickCount();
	
	// Include the frame numbers on each trace instead of the signature.
	dwFrame = (UDC_FNR(pHWHead) & 0x7ff);

	g_pTraceBuffer[dwIndex++] = dwFrame;

	if( dwIndex >= ((PAGE_SIZE*PAGE_NUM) / sizeof(DWORD)))
		dwIndex = 4;


	g_pTraceBuffer[dwIndex+3] = 0x98761234;
	g_pTraceBuffer[0] = dwIndex;
}
#else
#define UDCTrace( x, y, z )
#endif


/*
 * SA_USB_Dump_UDC_Regs
 *
 *
 */
void SA_USB_Dump_UDC_Regs(
	PSER_INFO pHWHead
	)
{
	RETAILMSG( 1, (TEXT("\r\nDumping UDC Regs:\r\n")));
	RETAILMSG( 1, (TEXT("UDC_CR:    %X\r\n"),    UDC_CR(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_ICR0:  %X\r\n"),  UDC_ICR0(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_ICR1:  %X\r\n"),  UDC_ICR1(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_ISR0:  %X\r\n"),  UDC_ISR0(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_ISR1:  %X\r\n"),  UDC_ISR1(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_FNR:   %X\r\n"),   UDC_FNR(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_CSR0:  %X\r\n"),  UDC_CSR0(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_CR_A:  %X\r\n"), ENDPOINT_A(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_CSR_A: %X\r\n"), UDC_CSR_A(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_CR_B:  %X\r\n"), ENDPOINT_B(pHWHead) ));
	RETAILMSG( 1, (TEXT("UDC_CSR_B: %X\r\n"), UDC_CSR_B(pHWHead) )); 
}


/*----------------------------------------------------------------------
 * Forward reference
 */

/*----------------------------------------------------------------------
 * Clear stats block
 */
static
void clearUdcStats(void)
{
  memset(&udcStats,0,sizeof(udcStats));
}

/*
 * getCommand 
 * 
 * Read the command from the endpoint 0 FIFO
 *
 * Returns  1 if read failed,
 *          0, success
 */
static
int getCommand(PSER_INFO pHWHead, void * dataP)
{
	volatile unsigned int bytes_to_read =0, word_count, byte_count, rx_word1; // temp_byte_count;
	PBYTE pData = dataP;
	//volatile  BYTE  *pEP0FIFO;
	//pEP0FIFO = (volatile  BYTE  *) &(UDC_DR_0( pHWHead ));

	//memset(pData,0x55,8);

	bytes_to_read = UDC_BCR_0(pHWHead);
	word_count = bytes_to_read/4;
	byte_count = bytes_to_read%4;

	if (word_count)
	{
	 while (word_count)
	 {
		 rx_word1 = UDC_DR_0( pHWHead );
		 //pRxWord[0] = rx_word1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -