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

📄 xsusb.c

📁 这是一个USB的驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under 
**  license and may only be used or copied in accordance with the terms of the 
**  license. The information in this file is furnished for informational use 
**  only, is subject to change without notice, and should not be construed as 
**  a commitment by Intel Corporation. Intel Corporation assumes no 
**  responsibility or liability for any errors or inaccuracies that may appear 
**  in this document or any software that may be provided in association with 
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by 
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME:  		xsusb.c
**
**  PURPOSE:   		This files contains the driver for UDC (USB Device controller)
**
**  LAST MODIFIED: $Modtime: 1/18/02 10:05a $
**
******************************************************************************/

/*
*******************************************************************************
*   HEADER FILES
*******************************************************************************
*/                                                                      

#include <string.h>
#include "dm.h"
#include "dm_errors.h"
#include "DM_Debug.h"
#include "cotulla.h"
#include "XsIntCtrlApi.h"
#include "XsDmaApi.h"
#include "XsClkMgr.h"
#include "serialCommon.h"
#include "mallocx.h"
#define UDC_GLOBALS  1
#include "xsusb.h"


#define COTULLA_A1 0x69052101
#define SABINAL_A1 0x69052122

/*
*******************************************************************************
*   GLOBAL DEFINITIONS
*******************************************************************************
*/

/*
*******************************************************************************
*   LOCAL DEFINITIONS
*******************************************************************************
*/

VOID XsUdcEP1IntHandler (UdcContextT * ctxP);
VOID XsUdcEP2IntHandler (UdcContextT * ctxP);
VOID XsUdcEP3IntHandler (UdcContextT * ctxP);
VOID XsUdcEP4IntHandler (UdcContextT * ctxP);
UINT32 XsDmaPopulateChainWithBufs (XsDmaDescriptorElementsTPT rootDescP);

// The Loopback Device Descriptor
CHAR UsbDeviceDesc[] = {
  18,			            // Descriptor length
  UsbDescTypeDevice,	    // Device descriptor
  0x10,		            	// USB 1.1 (LSB)
  1,			            // USB 1.1 (MSB)
  0xff,			            // No class
  0xff,			            // No sub class
  0xff,			            // No protoocol
  UDC_MAX_PACKET_SIZE_CTL,  // Max packet size EP0
  0x86,			            // Vendor ID (LSB) (Intel VID 32902)
  0x80,			            // Vendor ID (MSB)
  0x55,			            // Product ID
  0x55,			            // Product ID
  0,			            // Device BCD (LSB)
  0,			            // Device BCD (MSB)
  0,			            // Index of Manufacturer string
  0,			            // Index of Product string
  0,			            // Index of Serial number string
  3,		                // Number of configurations
};

// Note: UDC supports four device configurations.
// Configurations 1,2, and 3 each support two interfaces.
// This configuration descriptor has three configurations:
//   Configuration 1: BULK IN (EP1), BULK OUT (EP2)
//   Configuration 2: ISO IN (EP3), ISO OUT (EP4)
//   Configuration 5: Interrupt (EP5)
// Each of the configuration has one interface.  
CHAR UsbConfigDesc[] = {
// Configuration 1: Bulk IN, Bulk OUT
  9,			            // Descriptor length
  UsbDescTypeConfiguration, // Configuration descriptor
  UDC_CONFIG1_LENGTH,	    // Total len (LSB)
  0,			            // Total len (MSB)
  1,			            // Number interfaces
  1,			            // Configuration value
  0,			            // Configuration string index
  0xC0,			            // Attributes
  125,			            // Max Power

  9,			            // Descriptor length 
  UsbDescTypeInterface,     // Interface descriptor
  0,			            // Number of interface
  0,			            // Alternate setting
  2,			            // Number endpoints
  0xff,			            // Interface class 
  0xff,			            // Interface sub class
  0xff,			            // Interface protocol
  0,			            // Interface string descriptor

  7,			            // Descriptor length
  UsbDescTypeEndpoint,      // Endpoint descriptor
  0x81,			            // Endpoint address 1 (IN)
  UsbBulk,		            // Bulk transfer 
  BULK_IN_LENGTH,           // Max packet size LSB
  0,			            // Max packet size MSB
  0,			            // Polling interval

  7,			            // Descriptor length
  UsbDescTypeEndpoint,      // Endpoint descriptor
  0x02,			            // Endpoint address 2 (OUT)
  UsbBulk,		            // Bulk transfer
  BULK_OUT_LENGTH,     	    // Max packet size LSB
  0,			            // Max packet size MSB
  0,			            // Polling interval

// Configuration 2: ISO IN, ISO OUT, 
  9,			            // Descriptor length
  UsbDescTypeConfiguration, // Configuration descriptor
  UDC_CONFIG2_LENGTH,	    // Total len (LSB)
  0,			            // Total len (MSB)
  1,			            // Number interfaces
  2,			            // Configuration value
  0,			            // Configuration string index
  0xC0,			            // Attributes
  125,			            // Max Power

  9,			            // Descriptor length 
  UsbDescTypeInterface,     // Interface descriptor
  0,			            // Number of interface
  0,			            // Alternate setting
  3,			            // Number endpoints
  0xff,			            // Interface class 
  0xff,			            // Interface sub class
  0xff,			            // Interface protocol
  0,			            // Interface string descriptor

  7,			            // Descriptor length
  UsbDescTypeEndpoint,      // Endpoint descriptor
  0x83,			            // Endpoint address 3 (IN)
  UsbIsochronous,		    // ISO transfer 
  0x00,                     // Max packet size LSB
  0x01,			            // Max packet size MSB
  0,			            // Polling interval

  7,			            // Descriptor length
  UsbDescTypeEndpoint,      // Endpoint descriptor
  0x04,			            // Endpoint address 4 (OUT)
  UsbIsochronous,		    // ISO transfer
  0x00,                     // Max packet size LSB
  0x01,			            // Max packet size MSB
  0,			            // Polling interval

// Configuration 3: Interrupt 
  9,			            // Descriptor length
  UsbDescTypeConfiguration, // Configuration descriptor
  UDC_CONFIG3_LENGTH,	    // Total len (LSB)
  0,			            // Total len (MSB)
  1,			            // Number interfaces
  3,			            // Configuration value
  0,			            // Configuration string index
  0xC0,			            // Attributes
  125,			            // Max Power

  9,			            // Descriptor length 
  UsbDescTypeInterface,     // Interface descriptor
  0,			            // Number of interface
  0,			            // Alternate setting
  1,			            // Number endpoints
  0xff,			            // Interface class 
  0xff,			            // Interface sub class
  0xff,			            // Interface protocol
  0,			            // Interface string descriptor

  7,			            // Descriptor length
  UsbDescTypeEndpoint,      // Endpoint descriptor
  0x05,			            // Endpoint address 5 (OUT)
  UsbInterrupt,		        // Interrupt transfer
  INT_IN_LENGTH,            // Max packet size LSB
  0,			            // Max packet size MSB
  0,			            // Polling interval
};

static UdcIntCountT defaultUdcIntCount;

// this is used to support the control transfer on the Endpoint 0
static INT EP0Status;       
static PCHAR TxBuffEp0P;
static PCHAR RxBuffEp0P;
static CHAR EP0OutData[256];
static UdcSetupDataT ReqData;
static UINT16 DescIndex;
static UINT16 DescType;
static UINT16 DataLen;
static INT16 VendorReqType;
static INT16 VendorReqEndpointNum;
static INT VendorReqXferLength;
static INT VendorReqComplete = FALSE;

/*
static UINT FrameNumber;
static CHAR EP1Data[BULK_IN_LENGTH * 4];
static CHAR EP2Data[BULK_OUT_LENGTH * 4];
static CHAR EP3Data[ISO_IN_LENGTH * 4];
static CHAR EP4Data[ISO_OUT_LENGTH * 4];
static CHAR EP5Data[INT_IN_LENGTH * 4];
*/


UINT XsUdcGetFrameNumber (UdcRegsT * regsP)
{
    return (((regsP->UFNHR & UDC_UFNHR_FNMSB_MASK) << 8) | regsP->UFNLR);
}

VOID XsUdcCaptureStatistics (PUINT buffP, PUINT regsP, UINT param, UINT offset, PUINT totalCaptured)
{
	UINT total;

	total = *totalCaptured;
	*(buffP + total++) = (UINT)regsP;
	*(buffP + total++) = *regsP | (param << offset);
	*totalCaptured = total;
}

