📄 usrusbtool.c
字号:
/* usrUsbTool.c - USB Driver (USBD) and USB HCD Exerciser. */
/* Copyright 2000 Wind River Systems, Inc. */
/*
Modification history
--------------------
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 */
/* #define INCLUDE_DOSFS2 */
#ifdef INCLUDE_USB_PCI
#include "usb/usbPciLib.h" /* PCI interface */
#endif
#include "usb/usbdLib.h" /* USBD interface */
#include "config.h"
#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
#ifdef INCLUDE_SL811H
#include "usbSl811hs.h"
#include "usbHcdSl811hsLib.h"
#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_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_MS_BULKONLY
#include "iosLib.h"
#include "dosFsLib.h"
#include "usb/usbdLib.h"
#include "usb/usbQueueLib.h"
#include "drv/usb/usbBulkDevLib.h"
#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 "01e"
#define PGM_COPYRIGHT "Copyright (c) 2001, 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 40
#define MAX_PROD_STR_LEN 40
#define TX_BFR_SIZE 0x1000
#define AUDIO_BFR_SIZE 0x8000
/* locals */
#ifdef INCLUDE_USB
LOCAL BOOL initialized = FALSE;
LOCAL USBD_CLIENT_HANDLE usbdClientHandle = NULL;
LOCAL GENERIC_HANDLE uhciAttachToken = NULL;
LOCAL GENERIC_HANDLE ohciAttachToken = NULL;
LOCAL GENERIC_HANDLE sl811hAttachToken = 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 = ohciAttachToken = sl811hAttachToken = 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, "ohci", 4) == 0)
{
#ifdef INCLUDE_OHCI
*execFunc = usbHcdOhciExec;
*ppHandle = &ohciAttachToken;
*pPciClass = OHCI_CLASS;
*pPciSubclass = OHCI_SUBCLASS;
*pPciPgmIf = OHCI_PGMIF;
*ppHcdName = "OHCI";
#else
fprintf (fout, "OHCI Component Not Included.\n");
*execFunc = NULL;
#endif
}
else if (KeywordMatch (hcdName, "sl811h", 6) == 0)
{
#ifdef INCLUDE_SL811H
*execFunc = usbHcdSl811hExec;
*ppHandle = &sl811hAttachToken;
*pPciClass = 0;
*pPciSubclass = 0;
*pPciPgmIf = 0;
*ppHcdName = "SL811H";
#else
fprintf (fout, "SL811H Component Not Included.\n");
*execFunc = NULL;
#endif
}
else
{
fprintf (fout, "Must specify HCD type as 'uhci' or 'ohci' or 'sl811h'.\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;
#ifdef INCLUDE_USB_PCI
UINT8 busNo;
UINT8 deviceNo;
UINT8 funcNo;
PCI_CFG_HEADER pciCfgHdr;
#endif
UINT16 s;
#ifdef INCLUDE_SL811H
SL811_IO_CFG sl811IOCfg = {SL811H_IO_ADDR, SL811H_IO_ADDR_DATA, SL811H_INT_VEC, SL811H_INT_LVL};
#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 (strcmp(hcdName, "SL811H") == 0)
{
s = usbdHcdAttach (execFunc, &sl811IOCfg, pToken);
}
else
{
#ifdef INCLUDE_USB_PCI
/* 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);
#else
fprintf (fout, "Not implemented.\n");
return RET_CONTINUE;
#endif
}
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 */
if (*pToken == NULL)
{
fprintf (fout, "%s not attached.\n", hcdName);
}
else
{
fprintf (fout, "Detaching %s HCD.\n", hcdName);
s = usbdHcdDetach (*pToken);
*pToken = NULL;
fprintf (fout, "usbdHcdDetach() returned %d\n", s);
}
}
return RET_CONTINUE;
}
/***************************************************************************
*
* showUsbString - reads a string descriptor and displays it
*
* RETURNS: N/A
*/
LOCAL VOID showUsbString
(
USBD_CLIENT_HANDLE clientHandle,
USBD_NODE_ID nodeId,
FILE *fout,
UINT8 stringId,
UINT16 maxLen
)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -