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

📄 usrusbtool.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	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, 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);    *ppCmd = GetHexToken (*ppCmd, &endpoint, -1);    *ppCmd = GetHexToken (*ppCmd, &length, USB_MIN_CTRL_PACKET_SIZE);    /* Validate parameters */    if (nodeId == -1 || endpoint == -1)	{	fprintf (fout, "Must specify a node id and endpoint.\n");	return RET_CONTINUE;	}    if (length > sizeof (bfr))	{	fprintf (fout, "Length must be %d or less.\n", (int) sizeof (bfr));	return RET_CONTINUE;	}    /* Create a pipe to talk to this endpoint */    if ((s = usbdPipeCreate (usbdClientHandle, (GENERIC_HANDLE) nodeId, (UINT16) endpoint, 0, 0,	USB_XFRTYPE_INTERRUPT, USB_DIR_IN, length, length, INT_PIPE_SRVC_INTERVAL,	&handle)) != OK)	{	fprintf (fout, "usbdPipeCreate() returned %d\n", s);	return RET_CONTINUE;	}    /* Create thread to watch for keypress */    enterPressed = FALSE;    if (OSS_THREAD_CREATE (enterThread, (pVOID) fout, OSS_PRIORITY_INHERIT, "tEnter",	&thread) != OK)	goto pipe_done;    while (!enterPressed)	{	/* initialize IRP */	memset (&irp, 0, sizeof (irp));	irp.irpLen = sizeof (irp);	irp.userCallback = irpCallback;	irp.transferLen = length;	irp.bfrCount = 1;	irp.bfrList [0].pid = USB_PID_IN;	irp.bfrList [0].pBfr = bfr;	irp.bfrList [0].bfrLen = length;    	irpCallbackInvoked = FALSE;	if ((s = usbdTransfer (usbdClientHandle, handle, &irp)) != OK)	    {	    fprintf (fout, "usbdTransfer() returned %d\n", s);	    break;	    }	while (!enterPressed && !irpCallbackInvoked)	    OSS_THREAD_SLEEP (1);	if (irpCallbackInvoked)	    {	    if (irp.result != OK)		{		fprintf (fout, "irp.result == %d\n", irp.result);		break;		}	    fprintf (fout, "actLen = %d: ", irp.bfrList [0].actLen);	    displayMem (irp.bfrList [0].actLen, bfr, fout);	    }	else	    {	    if ((s = usbdTransferAbort (usbdClientHandle, handle, &irp)) 		!= OK)		{		fprintf (fout, "usbdTransferAbort() returned %d\n", s);		break;		}	    /* wait for the callback to be invoked */	    while (!irpCallbackInvoked)		OSS_THREAD_SLEEP (1);	    }	}    OSS_THREAD_DESTROY (thread);pipe_done:    if ((s = usbdPipeDestroy (usbdClientHandle, handle)) != OK)	{	fprintf (fout, "usbdPipeDestroy() returned %d\n", s);	return RET_CONTINUE;	}    return RET_CONTINUE;    }#ifdef INCLUDE_USB_KEYBOARD/*************************************************************************** cmdKbdInit - initializes USB keyboard SIO driver** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdKbdInit    (    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) */    )    {    if (usbKeyboardDevInit () == OK)	fprintf (fout, "usbKeyboardDevInit() returned OK\n");    else	fprintf (fout, "usbKeyboardDevInit() returned ERROR\n");    return RET_CONTINUE;    }/*************************************************************************** cmdKbdDown - shuts down USB keyboard SIO driver** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdKbdDown    (    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) */    )    {    if (usbKeyboardDevShutdown () == OK)	fprintf (fout, "usbKeyboardDevShutdown() returned OK\n");    else	fprintf (fout, "usbKeyboardDevShutdown() returned ERROR\n");    return RET_CONTINUE;    }/*************************************************************************** kbdAttachCallback - receives callbacks from USB keyboard SIO driver** RETURNS: N/A*/LOCAL SIO_CHAN *pKbdSioChan;LOCAL VOID kbdAttachCallback    (    pVOID arg,			    /* caller-defined argument */    SIO_CHAN *pChan,		    /* pointer to affected SIO_CHAN */    UINT16 attachCode		    /* defined as USB_KBD_xxxx */    )    {    FILE *fout = (FILE *) arg;    fprintf (fout, "pChan = %p, attach code = %s\n", pChan,	(attachCode == USB_KBD_ATTACH) ? "USB_KBD_ATTACH" : "USB_KBD_REMOVE");    if (attachCode == USB_KBD_ATTACH)	{	if (pKbdSioChan == NULL)	    {	    if (usbKeyboardSioChanLock (pChan) != OK)		fprintf (fout, "usbKeyboardSioChanLock() returned ERROR\n");	    else		pKbdSioChan = pChan;	    }

⌨️ 快捷键说明

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