VOID XsUdcDumpStatistics (PUINT buffP, PUINT totalCaptured)
{
 	INT i;
	UINT total;
	PUINT totalP = totalCaptured;


	if (*totalP > UDC_DEBUG_TOTAL)
	  total = UDC_DEBUG_TOTAL;
	else
	  total = *totalP / 2;
	DM_Printf("Total DBg:  %d", total);
    for (i = 0; i < total; i++)
	{
     	 DM_Printf("Register %08x : %08x", *buffP, *(buffP + 1));
     	 buffP += 2;
	}
}

/*
*******************************************************************************
*
* FUNCTION:         XsUdcEnableEndpointInt
*
* DESCRIPTION:      This function is used to enable the interrupts for Endpoints 0 - 15.
*
* INPUT PARAMETERS: UdcContextT * ctxP is a pointer to UDC's context structure
*                   INT endpointNum is an Endpoint's number
*
* RETURNS:          none
*
* GLOBAL EFFECTS:   none
*
* ASSUMPTIONS:      none
*
*******************************************************************************
*/
static
void XsUdcEnableEndpointInt (UdcContextT * ctxP, UdcEndpointsT endpointNum)
{
    volatile UdcRegsT * regsP = (UdcRegsT *)ctxP->regsP;    

    // Clear the corresponding bit in interrupt status/control register
    // to enable the endpoint's interrupt request

    if (endpointNum < Endpoint8)
    {
 	    regsP->UICR0 &= ~(1 << endpointNum);
 	}														  
    else
    {														  
     	regsP->UICR1 &= ~(1 << (endpointNum & 0x07));		  
    }
}

/*
*******************************************************************************
*
* FUNCTION:         XsUdcDisableEndpointInt
*
* DESCRIPTION:      This function is used to disable the interrupts for Endpoints 0 - 15.
*
* INPUT PARAMETERS: UdcContextT * ctxP is a pointer to UDC's context structure
*                   INT endpointNum is an Endpoint's number
*
* RETURNS:          none
*
* GLOBAL EFFECTS:   none
*
* ASSUMPTIONS:      none
*
*******************************************************************************
*/
static
void XsUdcDisableEndpointInt (UdcContextT * ctxP, UdcEndpointsT endpointNum)
{
    volatile UdcRegsT * regsP = (UdcRegsT *)ctxP->regsP;

    // Set the corresponding bit in interrupt status/control register
    // to disable the interrupt request
    if (endpointNum < Endpoint8)
    {
 		regsP->UICR0 |= (1 << endpointNum);
 	}
    else
    {
     	regsP->UICR1 |= (1 << (endpointNum & 0x07));
    }
}

/*
*******************************************************************************
*
* FUNCTION:         XsUdcClearEndpointInt
*
* DESCRIPTION:      This function is used to clear the interrupts for Endpoints 0 - 15.
*
* INPUT PARAMETERS: UdcContextT * ctxP is a pointer to UDC's context structure
*                   INT endpointNum is an Endpoint's number
*
* RETURNS:          none
*
* GLOBAL EFFECTS:   none
*
* ASSUMPTIONS:      none
*
*******************************************************************************
*/
static
void XsUdcClearEndpointInt (UdcContextT * ctxP, UdcEndpointsT endpointNum)
{
    volatile UdcRegsT * regsP = (UdcRegsT *)ctxP->regsP;
        
    // Write the corresponding bit in interrupt status/control register
    // to clear the interrupt
    if (endpointNum < Endpoint8)
    {
 		regsP->UISR0 = (1 << endpointNum);
 	}
    else
    {
     	regsP->UISR1 = (1 << (endpointNum & 0x07));
    }
}

VOID XsUdcCopyDataOutToIn (XsDmaDescriptorElementsT * firstDescInVtP,
                            XsDmaDescriptorElementsT * firstDescOutVtP,
                            INT shortPacket)
{
    XsDmaDescriptorElementsT* currentOutP = firstDescOutVtP; 
    XsDmaDescriptorElementsT* nextOutP;

⌨️ 快捷键说明

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