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

📄 xllp_udc.c

📁 优龙pxa270平台试验程序
💻 C
📖 第 1 页 / 共 5 页
字号:
    else
    {
        // Set this bit to disable USB Client detection
        pBoardReg->miscWr2 |= XLLP_MISC_WR2_USB_SC;
    }
}

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

  Function Name: 
    XllpUdcForceEndpointStall

  Description:
    This function forces the Endpoint to send STALL to the USB Host.
    It sets the UDCCSR.FST bit so the STALL handshake will be issued to all IN tokens.

  Global Register Modified: 
    None. 

  Input Arguments:
    P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
    XLLP_UDC_EP_T udcEndpointNum    - the UDC endpoint number

  Output Arguments:
    None
          
  Return Value: 
    None

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

void XllpUdcForceEndpointStall (P_XLLP_UDC_T pUdcHandle,
                                XLLP_UDC_EP_T udcEndpointNum)
{
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    
    
    pRegs->UDCCSR[udcEndpointNum] = 
          (pRegs->UDCCSR[udcEndpointNum] & XLLP_UDC_UDCCSR_DME) | XLLP_UDC_UDCCSR_FST; 
}

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

  Function Name: 
    XllpUdcClearEndpointStall

  Description:
    This function clears the UDCCSR.SST bit, after the STALL handshake was issued 
    from the UDC.

  Global Register Modified: 
    None. 

  Input Arguments:
    P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
    XLLP_UDC_EP_T udcEndpointNum    - the UDC endpoint number

  Output Arguments:
    None
          
  Return Value: 
    None

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

void XllpUdcClearEndpointStall (P_XLLP_UDC_T pUdcHandle,
                                XLLP_UDC_EP_T udcEndpointNum)
{
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    
    
    pRegs->UDCCSR[udcEndpointNum] = 
          (pRegs->UDCCSR[udcEndpointNum] & XLLP_UDC_UDCCSR_DME) | XLLP_UDC_UDCCSR_SST; 
}

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

  Function Name: 
    XllpUdcFlashEndpointFifo

  Description:
    This function flashes the Endpoint抯 FIFO. It sets the UDCCSR.FEF bit.

  Global Register Modified: 
    None. 

  Input Arguments:
    P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
    XLLP_UDC_EP_T udcEndpointNum    - the UDC endpoint number

  Output Arguments:
    None
          
  Return Value: 
    None

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

void XllpUdcFlashEndpointFifo (P_XLLP_UDC_T pUdcHandle,
                               XLLP_UDC_EP_T udcEndpointNum)
{
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    
    
    pRegs->UDCCSR[udcEndpointNum] = 
          (pRegs->UDCCSR[udcEndpointNum] & XLLP_UDC_UDCCSR_DME) | XLLP_UDC_UDCCSR_FEF; 
}
                                        
