?? usrusbtool.c
字號(hào):
/* 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 view01m,16sep00,wef changed all device component names to have _USB_ in them01l,12apr00,wef reverted to older version of usrUsbTool.c01k,07mar00,rcb Add casts to convert GENERIC_HANDLEs to UINT32 where necesary.01j,29jan00,wef made usbTool in to a component configlette01i,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.*//*DESCRIPTIONusbTool is a command line-driven program which allows the user to exerciseUSB capabilities through the USB Driver (USBD) and USB HCD (Host ControllerDriver). 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 */#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_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_USBLOCAL BOOL initialized = FALSE;LOCAL USBD_CLIENT_HANDLE usbdClientHandle = NULL;LOCAL GENERIC_HANDLE uhciAttachToken = NULL;LOCAL GENERIC_HANDLE ohciAttachToken = NULL;LOCAL BOOL enterPressed;LOCAL BOOL irpCallbackInvoked;#endif#ifdef INCLUDE_USB_PRINTERLOCAL 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_TARGLOCAL 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 = 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 { fprintf (fout, "Must specify HCD type as 'uhci' or 'ohci'.\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; 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; } /* 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 */ 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 ) { USB_STRING_DESCR * pString; UINT16 actLen; UINT16 i; char c; if ((pString = OSS_MALLOC (USB_MAX_DESCR_LEN)) == NULL) return; /* Read device descriptor to get string Ids for mfg/model */ if (usbdDescriptorGet (clientHandle, nodeId, USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_STRING, stringId, 0x0409, /* unicode code for English */ USB_MAX_DESCR_LEN, (UINT8 *) pString, &actLen) != OK) { fprintf (fout, "<<can't read string>>"); OSS_FREE (pString); return; } for (i = 0; i + 2 < actLen && i < maxLen * 2; i += 2) { c = pString->string [i]; fprintf (fout, "%c", (isprint ((int) c)) ? c : '_'); } if (i + 2 < actLen) fprintf (fout, "..."); OSS_FREE (pString); }/***************************************************************************** showMfgModel - Display mfg/model strings for a USB device** RETURNS: N/A*/LOCAL VOID showMfgModel ( USBD_CLIENT_HANDLE clientHandle, USBD_NODE_ID nodeId, FILE *fout ) { USB_DEVICE_DESCR * pDevDescr; UINT16 actLen; if((pDevDescr = OSS_MALLOC (USB_DEVICE_DESCR_LEN)) == NULL) return; /* Read device descriptor to get string Ids for mfg/model */ if (usbdDescriptorGet (clientHandle, nodeId, USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_DEVICE, 0, 0, USB_DEVICE_DESCR_LEN, (UINT8 *) pDevDescr, &actLen) != OK || actLen < USB_DEVICE_DESCR_LEN) { OSS_FREE (pDevDescr);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -