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

📄 xllp_udc.c

📁 优龙pxa270平台试验程序
💻 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:       xllp_udc.c
**
**  PURPOSE:   		This files contains the driver for USB Device controller 
**                  (UDC).
**
**
******************************************************************************/

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

#include <string.h>
#include "xllp_defs.h"
#include "xllp_udc.h"
#include "xllp_udc_os_depend.h"

extern const XLLP_INT8_T UsbDeviceDesc[];
extern const XLLP_INT8_T UsbConfigDesc[];
extern const XLLP_UDC_EP_CONFIG_TABLE_T defaultUdcEndpointConfigTable[];

/******************************************************************************

  Function Name: 
    XllpUdcComputeConfigRegisterValueSingle

  Description: 
    This function computes the configuration values that will be loadded to
    the Endpoints Configuration Registers UDCCRA-UDCCRX, based on the entries
    in the Endpoints Configuration table. It stores the configuration value in
    the Endpoints Configuration table. It also returns the configuration register's 
    value.

  Global Register Modified: 
    None 

  Input Arguments:
    XLLP_UDC_EP_T               udcEndpointNum        
    XLLP_UINT8_T                usbConfigNum          
    XLLP_UINT8_T                usbInterfaceNum       
    XLLP_UINT8_T                usbIntAltSettingsNum  
    XLLP_UDC_USB_EP_T           usbEndpointNum        
    XLLP_UDC_EP_TYPE_T          usbEndpointType       
    XLLP_UDC_EP_DIR_T           usbEndpointDirection  
    XLLP_UINT16_T               maxPacketSize      
    XLLP_UDC_EP_DOUBLE_BUFF_T   doubleBuffEnabled
    XLLP_UDC_EP_ENABLED_T       endpointEnabled
    P_XLLP_UINT32_T             pEndpointConfigRegValue

  Output Arguments:
    P_XLLP_UINT32_T pEndpointConfigRegValue
          
  Return Value:
    None 

*******************************************************************************/

void XllpUdcComputeConfigRegisterValueSingle (
                                    XLLP_UDC_EP_T   udcEndpointNum,        
                                    XLLP_UINT8_T    usbConfigNum,          
                                    XLLP_UINT8_T    usbInterfaceNum,       
                                    XLLP_UINT8_T    usbIntAltSettingsNum,  
                                    XLLP_UDC_USB_EP_T   usbEndpointNum,        
                                    XLLP_UDC_EP_TYPE_T  usbEndpointType,       
                                    XLLP_UDC_EP_DIR_T   usbEndpointDirection,  
                                    XLLP_UINT16_T   maxPacketSize,      
                                    XLLP_UDC_EP_DOUBLE_BUFF_T   doubleBuffEnabled,  	
                                    XLLP_UDC_EP_ENABLED_T       endpointEnabled,
                                    P_XLLP_UINT32_T pEndpointConfigRegValue)
{
    XLLP_UINT32_T endpointConfigValue;

    // Compute the Configuration register value
    endpointConfigValue = 
                    // Usb Configuration Number: (1-3)
                    usbConfigNum << XLLP_UDC_UDCCRZ_CN_SHIFT  |
                    // Usb Interface Number: (1-7)
                    usbInterfaceNum << XLLP_UDC_UDCCRZ_IN_SHIFT |
                    // Usb Interface Alternate Settings Number: (1-7)
                    usbIntAltSettingsNum << XLLP_UDC_UDCCRZ_AISN_SHIFT |
                    // Usb Endpoint Number: (1-15)
                    usbEndpointNum << XLLP_UDC_UDCCRZ_EN_SHIFT |
                    // Usb Endpoint type: Bulk, Iso, Interrupt
                    usbEndpointType << XLLP_UDC_UDCCRZ_ET_SHIFT |
                    // Usb Endpoint direction: IN, OUT
                    usbEndpointDirection << XLLP_UDC_UDCCRZ_ED_SHIFT |
                    // Max. Packet Size: (1-1023)
                    ((maxPacketSize << XLLP_UDC_UDCCRZ_MPS_SHIFT) & XLLP_UDC_UDCCRZ_MPS_MASK) |
                    // Double Buffering enabled\disabled and enable Endpoint
                    (doubleBuffEnabled << XLLP_UDC_UDCCRZ_DE_SHIFT) | XLLP_UDC_UDCCRZ_EE;

    // Return the Configuration register value
    *pEndpointConfigRegValue = endpointConfigValue;
}                                               

/******************************************************************************

  Function Name: 
    XllpUdcComputeConfigRegisterValue

  Description: 
    This function computes the configuration values that will be loadded to
    the Endpoints Configuration Registers UDCCRA-UDCCRX, based on the entries
    in the Endpoints Configuration table. It stores the configuration value in
    the Endpoints Configuration table. It also returns the configuration register's 
    value.

  Global Register Modified: 
    None 

  Input Arguments:
    P_XLLP_UDC_EP_CONFIG_TABLE_T pEndpointsConfigTable - a pointer to the Endpoints
                                                         Configuration Table.
  Output Arguments:
    P_XLLP_UINT32_T pEndpointConfigRegValue
          
  Return Value:
    None 

*******************************************************************************/

void XllpUdcComputeConfigRegisterValue (P_XLLP_UDC_EP_CONFIG_TABLE_T pEndpointsConfigTable,
                                        P_XLLP_UINT32_T pEndpointConfigRegValue)
{
    // Compute the Configuration register value
//    pEndpointsConfigTable->endpointConfigValue = 
    *pEndpointConfigRegValue =
    // Usb Configuration Number: (1-3)
    pEndpointsConfigTable->usbConfigNum << XLLP_UDC_UDCCRZ_CN_SHIFT  |
    // Usb Interface Number: (1-7)
    pEndpointsConfigTable->usbInterfaceNum << XLLP_UDC_UDCCRZ_IN_SHIFT |
    // Usb Interface Alternate Settings Number: (1-7)
    pEndpointsConfigTable->usbIntAltSettingsNum << XLLP_UDC_UDCCRZ_AISN_SHIFT |
    // Usb Endpoint Number: (1-15)
    pEndpointsConfigTable->usbEndpointNum << XLLP_UDC_UDCCRZ_EN_SHIFT |
    // Usb Endpoint type: Bulk, Iso, Interrupt
    pEndpointsConfigTable->usbEndpointType << XLLP_UDC_UDCCRZ_ET_SHIFT |
    // Usb Endpoint direction: IN, OUT
    pEndpointsConfigTable->usbEndpointDirection << XLLP_UDC_UDCCRZ_ED_SHIFT |
    // Max. Packet Size: (1-1023)
    ((pEndpointsConfigTable->maxPacketSize << XLLP_UDC_UDCCRZ_MPS_SHIFT) &
                                                    XLLP_UDC_UDCCRZ_MPS_MASK) |
    // Double Buffering enabled\disabled and enable Endpoint
    (pEndpointsConfigTable->doubleBuffEnabled << XLLP_UDC_UDCCRZ_DE_SHIFT) | 
                                                    XLLP_UDC_UDCCRZ_EE;

    // Return the Configuration register value
//    *pEndpointConfigRegValue = pEndpointsConfigTable->endpointConfigValue;
}

/******************************************************************************

  Function Name: 
    XllpUdcConfigureEndpoints

  Description: 
    This function configures and enables all of the Endpoints that are
    used for each of the USB Configurations and Interfaces.

  Global Register Modified: 
    None 

  Input Arguments:
    P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle

  Output Arguments:
    None
          
  Return Value: 
    XLLP_STATUS_T - error code if failed, zero if success

*******************************************************************************/

XLLP_STATUS_T XllpUdcConfigureEndpoints (P_XLLP_UDC_T pUdcHandle)
{
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    
    P_XLLP_UDC_EP_CONFIG_TABLE_T pConfigTable = (P_XLLP_UDC_EP_CONFIG_TABLE_T)
                                                           pUdcHandle->pConfigTable;
    XLLP_UINT32_T j, i = 1;
    XLLP_STATUS_T error = 0;
    XLLP_UINT32_T   endpointConfigRegValue;

    // Program the Endpoint Configuration Registers:
    // Disable UDC controller by writing zero to the UDE bit (UDCCR.UDE = 0),
    // that enables the Endpoint Configuration Registers for write operation.
    pRegs->UDCCR = 0;

    while (pConfigTable[i].usbEndpointNum != 0)
    {
        // Compute the values that would be loaded to the Endpoints Configuration 
        // Registers UDCCRA-UDCCRX, from the data in the Endpoints Configuration Table.
        XllpUdcComputeConfigRegisterValue (&pUdcHandle->pConfigTable[i], 
                                           &endpointConfigRegValue);

        // Write the configuration value to the Endpoints Configuration Registers UDCCRA-UDCCRX.
        j = pConfigTable[i].udcEndpointNum; 
//        pRegs->UDCCRZ[j] = pConfigTable[i].endpointConfigValue;
        pRegs->UDCCRZ[j] = endpointConfigRegValue;
        ++i;    
    }
   
    // Enable UDC controller by writing one to the bit UDE (UDCCR.UDE = 1),
    // that disables the Endpoint Configuration Registers for write operation.
    pRegs->UDCCR = XLLP_UDC_UDCCR_UDE;

    // Check if the Endpoint Memory Configuration is valid by reading the status of
    // the Endpoint Memory Configuration Error UDCCR.EMCE bit. 
    if (pRegs->UDCCR & XLLP_UDC_UDCCR_EMCE)
    {
        // This bit is set if the endpoint memory configuration has an error. 
        // The driver must clear UDCCR.EMCE bit by writing one to it before again enabling the UDC.
        pRegs->UDCCR = XLLP_UDC_UDCCR_EMCE;
        error = XLLP_TRUE;
    }

    return error;
}