/******************************************************************************

  Function Name: 
    XllpUdcConfigInterruptHandler

  Description: 
    This is the UDC's Configuration interrupt handler. This function is called
    when the USB Host issues the Set_Config or Set_Interface requests on the USB bus.

  Global Register Modified: 
    None. 

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

  Output Arguments:
    None
          
  Return Value: 
    None

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

void XllpUdcConfigInterruptHandler (P_XLLP_UDC_T pUdcHandle)
{       
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    
    XLLP_UINT32_T numActiveEndpoints;
    XLLP_UINT32_T configuration, interface, settings;

    // Get Active UDC Configuration number
    configuration = (pRegs->UDCCR & XLLP_UDC_UDCCR_ACN_MASK) >> XLLP_UDC_UDCCR_ACN_SHIFT;

    // Get Active UDC Interface Number
    interface = (pRegs->UDCCR & XLLP_UDC_UDCCR_AIN_MASK) >> XLLP_UDC_UDCCR_AIN_SHIFT;
    
    // Get Active UDC Alternative Interface Setting Number
    settings = (pRegs->UDCCR & XLLP_UDC_UDCCR_AAISN_MASK) >> XLLP_UDC_UDCCR_AAISN_SHIFT;

    // Switch Endpoint memory to active configuration
    pRegs->UDCCR |= XLLP_UDC_UDCCR_SMAC;

    if (pUdcHandle->usbConfigNumActive != configuration)
    {
        // Build the list of the endpoints in active configuration
        XllpUdcBuildListOfActiveEndpoints (pUdcHandle, 
                                           configuration, interface, settings,
                                           &numActiveEndpoints);
    
        // Update active configuration, interface and alt. settings in UDC handler structure
        pUdcHandle->usbConfigNumActive = configuration;     
        pUdcHandle->usbInterfaceNumActive = interface;   
        pUdcHandle->usbIntAltSettingsNumActive = settings;
    }
}


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

  Function Name: 
    XllpUdcHWSetup

  Description: 
    This function initilizes UDC Controller's hardware.

  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 XllpUdcHWSetup (P_XLLP_UDC_T pUdcHandle)
{
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    
    P_XLLP_CLK_MGR_REGS_T pClkMgrRegs = (P_XLLP_CLK_MGR_REGS_T)XLLP_CLK_MGR_REGS_BASE;
    XLLP_STATUS_T error = 0;

    // Enable USB Client Unit Clock in Clock-Enable Register, CKEN [11] = 1.
    pClkMgrRegs->CKEN |= XLLP_CLK_MGR_REGS_CKEN_UDC_EN;

    // Program the Endpoint Configuration Registers.
    error = XllpUdcConfigureEndpoints (pUdcHandle);
    if (!error)
    {
        // Enables Reset, Resume, and Configuration change interrupts by
        // setting the corresponding bits to one in the UDC Interrupt Control Register UDCICR1,
        // and disables Start of the frame interrupt.
//        pRegs->UDCICR1 = XLLP_UDC_UDCICR1_EVENTS & ~XLLP_UDC_UDCICR1_IESOF;
        pRegs->UDCICR1 = (XLLP_UDC_UDCISR1_IRRU | XLLP_UDC_UDCISR1_IRRS | XLLP_UDC_UDCISR1_IRCC) &
                         ~XLLP_UDC_UDCICR1_IESOF & ~XLLP_UDC_UDCISR1_IRSU;

        // Enable the Endpoint 0 interrupt by setting IE0[0] and IE0[1] in the UDC 
        // Interrupt Control Register UDCICR0, so it will respond to the USB Host requests.
        XllpUdcEnableInterrupt (pUdcHandle, 
                                INT_ENDPOINT_0,
                                PACKET_COMPL_INT);
        
        XllpUdcEnableInterrupt (pUdcHandle, 
                                INT_ENDPOINT_0,
                                FIFO_ERROR_INT);

        // Register the first level UDC interrupt with the interrupt service.
        // This is function wraper, OS specific or none
        XllpUdcRegisterFirstLevelInterrupt(pUdcHandle);

        // Enable the first level UDC interrupt.
        // This is function wraper, OS specific or none
        XllpUdcEnableFirstLevelInterrupt();

        // Set the setup complete flag in the UDC抯 handler structure to signal 
        // that hardware setup was successful.
        pUdcHandle->setupComplete = XLLP_TRUE;
    }

    return error;
}


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

  Function Name: 
    XllpUdcHWShutdown

  Description: 
    This function will shutdown the UDC Controller's hardware and clears the UDC 
    handle's variables.

  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 XllpUdcHWShutdown (P_XLLP_UDC_T pUdcHandle)
{
    volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;    
    P_XLLP_CLK_MGR_REGS_T pClkMgrRegs = (P_XLLP_CLK_MGR_REGS_T)XLLP_CLK_MGR_REGS_BASE;
    XLLP_STATUS_T error = 0;

    // Disable USB Client Unit Clock in Clock-Enable Register, CKEN [11] = 0.
    pClkMgrRegs->CKEN &= XLLP_CLK_MGR_REGS_CKEN_UDC_DIS;

    // Disable the interrupt requests from endpoints A - X, and all Event interrupts
    pRegs->UDCICR0 &= ~XLLP_UDC_UDCICR0_ENABLE_ALL;
    pRegs->UDCICR1 &= ~(XLLP_UDC_UDCICR1_EVENTS | XLLP_UDC_UDCICR1_ENABLE_ALL);
     
    // Disable first level UDC interrupt
    error = XllpUdcDisableFirstLevelInterrupt();

    // Unregister the UDC interrupt handler    
    error = XllpUdcUnRegisterFirstLevelInterrupt();

    // Clear the rest of the UDC handle抯 variables
	pUdcHandle->setupComplete = XLLP_FALSE;
    pUdcHandle->enumerateComplete = XLLP_FALSE;
    pUdcHandle->cableAttached = XLLP_FALSE;
    pUdcHandle->enableDma = XLLP_FALSE;

    pUdcHandle->usbConfigNumActive = 0;
    pUdcHandle->usbInterfaceNumActive = 0;
    pUdcHandle->usbIntAltSettingsNumActive = 0; 

    return error;
}

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

  Function Name: 
    XllpUdcSWInit

  Description: 
    This function initializes the handle's variables that will be used by the 
    UDC driver and no hardware will be accessed it this point.

  Global Register Modified: 
    None. 

  Input Arguments:
    P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
	P_XLLP_UDC_REGISTERS_T pRegs - a pointer to the UDC's registers base

  Output Arguments:
    None
          
  Return Value: 
    None

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

void XllpUdcSWInit (P_XLLP_UDC_T pUdcHandle, P_XLLP_UDC_REGISTERS_T pRegs)
{
//    XLLP_UINT32_T   endpointConfigRegValue, i = 1;

    // Set the UDC handle抯 pointer to the UDC Registers 
    // with the base address of the UDC Registers.
    pUdcHandle->pRegsBase = (P_XLLP_UDC_REGISTERS_T)pRegs;

    // Sets the UDC handle抯 pointer to the Endpoints Configuration Table 
    // with the pointer to the default Endpoints Configuration Table.
    pUdcHandle->pConfigTable = (P_XLLP_UDC_EP_CONFIG_TABLE_T)defaultUdcEndpointConfigTable;

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

    // Clear the Interrupt Statistics structure
    memset (&pUdcHandle->interruptStat, 0, sizeof(XLLP_UDC_INT_STATISTICS_T));

    // Clear the Endpoints transfer structures
    memset (&pUdcHandle->EpXferTable[0], 0, (sizeof(XLLP_UDC_XFER_T) * XLLP_UDC_MAX_EP_NUM));

    // Clear the Endpoint 0 control structure
    memset (&pUdcHandle->controlXfer, 0, sizeof(XLLP_UDC_USB_CTRL_XFER_T));

    // Clear the Vendor requests control structure
    memset (&pUdcHandle->vendorReq, 0, sizeof(XLLP_UDC_VENDOR_REQ_DATA_T));

    // Clear the List of Active Endpoints
    memset (&pUdcHandle->listOfActiveEndpoints, 0, 
                         (sizeof(XLLP_UDC_USB_BIND_ENDPOINTS_T) * XLLP_UDC_USB_MAX_EP_NUM));

    // Clear the rest of the UDC handle抯 variables
	pUdcHandle->setupComplete = XLLP_FALSE;
    pUdcHandle->enumerateComplete = XLLP_FALSE;
    pUdcHandle->cable

⌨️ 快捷键说明

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