📄 usrusbtool.c
字号:
/* usrUsbTool.c - USB Driver (USBD) and USB HCD Exerciser. */
/* Copyright 2000-2002 Wind River Systems, Inc. */
/*
Modification history
--------------------
01p,16mar02,wef fixed a bug w/ speaker operation.
01n,13dec01,wef merge from veloce view
01m,16sep00,wef changed all device component names to have _USB_ in them
01l,12apr00,wef reverted to older version of usrUsbTool.c
01k,07mar00,rcb Add casts to convert GENERIC_HANDLEs to UINT32 where necesary.
01j,29jan00,wef made usbTool in to a component configlette
01i,17jan00,rcb Add functions to test usbSpeakerLib.
01h,29nov99,rcb Increase frame number fields to 32-bits in
cmdGetCurrentFrame().
01g,23nov99,rcb Added "Attach" and "Detach" commands to control attach/detach
of UHCI or OHCI HCD modules. Removed automatic attachment
from "UsbInit" command.
01f,23nov99,rcb Change #include ../xxx references to lower case.
01e,12nov99,rcb Shorted path names...affects "#include" directives.
01d,07oct99,rcb Add code to test usbMouseLib.c.
01c,04oct99,rcb Add "dump" command.
01b,24sep99,rcb Add "print" function to dump files to printer.
01a,01jun99,rcb First.
*/
/*
DESCRIPTION
usbTool is a command line-driven program which allows the user to exercise
USB capabilities through the USB Driver (USBD) and USB HCD (Host Controller
Driver).
In the vxWorks environment, the user starts usbTool by invoking the "usbTool"
entry point from the vxWorks shell. usbTool then displays a prompt:
USB>
The user may now enter commands which will be parsed and executed by usbTool.
Each command follows the format:
USB>command [optional parameter(s)]
Commands are executed after the user presses [enter]. The user may enter
the "help" or "?" commands to see a list of currently supported commands.
Multiple commands may be entered on the same command line separated by
semicolons (';'). usbTool which execute each command as if it had been
entered on a separate line (unless a command terminates with an error, in
which case all remaining commands entered on the same line will be ignored).
The "quit"/"exit"/"bye" command terminates usbTool.
*/
/* Include files */
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "ioLib.h"
#include "ctype.h"
#include "usb/usbPlatform.h" /* Basic definitions */
#include "usb/tools/cmdParser.h" /* Command parser util funcs */
#include "usb/usbPciLib.h" /* PCI interface */
#include "usb/usbdLib.h" /* USBD interface */
/* Added by Ajay -start*/
#include "config.h"
#include "drv/multi/s3c2510.h"
#include "drv/intrCtl/s3c2510Intr.h"
/* Extra definitions used */
#define S3C2510_USB_HOST_BASE_ADDRESS 0xF0100000
#define INVALID_PCI_DEVICE_ID 0xFFFF
#define INVALID_PCI_VENDOR_ID 0xFFFF
#undef USB_HOST_DEBUG
/* Its not defined in config.h to remove compiler error while building bootrom */
#define INCLUDE_USB
/* Added by Ajay -end */
#ifdef INCLUDE_UHCI
#include "drv/usb/usbUhci.h" /* UHCI definitions */
#include "drv/usb/usbHcdUhciLib.h" /* UHCI HCD entry point, etc. */
#endif
#ifdef INCLUDE_OHCI
#include "drv/usb/usbOhci.h" /* OHCI definitions */
#include "drv/usb/usbHcdOhciLib.h" /* OHCI HCD entry point, etc. */
#endif
#include "usb/usbHid.h" /* USB HID definitions */
#ifdef INCLUDE_USB_KEYBOARD
#include "drv/usb/usbKeyboardLib.h" /* USB keyboard SIO driver */
#endif
#ifdef INCLUDE_USB_MOUSE
#include "drv/usb/usbMouseLib.h" /* USB mouse SIO driver */
#endif
#ifdef INCLUDE_USB_PRINTER
#include "usb/usbPrinter.h"
#include "drv/usb/usbPrinterLib.h" /* USB printer SIO driver */
#endif
#ifdef INCLUDE_USB_LOOPBACK
#include "usbLoopbackLib.h" /* USB loopback driver */
#endif
#ifdef INCLUDE_USB_SPEAKER
#include "usb/tools/wavFormat.h" /* Microsoft .wav file format */
#include "usb/usbAudio.h" /* USB audio definitions */
#include "drv/usb/usbSpeakerLib.h" /* USB speaker SEQ_DEV driver */
#endif
#ifdef INCLUDE_USB_TARG
#include "usb/target/usbTargLib.h" /* USB target library */
#include "drv/usb/target/usbPdiusbd12Eval.h" /* Philips target eval */
#include "drv/usb/target/usbTcdPdiusbd12EvalLib.h" /* Philips TCD */
#include "drv/usb/target/usbTargPhilipsD12EvalLib.h" /* Philips eval target */
#include "drv/usb/target/usbTargKbdLib.h" /* USB keyboard emulator */
#include "drv/usb/target/usbTargPrnLib.h" /* USB printer emulator */
#endif
/* defines */
#define PGM_NAME "usbTool"
#define PGM_DESCR "USB exerciser"
#define PGM_VERSION "01f"
#define PGM_COPYRIGHT "Copyright (c) 2002, Wind River Systems, Inc.\n"
/* Prompt definition */
#define PROMPT "usb>" /* Program prompt */
#define INDENT 2 /* indent used during bus enumerate */
/* misc defines */
#define INT_PIPE_SRVC_INTERVAL 20 /* milliseconds */
#define CTRL_Z 26 /* ASCI code for ^Z */
#define MAX_MFG_STR_LEN 30
#define MAX_PROD_STR_LEN 30
#define TX_BFR_SIZE 0x1000
#define AUDIO_BFR_SIZE 0x8000
#define GENERIC_USB_BFR 256
/* locals */
#ifdef INCLUDE_USB
LOCAL BOOL initialized = FALSE;
LOCAL USBD_CLIENT_HANDLE usbdClientHandle = NULL;
LOCAL GENERIC_HANDLE uhciAttachToken = NULL;
LOCAL GENERIC_HANDLE pciOhciAttachToken = NULL;
LOCAL GENERIC_HANDLE s3c2510OhciAttachToken = NULL;
LOCAL BOOL enterPressed;
LOCAL BOOL irpCallbackInvoked;
#endif
#ifdef INCLUDE_USB_PRINTER
LOCAL BOOL patternTest;
LOCAL UINT32 txCharCount; /* count of chars to "print" */
LOCAL UINT16 nextCharVal; /* next value for pattern test */
LOCAL FILE *txFile = NULL; /* file being "printed" */
LOCAL char txBfr [TX_BFR_SIZE]; /* Working buffer */
LOCAL UINT16 txBfrCount; /* count of chars in working bfr */
LOCAL UINT16 txBfrIndex; /* ptr to next char in bfr */
#endif
#ifdef INCLUDE_USB_TARG
LOCAL BOOL targInit = FALSE;
LOCAL USB_TARG_CHANNEL targChannel = NULL;
LOCAL UINT16 numEndpoints = 0;
LOCAL pUSB_TARG_ENDPOINT_INFO pEndpoints = NULL;
LOCAL BOOL targEnable = FALSE;
#endif /* #ifdef INCLUDE_USB_TARG */
#ifdef INCLUDE_USB
/*************************************************************************
*
* cmdUsbInit - Initialize USBD
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdUsbInit
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
UINT16 usbdVersion;
char usbdMfg [USBD_NAME_LEN+1];
UINT16 s;
/* if already initialized, just show a warning */
if (initialized)
{
fprintf (fout, "Already initialized.\n");
return RET_CONTINUE;
}
/* Initialize the USBD */
s = usbdInitialize ();
fprintf (fout, "usbdInitialize() returned %d\n", s);
if (s == OK)
{
/* Register ourselves with the USBD */
s = usbdClientRegister (PGM_NAME, &usbdClientHandle);
fprintf (fout, "usbdClientRegister() returned %d\n", s);
if (s == OK)
{
fprintf (fout, "usbdClientHandle = 0x%x\n", (UINT32) usbdClientHandle);
/* Display the USBD version */
if ((s = usbdVersionGet (&usbdVersion, usbdMfg)) != OK)
{
fprintf (fout, "usbdVersionGet() returned %d\n", s);
}
else
{
fprintf (fout, "USBD version = 0x%4.4x\n", usbdVersion);
fprintf (fout, "USBD mfg = '%s'\n", usbdMfg);
}
if (s == OK)
initialized = TRUE;
}
}
if (s != OK)
{
fprintf (fout, "initialization failed\n");
}
return RET_CONTINUE;
}
/*************************************************************************
*
* cmdUsbDown - Shut down USBD
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdUsbDown
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
UINT16 s;
initialized = FALSE;
uhciAttachToken = pciOhciAttachToken = s3c2510OhciAttachToken = NULL;
/* Unregister our client */
if (usbdClientHandle == NULL)
{
fprintf (fout, "usbdClientHandle == NULL. not registered\n");
}
else
{
s = usbdClientUnregister (usbdClientHandle);
usbdClientHandle = NULL;
fprintf (fout, "usbdClientUnregister() returned %d\n", s);
}
/* shut down USBD */
s = usbdShutdown ();
fprintf (fout, "usbdShutdown() returned %d\n", s);
return RET_CONTINUE;
}
/*************************************************************************
*
* getHcdType - Determines type of HCD specified by caller
*
* RETURNS: N/A
*/
LOCAL VOID getHcdType
(
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fout, /* stream for output (if any) */
HCD_EXEC_FUNC *execFunc, /* pointer to HCD exec func */
GENERIC_HANDLE **ppHandle, /* pointer to generic handle pointer */
pUINT8 pPciClass, /* pointer to pci class var */
pUINT8 pPciSubclass, /* pointer to pci subclass var */
pUINT8 pPciPgmIf, /* pointer to pci pgmif var */
char **ppHcdName /* pointer to name string var */
)
{
char hcdName [32];
/* Get HCD type */
*ppCmd = GetNextToken (*ppCmd, hcdName, sizeof (hcdName));
if (KeywordMatch (hcdName, "uhci", 4) == 0)
{
#ifdef INCLUDE_UHCI
*execFunc = usbHcdUhciExec;
*ppHandle = &uhciAttachToken;
*pPciClass = UHCI_CLASS;
*pPciSubclass = UHCI_SUBCLASS;
*pPciPgmIf = UHCI_PGMIF;
*ppHcdName = "UHCI";
#else
fprintf (fout, "UHCI Component Not Included.\n");
*execFunc = NULL;
#endif
}
else if (KeywordMatch (hcdName, "pciohci", 7) == 0)
{
#ifdef INCLUDE_OHCI
*execFunc = usbHcdOhciExec;
*ppHandle = &pciOhciAttachToken;
*pPciClass = OHCI_CLASS;
*pPciSubclass = OHCI_SUBCLASS;
*pPciPgmIf = OHCI_PGMIF;
*ppHcdName = "PCIOHCI";
#else
fprintf (fout, "OHCI Component Not Included.\n");
*execFunc = NULL;
#endif
}
else if (KeywordMatch (hcdName, "s3c2510ohci", 11) == 0)
{
#ifdef INCLUDE_OHCI
*execFunc = usbHcdOhciExec;
*ppHandle = &s3c2510OhciAttachToken;
*pPciClass =0xff;
*pPciSubclass = 0xff;
*pPciPgmIf = 0xff;
*ppHcdName = "S3C2510OHCI";
#else
fprintf (fout, "OHCI Component Not Included.\n");
*execFunc = NULL;
#endif
}
else
{
fprintf (fout, "Must specify HCD type as 'uhci', 'pciohci' or 's3c2510ohci'.\n");
*execFunc = NULL;
}
return;
}
/*************************************************************************
*
* cmdAttach - Attaches HCD to USBD
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdAttach
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
HCD_EXEC_FUNC execFunc;
GENERIC_HANDLE *pToken;
UINT8 pciClass;
UINT8 pciSubclass;
UINT8 pciPgmIf;
char *hcdName;
UINT8 busNo;
UINT8 deviceNo;
UINT8 funcNo;
PCI_CFG_HEADER pciCfgHdr;
UINT16 s;
#ifdef USB_HOST_DEBUG
UINT8 i=0;
#endif
getHcdType (ppCmd, fout, &execFunc, &pToken, &pciClass, &pciSubclass,
&pciPgmIf, &hcdName);
if (execFunc != NULL)
{
if (*pToken != NULL)
{
fprintf (fout, "%s already attached.\n", hcdName);
return RET_CONTINUE;
}
/* If attach was called for S3c2510 HCD */
if((pciClass==0xff)&&(pciSubclass==0xff)&&(pciPgmIf==0xff))
{
/* just to test */
/* printf ("Value of S3C2510_UPLLCON before setting %x \n", *S3C2510_UPLLCON ); */
/* printf ("Value of S3C2510_SYSCFG %x \n", *S3C2510_SYSCFG );*/
/* *S3C2510_SYSCFG = 0x00000100; */ /* as per linux*/
/* *S3C2510_HPRIR = 0x00000330; */
/* *S3C2510_SYSCFG = 0x30000102;*//* as per our BSP */
/* changing USB Clock */
/* *S3C2510_UPLLCON = 0x00010358;*/
/* test ends here */
/* PLEASE ENSURE THAT UPLL IS DEFINED AS 96 MHz IN config.h */
/* Enable the peripheral clock */
*S3C2510_PCLKDIS &= ~S3C2510_PCLKDIS_USBH;
#ifdef USB_HOST_DEBUG
printf ("Values starting at S3C2510_SYSCFG \n" );
for (i=0;i<11;i++)
{
printf ("Offset %d : %x\n",i,*REG_32(i*4));
}
#endif
/* Form the fake PCI header for S3C2510 OHCI host controller */
memset (&pciCfgHdr,0, sizeof(PCI_CFG_HEADER));
pciCfgHdr.vendorId = INVALID_PCI_VENDOR_ID;
pciCfgHdr.deviceId = INVALID_PCI_DEVICE_ID;
pciCfgHdr.baseReg [0] = S3C2510_USB_HOST_BASE_ADDRESS;/* 0xF0100000 */
pciCfgHdr.intLine = INT_LVL_USBH;/* 13 */
}
else
{
/* Find an instance of a USB host controller */
if (!usbPciClassFind (pciClass, pciSubclass, pciPgmIf, 0,
&busNo, &deviceNo, &funcNo))
{
fprintf (fout, "No %s host controller found.\n", hcdName);
return RET_CONTINUE;
}
usbPciConfigHeaderGet (busNo, deviceNo, funcNo, &pciCfgHdr);
}
/* Attach the UHCI HCD to the USBD. */
s = usbdHcdAttach (execFunc, &pciCfgHdr, pToken);
fprintf (fout, "usbdHcdAttach() returned %d\n", s);
if (s == OK)
{
fprintf (fout, "AttachToken = 0x%x\n", (UINT32) *pToken);
}
}
return RET_CONTINUE;
}
/*************************************************************************
*
* cmdDetach - Detaches HCD from USBD
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdDetach
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
HCD_EXEC_FUNC execFunc;
GENERIC_HANDLE *pToken;
UINT8 pciClass;
UINT8 pciSubclass;
UINT8 pciPgmIf;
char *hcdName;
UINT16 s;
getHcdType (ppCmd, fout, &execFunc, &pToken, &pciClass, &pciSubclass,
&pciPgmIf, &hcdName);
if (execFunc != NULL)
{
/* Detach the HCD */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -