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

📄 usrusbtool.c

📁 VxWorks BSP for S3C2510A
💻 C
📖 第 1 页 / 共 5 页
字号:
	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);
	return;
	}

    if (pDevDescr->manufacturerIndex != 0 || pDevDescr->productIndex != 0)
	fprintf (fout, " = ");

    if (pDevDescr->manufacturerIndex != 0)
	{
	showUsbString (clientHandle, nodeId, fout, pDevDescr->manufacturerIndex,
	    MAX_MFG_STR_LEN);
	fprintf (fout, "/");
	}

    if (pDevDescr->productIndex != 0)
	{
	showUsbString (clientHandle, nodeId, fout, pDevDescr->productIndex,
	    MAX_PROD_STR_LEN);
	}
    }


/***************************************************************************
*
* HubEnumerate - Enumerate all ports on the specified hub
* 
* This routine enumerates all devices from the specified HubId down.
* <clientHandle> must be a valid USBD_CLIENT_HANDLE.  <hubId> specifies
* the Node Id of the first USB hub to be enumerated.
*
* RETURNS: OK, or ERROR if USBD returns an error.
*/

LOCAL UINT16 HubEnumerate
    (
    USBD_CLIENT_HANDLE clientHandle,	/* Caller抯 USBD client handle */
    USBD_NODE_ID hubId, 		/* Node Id for hub to enumerate */
    FILE *fout,
    UINT16 indent
    )

    {
    UINT16 portCount;			/* Number of ports on this hub */
    UINT16 portIndex;			/* current port index */
    UINT16 nodeType;			/* type of node being enumerated */
    USBD_NODE_ID nodeId;		/* id of node being enumerated */
    UINT16 s;

    /* Retrieve the number of ports for this hub. */

    fprintf (fout, "%*shub 0x%x", indent, "", (UINT32) hubId);
    showMfgModel (clientHandle, hubId, fout);
    fprintf (fout, "\n");

    if ((s = usbdHubPortCountGet (clientHandle, hubId, &portCount)) 
	!= OK)
	{
	fprintf (fout, "usbdHubPortCountGet() returned %d\n", s);
	return ERROR;
	}

    fprintf (fout, "%*sport count = %d\n", indent+INDENT, "", portCount);

    /* See if a device is attached to each of the hub抯 ports. */

    for (portIndex = 0; portIndex < portCount; portIndex++) 
	{
	if ((s = usbdNodeIdGet (clientHandle, hubId, portIndex, &nodeType, 
	    &nodeId)) != OK)
	    {
	    fprintf (fout, "%*susbdNodeIdGet() returned %d\n", indent+INDENT, "", 
		s);
	    return ERROR;
	    }

	switch (nodeType)
	    {
	    case USB_NODETYPE_NONE:	/* No device attached. */

		fprintf (fout, "%*sport %d not connected\n", indent+INDENT, "", 
		    portIndex);
		break;

	    case USB_NODETYPE_HUB:	/* Another hub found. */

		fprintf (fout, "%*sport %d is hub 0x%x\n", indent+INDENT, "",
		    portIndex, (UINT32) nodeId);

		if (HubEnumerate (clientHandle, nodeId, fout, indent+INDENT) 
		    != OK)
		    return ERROR;

		break;

	    case USB_NODETYPE_DEVICE:	/* Device attached to port. */

		fprintf (fout, "%*sport %d is device 0x%x", indent+INDENT, "",
		    portIndex, (UINT32) nodeId);

		showMfgModel (clientHandle, nodeId, fout);
		fprintf (fout, "\n");

		break;

	    default:			/* Unknown node type code */

		fprintf (fout, "%*snode type not recognized for node 0x%x\n",
		    indent+INDENT, "", (UINT32) nodeId);
		break;
	    }
	}

    return OK;
    }


/***************************************************************************
*
* USBEnumerate - Enumerate all USB host controllers in the system.
* 
* This routine enumerates all USB host controllers, hubs, and devices
* currently connected to the system.  The caller must register with the
* USBD prior to calling this function and supply its USBD_CLIENT_HANDLE
* in <clientHandle>.
*
* RETURNS: OK, or ERROR if USBD returns an error.
*/

LOCAL UINT16 USBEnumerate
    (
    USBD_CLIENT_HANDLE clientHandle,	/* Caller抯 USBD client handle */
    FILE *fout
    )

    {
    UINT16 busCount;			/* Number of USB host controllers */
    UINT16 busIndex;			/* current bus index */
    USBD_NODE_ID rootId;		/* Root hub id for current bus */
    UINT16 s;


    /* Retrieve the number of USB host controllers in the system. */

    if ((s = usbdBusCountGet (clientHandle, &busCount)) != OK)
	{
	fprintf (fout, "usbdBusCountGet() returned %d\n", s);
	return ERROR;
	}

    fprintf (fout, "bus count = %d\n", busCount);

    /* Retrieve the root hub id for each host controller and enumerate it. */

    for (busIndex = 0; busIndex < busCount; busIndex++) 
	{
	if ((s = usbdRootNodeIdGet (clientHandle, busIndex, &rootId))
	    != OK)
	    {
	    fprintf (fout, "usbdRootNodeIdGet() returned %d\n", s);
	    return ERROR;
	    }

	fprintf (fout, "enumerating bus %d\n", busIndex);
	
	if (HubEnumerate (clientHandle, rootId, fout, INDENT) != OK)
	    return ERROR;
	}

    return OK;
    }


/*************************************************************************
*
* cmdUsbEnum - Enumerate USBs attached to system
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdUsbEnum
    (
    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) */
    )

    {
    USBEnumerate (usbdClientHandle, fout);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdUsbStats - Show bus statistics
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdUsbStats
    (
    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) */
    )

    {
    long nodeId;
    USBD_STATS stats;
    UINT16 s;

    /* Extract parameters. */

    *ppCmd = GetHexToken (*ppCmd, &nodeId, -1);


    /* Validate parameters */

    if (nodeId == -1)
	{
	fprintf (fout, "Must specify a node id.\n");
	return RET_CONTINUE;
	}


    /* Execute function. */

    if ((s = usbdStatisticsGet (usbdClientHandle, (GENERIC_HANDLE) nodeId, &stats, sizeof (stats)))
	!= OK)
	fprintf (fout, "usbdStatisticsGet() returned %d\n", s);
    else
	{
	fprintf (fout, "totalTransfersIn    = %ld\n", (long) stats.totalTransfersIn);
	fprintf (fout, "totalTransfersout   = %ld\n", (long) stats.totalTransfersOut);
	fprintf (fout, "totalReceiveErrors  = %ld\n", (long) stats.totalReceiveErrors);
	fprintf (fout, "totalTransmitErrors = %ld\n", (long) stats.totalTransmitErrors);
	}

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdGetConfig - get current configuration value for a device
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdGetConfig
    (
    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) */
    )

    {
    long nodeId;
    UINT16 * pConfiguration;
    UINT16 s;

    /* Extract parameters. */

    *ppCmd = GetHexToken (*ppCmd, &nodeId, -1);


    /* Validate parameters */

    if (nodeId == -1)
	{
	fprintf (fout, "Must specify a node id.\n");
	return RET_CONTINUE;
	}

    if ((pConfiguration = OSS_MALLOC (sizeof (UINT16))) == NULL)
	return RET_CONTINUE;

    /* Execute function. */

    if ((s = usbdConfigurationGet (usbdClientHandle, 
				   (GENERIC_HANDLE) nodeId, 
				   pConfiguration))
			    != OK)
	fprintf (fout, "usbdConfigurationGet() returned %d\n", s);
    else
	fprintf (fout, "current configuration = 0x%x\n", *pConfiguration);

    OSS_FREE (pConfiguration);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdSetConfig - set current configuration value for a device
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdSetConfig
    (
    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) */
    )

    {
    long nodeId;
    long configuration;
    UINT16 s;

    /* Extract parameters. */

    *ppCmd = GetHexToken (*ppCmd, &nodeId, -1);
    *ppCmd = GetHexToken (*ppCmd, &configuration, -1);


    /* Validate parameters */

    if (nodeId == -1 || configuration == -1)
	{
	fprintf (fout, "Must specify a node id and configuration value.\n");
	return RET_CONTINUE;
	}


    /* Execute function. */

    s = usbdConfigurationSet (usbdClientHandle, (GENERIC_HANDLE) nodeId, (UINT16) configuration, 0);
    fprintf (fout, "usbdConfigurationSet() returned %d\n", s);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdGetInterface - get alt. setting for an interface
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdGetInterface
    (
    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) */
    )

    {
    long nodeId;
    long index;
    UINT16 * pAltSetting;
    UINT16 s;

    /* Extract parameters. */

    *ppCmd = GetHexToken (*ppCmd, &nodeId, -1);
    *ppCmd = GetHexToken (*ppCmd, &index, -1);


    /* Validate parameters */

    if (nodeId == -1 || index == -1)
	{
	fprintf (fout, "Must specify a node id and interface number.\n");
	return RET_CONTINUE;
	}

    if ((pAltSetting = OSS_MALLOC (sizeof (UINT16))) == NULL)
        return RET_CONTINUE;


    /* Execute function. */

    if ((s = usbdInterfaceGet (usbdClientHandle, 
			       (GENERIC_HANDLE) nodeId, 
			       index, 
			       pAltSetting))
	!= OK)
	fprintf (fout, "usbdInterfaceGet() returned %d\n", s);
    else
	fprintf (fout, "alternate setting = 0x%x\n", *pAltSetting);

    OSS_FREE (pAltSetting);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdSetInterface - set alt. setting for an interface
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdSetInterface
    (
    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) */
    )

    {
    long nodeId;
    long index;
    long altSetting;
    UINT16 s;

    /* Extract parameters. */

    *ppCmd = GetHexToken (*ppCmd, &nodeId, -1);
    *ppCmd = GetHexToken (*ppCmd, &index, -1);
    *ppCmd = GetHexToken (*ppCmd, &altSetting, -1);


    /* Validate parameters */

    if (nodeId == -1 || index == -1 || altSetting == -1)
	{
	fprintf (fout, "Must specify a node id, interface number, and alt. setting.\n");
	return RET_CONTINUE;
	}


    /* Execute function. */

    s = usbdInterfaceSet (usbdClientHandle, (GENERIC_HANDLE) nodeId, index, altSetting);
    fprintf (fout, "usbdInterfaceSet() returned %d\n", s);

    return RET_CONTINUE;
    }
#endif	/* INCLUDE_USB from way above*/

⌨️ 快捷键说明

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