/******************************************************************************

  Function Name: 
    XllpUdcEnableInterrupt

  Description: 
    This function enables the Endpoints or Events interrupt.

  Global Register Modified: 
    None 

  Input Arguments:
    P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
    XLLP_UDC_INTERRUPTS_T udcEndpointNum - an endpoint or event number
    XLLP_UDC_EP_INTERRUPT_TYPE_T interruptType - PC or FIFO error interrupts

  Output Arguments:
    None
          
  Return Value: 
    None

*******************************************************************************/

void XllpUdcEnableInterrupt (P_XLLP_UDC_T pUdcHandle, 
                            XLLP_UDC_INTERRUPTS_T udcEndpointNum,
                            XLLP_UDC_EP_INTERRUPT_TYPE_T interruptType)
{
    XLLP_UINT32_T bitNum;
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    
    
    // Set the corresponding bit in the UDC's interrupt control registers UDCICR0 and UDCICR1
    // to enable the endpoint's and event's interrupt requests.
    if (udcEndpointNum < INT_ENDPOINT_Q)
    {
 	    bitNum = (udcEndpointNum << 1) | interruptType;
   	    pRegs->UDCICR0 |= (1 << bitNum);		  
 	}														  
    else if (udcEndpointNum < INT_ENDPOINT_X + 1)
    {														  
     	udcEndpointNum -= INT_ENDPOINT_Q;
     	bitNum = ((udcEndpointNum  & 0xff) << 1) | interruptType;
   	    pRegs->UDCICR1 |= (1 << bitNum);		  
    }
    else if (udcEndpointNum >= INT_RESET)
    {
   	    bitNum = (udcEndpointNum & 0x1f);
   	    pRegs->UDCICR1 |= (1 << bitNum);		  
    }
}

/******************************************************************************

  Function Name: 
    XllpUdcDisableInterrupt

  Description: 
    This function disables the Endpoints or Events interrupts.

  Global Register Modified: 
    None 

  Input Arguments:
    P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
    XLLP_UDC_INTERRUPTS_T udcEndpointNum - an endpoint or event number
    XLLP_UDC_EP_INTERRUPT_TYPE_T interruptType - PC or FIFO error interrupts

  Output Arguments:
    None
          
  Return Value: 
    None

*******************************************************************************/

void XllpUdcDisableInterrupt (P_XLLP_UDC_T pUdcHandle, 
                            XLLP_UDC_INTERRUPTS_T udcEndpointNum,
                            XLLP_UDC_EP_INTERRUPT_TYPE_T interruptType)
{
    XLLP_UINT32_T bitNum;
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    

    // Clear the corresponding bit in the UDC's interrupt control registers UDCICR0 and UDCICR1
    // to disable the endpoint's and event's interrupt requests.
    if (udcEndpointNum < INT_ENDPOINT_Q)
    {
 	    bitNum = (udcEndpointNum << 1) | interruptType;
        pRegs->UDCICR0 &= ~(1 << bitNum);		  
 	}														  
    else if (udcEndpointNum < (INT_ENDPOINT_X + 1))
    {														  
     	udcEndpointNum -= INT_ENDPOINT_Q;
     	bitNum = ((udcEndpointNum  & 0xff) << 1) | interruptType;
        pRegs->UDCICR1 &= ~(1 << bitNum);		  
    }
    else if (udcEndpointNum >= INT_RESET)
    {
     	bitNum = (udcEndpointNum  & 0x1f);
        pRegs->UDCICR1 &= ~(1 << bitNum);		  
    }
}

/******************************************************************************

  Function Name: 
    XllpUdcClearInterrupt

  Description: 
    This function clears the Endpoints or Events interrupts.
    It also clears the Endpoint FIFO Error bit in the Endpoint's UDCCSR register.

  Global Register Modified: 
    None 

  Input Arguments:
    P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle

⌨️ 快捷键说明

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