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

📄 usbhost.c

📁 优龙pxa270平台试验程序
💻 C
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001, 2002 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:       USBHost.c
**
**  PURPOSE:        This file contained functions to test the functionality of
**					the USB Host.
**
**  LAST MODIFIED:  $Modtime: 7/17/03 1:01p $
******************************************************************************/

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

#include <stdio.h>
#include <string.h>
#include "systypes.h"
#include "timedelays.h"
#include "DM_Debug.h"
#include "DM_Errors.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
#include "XsUsbHostDrv.h"
#include "XsUsbHostAPI.h"
#include "UsbHost.h"
#include "xllp_udc.h"
#include "xsudc.h"
#include "USBClient.h"
#include "UsbCableInt.h"
#include "boardControl.h"

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

/*
*******************************************************************************
*
* FUNCTION:			PostUsbHostEnumerateTest
*
* DESCRIPTION:		This function enumerates the devices connected to the USB Host.
*
* INPUT PARAMETERS:	void * ctxP - a pointer to the USB Host context structure
*					PCHAR param - if one, loopback is enabled
*
* RETURNS:		    None.
*
* GLOBAL EFFECTS:	None.
*
* ASSUMPTIONS:		Usb device is attached to the port.
*
* CALLS:			XsUsbHostHWSetup, XsUsbHostInitialize 
*
* CALLED BY:		The menu system
*
* PROTOTYPE:		UINT PostUsbHostEnumerateTest (UsbHostContextT * ctxP, INT loopbackEnabled)
*
*******************************************************************************
*/
UINT PostUsbHostEnumerateTest (UsbHostContextT * ctxP, INT loopbackEnabled)
{
    UINT errorCount = 0;
    UINT udcTestStatus = ERR_L_NONE;
    UINT status = UsbdNoError;
    
	printf (" Testing USB Host and USB Client enumerate\r\n");

    PostDisplayProgress(ERR_L_USB, ERR_S_XSUSB_ENUMERATE, 1);

	// Init the USB host controller
    XsUsbHostHWSetup();

    PostDisplayProgress(ERR_L_USB, ERR_S_XSUSB_ENUMERATE, 2);

    // Start the USB Host test
  	status = XsUsbHostInitialize (ctxP->USBOHCIRegP, 
  	                     (UsbClientLoopbackT)PostUsbClientEnumerateTest,
  	                     loopbackEnabled,
  	                     &udcTestStatus);
    
    if (udcTestStatus != ERR_L_NONE)
    {
        PostDisplayProgress(ERR_L_USB, ERR_S_XSUSB_ENUMERATE, 3);
        ++errorCount;
    }
    else if (status != UsbdNoError)
    {
        status = ERRORCODEX(ERR_L_USB,
                        ERR_S_XSUSB_ENUMERATE,
                        1,
                        ERR_T_WRONG_STATE);
        XllpUtilityOutputError(status);
        ++errorCount;
    }
    else
    {
        PostDisplayProgress(ERR_L_USB, ERR_S_XSUSB_ENUMERATE, 4);

        // Test done
        printf (" Success!\r\n");
    }
    
    // Shutdown the USB Host controller
    XsUsbHostShutdown ();

    PostDisplayProgress(ERR_L_USB, ERR_S_XSUSB_ENUMERATE, 5);

	if (loopbackEnabled)
    {
        PostDisplayProgress(ERR_L_USB, ERR_S_XSUSB_ENUMERATE, 6);

	    // Unregister the USB client interrupt with the Lubbock interrupt controller
        UsbCableUnRegisterHandlers ();

        // Disable USB Client interrupt
        UsbCableDisableInt ();

        // Shutdown the USB Client
//        XsUdcHWShutdown ();
    }

    return errorCount;
}

/*
*******************************************************************************
*
* FUNCTION:			UsbHostEnumerateTest
*
* DESCRIPTION:		This function enumerates the devices connected to the USB Host.
*
* INPUT PARAMETERS:	void * ctxP - a pointer to the USB Host context structure
*					PCHAR param - if one, loopback is enabled
*
* RETURNS:		    None.
*
* GLOBAL EFFECTS:	None.
*
* ASSUMPTIONS:		Usb device is attached to the port.
*
* CALLS:			XsUsbHostHWSetup, XsUsbHostInitialize 
*
* CALLED BY:		The menu system
*
* PROTOTYPE:		void UsbHostEnumerateTest (void * ctxP, PCHAR param)
*
*******************************************************************************
*/
void UsbHostEnumerateTest (void * ctxp, PCHAR param)
{
	INT loopbackEnabled;
	UINT status = ERR_L_NONE;
	UsbHostContextT * ctxP = (UsbHostContextT*)ctxp;

    if (sscanf(param, "%d", &loopbackEnabled) != 1)
	{
		// Bad number of the parameters have been passed to the function
        status = ERRORCODEX(ERR_L_USB,
                        ERR_S_XSUSB_ENUMERATE,
                        2,
                        ERR_T_ILLPARAM);
        XllpUtilityOutputError(status);
        return;
	}

    PostUsbHostEnumerateTest (ctxP, loopbackEnabled);    
}

void UsbHostEnableDebugMode (void * ctxp, PCHAR param)
{
    INT enable;
    UINT status = ERR_L_NONE;
    
    if (sscanf(param, "%d", &enable) != 1)
	{
		// Bad number of the parameters have been passed to the function
        status = ERRORCODEX(ERR_L_USB,
                        ERR_S_XSUSB_ENUMERATE,
                        3,
                        ERR_T_ILLPARAM);
        XllpUtilityOutputError(status);
        return;
	}

    DM_ControlWordsDebugPrintPutBit(DM_CW_USB_HOST_0, enable);
}

void UsbHostDisplayStructures (void * arg, PCHAR param)
{
    XsUsbHostDisplayStructures(arg, param);
}

⌨️ 快捷键说明

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