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

📄 usrusbtool.c

📁 VxWorks BSP for S3C2510A
💻 C
📖 第 1 页 / 共 5 页
字号:


/*************************************************************************
*
* displayMem - dumps memory to display
*
* RETURNS:  N/A
*/

LOCAL VOID displayMem
    (
    UINT16 bfrLen,
    pUINT8 pBfr,
    FILE *fout
    )

    {
    int i,j;

    for (i = 0; i < bfrLen; i += 16)
	{
	for (j = i; j < bfrLen && j < i+16; j++)
	    {
	    fprintf (fout, "%2.2x ", pBfr [j]);
	    if (j % 16 == 7)
		fprintf (fout, " ");
	    }
	fprintf (fout, " ");
	for (j = i; j < bfrLen && j < i+16; j++)
	    {
	    fprintf (fout, "%c", (pBfr [j] >= 32 && pBfr [j] <= 127) ? 
		pBfr [j] : '.');
	    }
	fprintf (fout, "\n");
	}
    }

#ifdef INCLUDE_USB

/*************************************************************************
*
* cmdGetStatus - get status for a device/interface/endpoint
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdGetStatus
    (
    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 statusType;
    long index;
    long length;
    UINT8 * pStatusBfr;
    UINT16 actLen;
    UINT16 s;

    /* Extract parameters. */

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


    /* Validate parameters */

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

    if (length > GENERIC_USB_BFR)
	{
	fprintf (fout, "length must be 0x%x or less.\n", 
	    (unsigned int) GENERIC_USB_BFR);
	return RET_CONTINUE;
	}

    if ((pStatusBfr = OSS_MALLOC (GENERIC_USB_BFR)) == NULL)
        return RET_CONTINUE;


    /* Execute function. */

    if ((s = usbdStatusGet (usbdClientHandle, 
			    (GENERIC_HANDLE) nodeId, 
			    statusType, 
			    index, 
			    length, 
			    pStatusBfr, 
			    &actLen)) != OK)
	fprintf (fout, "usbdStatusGet() returned %d\n", s);
    else
	{
	fprintf (fout, "actLen = 0x%x (%d) bytes\n", actLen, actLen);
	displayMem (actLen, pStatusBfr, fout);
	}

    OSS_FREE (pStatusBfr);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdGetAddress - get USB address for a node
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdGetAddress
    (
    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 address;
    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 = usbdAddressGet (usbdClientHandle, (GENERIC_HANDLE) nodeId, &address))
	!= OK)
	fprintf (fout, "usbdAddressGet() returned %d\n", s);
    else
	fprintf (fout, "current address = 0x%x\n", address);


    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdSetAddress - set USB address for a node
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdSetAddress
    (
    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 address;
    UINT16 s;

    /* Extract parameters. */

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


    /* Validate parameters */

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


    /* Execute function. */

    s = usbdAddressSet (usbdClientHandle, (GENERIC_HANDLE) nodeId, (UINT16) address);
    fprintf (fout, "usbdAddressnSet() returned %d\n", s);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdSetFeature - set a USB feature
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdSetFeature
    (
    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 featureType;
    long feature;
    long index;
    UINT16 s;

    /* Extract parameters. */

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


    /* Validate parameters */

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


    /* Execute function. */

    s = usbdFeatureSet (usbdClientHandle, (GENERIC_HANDLE) nodeId, featureType, feature, index);
    fprintf (fout, "usbdFeatureSet() returned %d\n", s);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdClrFeature - clear a USB feature
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdClrFeature
    (
    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 featureType;
    long feature;
    long index;
    UINT16 s;

    /* Extract parameters. */

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


    /* Validate parameters */

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


    /* Execute function. */

    s = usbdFeatureClear (usbdClientHandle, (GENERIC_HANDLE) nodeId, featureType, feature, index);
    fprintf (fout, "usbdFeatureClear() returned %d\n", s);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdGetDescr - retrieve a USB descriptor
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdGetDescr
    (
    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 requestType;
    long descriptorType;
    long index;
    long languageId;
    long length;
    UINT8 * pDescrBuf;
    UINT16 actLen;
    UINT16 s;

    /* Extract parameters. */

    *ppCmd = GetHexToken (*ppCmd, &nodeId, -1);
    *ppCmd = GetHexToken (*ppCmd, &requestType, -1);
    *ppCmd = GetHexToken (*ppCmd, &descriptorType, -1);
    *ppCmd = GetHexToken (*ppCmd, &index, -1);
    *ppCmd = GetHexToken (*ppCmd, &languageId, -1);
    *ppCmd = GetHexToken (*ppCmd, &length, -1);


    /* Validate parameters */

    if (nodeId == -1 || requestType == -1 || descriptorType == -1 || index == -1 
	|| languageId == -1 || length == -1)
	{
	fprintf (fout, "Must specify a node id,request type, descr. type, index, language, and length.\n");
	return RET_CONTINUE;
	}

    if (length > GENERIC_USB_BFR)
	{
	fprintf (fout, "length must be 0x%x or less.\n", 
	    (unsigned int) GENERIC_USB_BFR);
	return RET_CONTINUE;
	}

    if ((pDescrBuf = OSS_MALLOC (GENERIC_USB_BFR)) == NULL)
        return RET_CONTINUE;

    /* Execute function. */

    s = usbdDescriptorGet (usbdClientHandle, 
			   (GENERIC_HANDLE) nodeId, 
			   requestType, 
			   descriptorType, 
			   index, 
			   languageId, 
			   length, 
			   pDescrBuf, 
			   &actLen);

    if (s != OK)
	fprintf (fout, "usbdDescriptorGet() returned %d\n", s);
    else
	{
	fprintf (fout, "actLen = 0x%x (%d) bytes\n", actLen, actLen);
	displayMem (actLen, pDescrBuf, fout);
	}

    OSS_FREE (pDescrBuf);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdGetSynchFrame - retrieve current synch frame from a device endpoint
*
* RETURNS:  RET_CONTINUE;
*/

LOCAL UINT16 cmdGetSynchFrame
    (
    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 endpoint;
    UINT16 * pSynchFrame;
    UINT16 s;

    /* Extract parameters. */

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


    /* Validate parameters */

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

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

    /* Execute function. */

    if ((s = usbdSynchFrameGet (usbdClientHandle, 
				(GENERIC_HANDLE) nodeId, 
				endpoint, 
				pSynchFrame)) 
			!= OK)
	fprintf (fout, "usbdSynchFrameGet() returned %d\n", s);
    else
	fprintf (fout, "synch frame = 0x%4.4x\n", FROM_LITTLEW (*pSynchFrame));

    OSS_FREE (pSynchFrame);

    return RET_CONTINUE;
    }


/*************************************************************************
*
* cmdGetCurrentFrame - retrieve current frame for a USB
*
* RETURNS:  RET_CONTINUE
*/

LOCAL UINT16 cmdGetCurrentFrame
    (
    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;
    UINT32 frameNo;
    UINT32 frameWindow;
    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 = usbdCurrentFrameGet (usbdClientHandle, (GENERIC_HANDLE) nodeId, 
	&frameNo, &frameWindow)) != OK)
	fprintf (fout, "usbdCurrentFrameGet() returned %d\n", s);
    else
	{
	fprintf (fout, "frame number = %ld\n", (long) frameNo);
	fprintf (fout, "frame window = %ld\n", (long) frameWindow);
	}

    return RET_CONTINUE;
    }


/*************************************************************************
*
* enterThread - waits for user to press [enter]
*
* RETURNS:  N/A
*/

LOCAL VOID enterThread
    (
    pVOID param
    )

    {
    FILE *fout = (FILE *) param;
    char bfr [256];

    fprintf (fout, "Press [enter] to terminate polling.\n");
    gets (bfr);
    enterPressed = TRUE;
    }


/*************************************************************************
*
* irpCallback - called when IRP completes
*
* RETURNS:  N/A
*/

LOCAL VOID irpCallback
    (
    pVOID pIrp
    )

    {
    irpCallbackInvoked = TRUE;
    }


/*************************************************************************
*
* cmdIntPoll - polls interrupt endpoint for input
*
* Continuously reads IN packets from interrupt endpoint until key 
* pressed.
*
* RETURNS:  RET_CONTINUE
*/

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

    {
    THREAD_HANDLE thread;
    long nodeId;
    long endpoint;
    long length;
    USBD_PIPE_HANDLE handle;
    char bfr [256];
    USB_IRP irp;
    UINT16 s;

    /* Extract parameters. */

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

⌨️ 快捷键说明

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