📄 usbclient.c
字号:
/******************************************************************************
**
** 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: USBClient.c
**
** PURPOSE: This file contained functions to test the functionality of
** the USB Client.
**
** LAST MODIFIED: $Modtime: 7/17/03 1:01p $
******************************************************************************/
/*
*******************************************************************************
* HEADER FILES
*******************************************************************************
*/
#include <string.h>
#include <stdio.h>
#include "systypes.h"
#include "xllp_defs.h"
#include "DM_Debug.h"
#include "XsIntCtrlApi.h"
#include "xllp_udc.h"
#include "xsudc.h"
#include "USBClient.h"
#include "UsbCableInt.h"
#include "XsDmaApi.h"
#include "serialCommon.h"
#include "timedelays.h"
#include "boardControl.h"
#include "DM_Errors.h"
#include "mallocx.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
/*
*******************************************************************************
* LOCAL CONSTANTS
*******************************************************************************
*/
/*
*******************************************************************************
*
* FUNCTION: UsbConfigClientTest
*
* DESCRIPTION: This function sets the client configuration in according to the selection
* made in the Usb Client Configuration menu.
* It selects DMA or Megacell to service Endpoint's FIFOs for BULK and ISO.
* The SOF interrupt can be selected to service ISO transfer.
*
* INPUT PARAMETERS: PVOID ctxP - a pointer to the USB Client context structure
* PCHAR param - is used to configure the USB Client
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS:
*
* CALLED BY: The menu system
*
* PROTOTYPE: void UsbConfigClientTest (PVOID ctxP, PCHAR param)
*
*******************************************************************************
*/
void UsbConfigClientTest (PVOID ctxp, PCHAR param)
{
P_XLLP_UDC_T ctxP = (P_XLLP_UDC_T)ctxp;
INT tempParam;
// Process input param. to set client configuration
sscanf(param, "%d", &tempParam);
if (tempParam == 0)
{
// Megasell is used to service Endpoint's FIFOs for BULK and ISO
ctxP->enableDma = FALSE;
// ctxP->enableSOF = FALSE;
printf (" USB Client interrupts enabled\r\n");
}
else if (tempParam == 1)
{
// DMA is used to service Endpoint's FIFOs for BULK and ISO
ctxP->enableDma = TRUE;
// ctxP->enableSOF = FALSE;
printf (" USB Client DMA enabled\r\n");
}
else if (tempParam == 2)
{
// The SOF interrupt can be selected to service ISO transfer
// ctxP->enableSOF = TRUE;
ctxP->enableDma = FALSE;
printf (" USB Client SOF interrupt enabled with ISO\r\n");
}
DM_WaitMs(1000);
}
VOID UsbCableAttachedInterruptHandler (PVOID param); //hzh
UINT PostUsbClientEnumerateTest (P_XLLP_UDC_T ctxP, UINT loopbackEnabled)
{
UINT status;
UINT errorCount = 0;
if (loopbackEnabled)
{
PostDisplayProgress(ERR_L_XSUDC, ERR_S_XSUDC_STARTCLIENT, 1);
// Register the USB Client cable attach/disconnect interrupts
UsbCableRegisterHandlers ();
// Enable USB Client interrupt
UsbCableEnableInt ();
DM_WaitMs(100);
// Wait for the cable attachment
// The UDC HW setup function will be called on the cable detection
if (IsDevicePresent(USB_CBL))
{
UsbCableAttachedInterruptHandler(NULL); //hzh
PostDisplayProgress(ERR_L_XSUDC, ERR_S_XSUDC_STARTCLIENT, 2);
// Force board interrupt controller to generate GPIO[0] interrupt
// on the USB Cable insertion.
if (ctxP->cableAttached == FALSE)
{
ModifyBoardInterruptSetRegister(Int_Set_Register, INT_USBC);
DM_WaitMs(10);
}
}
else
{
PostDisplayProgress(ERR_L_XSUDC, ERR_S_XSUDC_STARTCLIENT, 3);
printf (" User! Please insert USB cable\r\n");
GetUserResponse(YES);
}
if (ctxP->cableAttached == FALSE)
{
// Usb Cable was not detected
status = ERRORCODEX(ERR_L_XSUDC,
ERR_S_XSUDC_CABLE,
1,
ERR_T_NODEVICE);
XllpUtilityOutputError(status);
// Unregister the USB client interrupt with the board interrupt controller
UsbCableUnRegisterHandlers ();
// Disable USB Client interrupt
UsbCableDisableInt ();
// Shutdown the USB Client
XsUdcHWShutdown ();
return (++errorCount);
}
if (ctxP->setupComplete == FALSE)
{
// USB Client setup fail
status = ERRORCODEX(ERR_L_XSUDC,
ERR_S_XSUDC_STARTCLIENT,
2,
ERR_T_NODEVICE);
XllpUtilityOutputError(status);
// Unregister the USB client interrupt with the board interrupt controller
UsbCableUnRegisterHandlers ();
// Disable USB Client interrupt
UsbCableDisableInt ();
// Shutdown the USB Client
XsUdcHWShutdown ();
return (++errorCount);
}
PostDisplayProgress(ERR_L_XSUDC, ERR_S_XSUDC_STARTCLIENT, 7);
}
else
{
PostDisplayProgress(ERR_L_XSUDC, ERR_S_XSUDC_STARTCLIENT, 4);
// Display start test in DMA or interrupt
if (ctxP->enableDma == 0)
printf (" Testing USB Client\r\n");
else
printf (" Testing USB Client with DMA\r\n");
// Call the UDC HW setup function before inserting the cable
status = XsUdcHWSetup();
if (!status)
ctxP->setupComplete = TRUE;
PostDisplayProgress(ERR_L_XSUDC, ERR_S_XSUDC_STARTCLIENT, 5);
printf (" User! Please start USB Host Application and insert USB Function cable\r\n");
GetUserResponse(YES);
// Wait for the cable attachment
if (IsDevicePresent(USB_CBL))
{
ctxP->cableAttached = TRUE;
printf (" User! Please click on 'Set Configuration' button\r\n");
printf (" User! Please click on 'No' button for full speed device\r\n");
printf (" User! Please click on 'OK' button to enter configuration value\r\n");
printf (" User! Please click on 'OK' button to exit\r\n");
GetUserResponse(YES);
}
else
{
ctxP->cableAttached = FALSE;
}
if (ctxP->cableAttached == FALSE)
{
// Usb Cable was not detected
status = ERRORCODEX(ERR_L_XSUDC,
ERR_S_XSUDC_CABLE,
3,
ERR_T_NODEVICE);
XllpUtilityOutputError(status);
XsUdcHWShutdown ();
return (++errorCount);
}
if (ctxP->setupComplete == FALSE)
{
// USB Client setup fail
status = ERRORCODEX(ERR_L_XSUDC,
ERR_S_XSUDC_STARTCLIENT,
4,
ERR_T_NODEVICE);
XllpUtilityOutputError(status);
XsUdcHWShutdown ();
return (++errorCount);
}
if (ctxP->enumerateComplete == FALSE)
{
// USB Client enumeration fail
status = ERRORCODEX(ERR_L_XSUDC,
ERR_S_XSUDC_ENUMERATE,
5,
ERR_T_NODEVICE);
XllpUtilityOutputError(status);
XsUdcHWShutdown ();
return (++errorCount);
}
PostDisplayProgress(ERR_L_XSUDC, ERR_S_XSUDC_STARTCLIENT, 6);
// Test done
printf (" Success!\r\n");
// Shutdown the USB Client
XsUdcHWShutdown ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -