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

📄 usrusbtool.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    enterPressed = FALSE;    if (OSS_THREAD_CREATE (enterThread, 			   (pVOID) fout, 			   OSS_PRIORITY_INHERIT, 			   "tEnter",			   &thread) 			!= OK)	{	fprintf (fout, "Error creating thread.\n");	return ERROR;	}    /* Wait for a printer to be attached. */    if (pPrnSioChan == NULL)	{	fprintf (fout, "Waiting for printer to be attached...\n");	while (!enterPressed && pPrnSioChan == NULL)	    OSS_THREAD_SLEEP (1);	}    /* kill keypress thread */    OSS_THREAD_DESTROY (thread);    if (enterPressed)	return ERROR;    if ((pBfr = OSS_MALLOC (USB_PRN_MAX_DEVICE_ID_LEN)) == NULL)        return ERROR;    pCaps = (USB_PRINTER_CAPABILITIES *) pBfr;    /* Display the printer characteristics. */    if ((*pPrnSioChan->pDrvFuncs->ioctl) (pPrnSioChan, 					  SIO_USB_PRN_DEVICE_ID_GET, 					  (void *) pBfr) 					!= OK)	fprintf (fout, "ioctl (SIO_USB_PRN_DEVICE_ID_GET) returned ERROR.\n");    else	{	idLen = FROM_BIGW (pCaps->length);	fprintf (fout, "Device ID length = %d\n", idLen);	fprintf (fout, "Device ID = ");	for (i = 0; i < idLen - 2; i++)	    fprintf (fout, "%c", pCaps->caps [i]);	fprintf (fout, "\n");	}    if ((*pPrnSioChan->pDrvFuncs->ioctl) (pPrnSioChan, SIO_USB_PRN_PROTOCOL_GET,	(void *) &protocol) != OK)	fprintf (fout, "ioctl (SIO_USB_PRN_PROTOCOL_GET) returned ERROR.\n");    else	{	fprintf (fout, "protocol = 0x%x ", protocol);	switch (protocol)	    {	    case USB_PROTOCOL_PRINTER_UNIDIR:		fprintf (fout, "(USB_PROTOCOL_PRINTER_UNIDIR)\n");		break;	    case USB_PROTOCOL_PRINTER_BIDIR:		fprintf (fout, "(USB_PROTOCOL_PRINTER_BIDIR)\n");		break;	    default:		fprintf (fout, "(unknown)\n");		break;	    }	}    OSS_FREE (pBfr);    return OK;    }/*************************************************************************** cmdPrint - performs printer test** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdPrint    (    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 blocks;    /* Get parameters */    *ppCmd = GetHexToken (*ppCmd, &blocks, 1);    /* Wait for a printer to be connected */    if (waitForPrinter (fout) == OK)	{	/* trigger a transmission. */	patternTest = TRUE;	nextCharVal = 0;	txCharCount = blocks * 4096;	fprintf (fout, "sending %d 4k blocks to printer...\n", (UINT16) blocks);	if ((*pPrnSioChan->pDrvFuncs->txStartup) (pPrnSioChan) != OK)	    fprintf (fout, "txStartup() returned ERROR.\n");	}    return RET_CONTINUE;    }/*************************************************************************** cmdPrintFnm - sends file to printer** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdPrintFnm    (    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) */    )    {    char fnm [MAX_CMD_LEN];    FILE *f;    long fsize;    /* Get filename parameter */    *ppCmd = GetNextToken (*ppCmd, fnm, sizeof (fnm));    /* Terminate any current dump test */    closeTxFile ();    /* Attempt to open file */    if ((f = fopen (fnm, "rb")) == NULL)	{	fprintf (fout, "Unable to open '%s'.\n", fnm);	return RET_CONTINUE;	}    /* Determine file size */    fseek (f, 0, SEEK_END);    fsize = ftell (f);    fprintf (fout, "file '%s' is %ld bytes.\n", fnm, fsize);    fseek (f, 0, SEEK_SET);    /* Wait for printer */    if (waitForPrinter (fout) == OK)	{	/* Initiate transmission */	patternTest = FALSE;	txFile = f;	txBfrCount = 0;	txCharCount = fsize;	fprintf (fout, "sending %ld bytes to printer...\n", fsize);	if ((*pPrnSioChan->pDrvFuncs->txStartup) (pPrnSioChan) != OK)	    {	    fprintf (fout, "txStartup() returned ERROR.\n");	    closeTxFile ();	    }	/* NOTE: If this path is successful, the file will be closed by	 * the prnTxCallback().	 */	}    else	{	/* Close input file */	fclose (f);	}        return RET_CONTINUE;    }#endif	/*INCLUDE_USB_PRINTER*/#ifdef INCLUDE_USB_SPEAKER/*************************************************************************** spkrAttachCallback - receives attach callbacks from speaker SEQ_DEV driver** RETURNS: N/A*/LOCAL SEQ_DEV *pSpkrSeqDev = NULL;LOCAL VOID spkrAttachCallback    (    pVOID arg,			    /* caller-defined argument */    SEQ_DEV *pSeqDev,		    /* pointer to affected SEQ_DEV */    UINT16 attachCode		    /* defined as USB_KBD_xxxx */    )    {    FILE *fout = (FILE *) arg;    fprintf (fout, "pSeqDev = %p, attach code = %s\n", pSeqDev,	(attachCode == USB_SPKR_ATTACH) ? "USB_SPKR_ATTACH" : "USB_SPKR_REMOVE");    if (attachCode == USB_SPKR_ATTACH)	{	if (pSpkrSeqDev == NULL)	    {	    if (usbSpeakerSeqDevLock (pSeqDev) != OK)		fprintf (fout, "usbSpeakerSeqDevLock() returned ERROR\n");	    else		{		pSpkrSeqDev = pSeqDev;		}	    }	else	    {	    fprintf (fout, "Another channel already in use, ignored.\n");	    }	}    else	{	if (pSeqDev == pSpkrSeqDev)	    {	    if (usbSpeakerSeqDevUnlock (pSeqDev) != OK)		fprintf (fout, "usbSpeakerSeqDevUnlock() returned ERROR\n");	    pSpkrSeqDev = NULL;	    }	}    }/***************************************************************************** audioThread - Dumps audio data to usbSpeakerLib** By convention, <param> is the file handle for the file to be played and * the global "wavDataLength" should be the length of the data chunk.  The* file position should be set to the beginning of the data in the data chunk.** This thread closes the file after reading all data.** RETURNS: N/A*/LOCAL BOOL audioThreadBusy = FALSE;LOCAL UINT32 wavDataLen;LOCAL VOID audioThread    (    pVOID param    )    {    FILE *wavFile = (FILE *) param;    pUINT8 pBfr;    UINT32 remDataLen = wavDataLen;    UINT32 actLen;    /* Create a buffer for audio data */    if ((pBfr = OSS_MALLOC (AUDIO_BFR_SIZE)) == NULL)	{	printf ("Out of memory creating audio buffer.\n");	}    else	{	/* open the audio stream. */	if ((*pSpkrSeqDev->sd_ioctl) (pSpkrSeqDev, 	    USB_SPKR_IOCTL_OPEN_AUDIO_STREAM, 0) != OK)	    {	    printf ("IOCTL OPEN_AUDIO_STREAM returned ERROR.\n");	    }	else	    {	    /* Read audio data and pass it to usbSpeakerLib. */	    while (remDataLen > 0 &&		(actLen = fread (pBfr, 1, min (remDataLen, AUDIO_BFR_SIZE), 		    wavFile)) > 0)		{		if ((*pSpkrSeqDev->sd_seqWrt) (pSpkrSeqDev, actLen,		    pBfr, FALSE) != OK)		    {		    printf ("sd_seqWrt() returned ERROR.\n");		    break;		    }		else		    {		    remDataLen -= actLen;		    }		}	    /* Mark the end of the audio stream. */	    if ((*pSpkrSeqDev->sd_ioctl) (pSpkrSeqDev, 		USB_SPKR_IOCTL_CLOSE_AUDIO_STREAM, 0) != OK)		{		printf ("IOCTL CLOSE_AUDIO_STREAM returned ERROR.\n");		}	    }	OSS_FREE (pBfr);	}    /* Close the input file. */    fclose (wavFile);    audioThreadBusy = FALSE;    }/*************************************************************************** cmdSpkrInit - initializes USB speaker SEQ_DEV driver** RETURNS: RET_CONTINUE*/LOCAL BOOL spkrInitialized = FALSE;LOCAL UINT16 cmdSpkrInit    (    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 (spkrInitialized)	{	fprintf (fout, "USB speaker SEQ_DEV driver already initialized.\n");	return RET_CONTINUE;	}    if (usbSpeakerDevInit () == OK)	{	fprintf (fout, "usbSpeakerDevInit() returned OK\n");	spkrInitialized = TRUE;	/* Register for attach notification */	if (usbSpeakerDynamicAttachRegister (spkrAttachCallback, (pVOID) fout) != OK)	    {	    fprintf (fout, "usbSpeakerDynamicAttachRegister() returned ERROR\n");	    return RET_CONTINUE;	    }	}    else	fprintf (fout, "usbSpeakerDevInit() returned ERROR\n");    audioThreadBusy = FALSE;    return RET_CONTINUE;    }/*************************************************************************** cmdSpkrDown - shuts down USB speaker SEQ_DEV driver** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdSpkrDown    (    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 (!spkrInitialized)	{	fprintf (fout, "USB speaker SEQ_DEV driver not initialized.\n");	return RET_CONTINUE;	}    if (audioThreadBusy)	{	fprintf (fout, "audioThread is busy.\n");	return RET_CONTINUE;	}    spkrInitialized = FALSE;    pSpkrSeqDev = NULL;    /* unregister */    if (usbSpeakerDynamicAttachUnRegister (spkrAttachCallback, (pVOID) fout) != OK)	fprintf (fout, "usbSpeakerDynamicAttachUnRegister() returned ERROR\n");    if (usbSpeakerDevShutdown () == OK)	fprintf (fout, "usbSpeakerDevShutdown() returned OK\n");    else	fprintf (fout, "usbSpeakerDevShutdown() returned ERROR\n");    return RET_CONTINUE;    }/*************************************************************************** waitForSpeaker - waits for a speaker to be connected** RETURNS: OK if speaker connected, else ERROR*/LOCAL STATUS waitForSpeaker    (    FILE *fout    )    {    THREAD_HANDLE thread;    /* Create thread to watch for keypress */    enterPressed = FALSE;    if (OSS_THREAD_CREATE (enterThread, (pVOID) fout, OSS_PRIORITY_INHERIT, "tEnter",	&thread) != OK)	{	fprintf (fout, "Error creating thread.\n");	return ERROR;	}    /* Wait for a speaker to be attached. */    if (pSpkrSeqDev == NULL)	{	fprintf (fout, "Waiting for speaker to be attached...\n");	while (!enterPressed && pSpkrSeqDev == NULL)	    OSS_THREAD_SLEEP (1);	}    /* kill keypress thread */    OSS_THREAD_DESTROY (thread);    if (enterPressed)	return ERROR;    return OK;    }/*************************************************************************** cmdSpkrFmt - Displays available speaker formats** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdSpkrFmt    (    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 fmtCount, i;    pUSB_SPKR_AUDIO_FORMAT pFmt;    if (!spkrInitialized)	{	fprintf (fout, "USB speaker SEQ_DEV driver not initialized.\n");	return RET_CONTINUE;	}    if (waitForSpeaker (fout) != OK)	return RET_CONTINUE;    /* Get number and info about speaker formats */    if ((*pSpkrSeqDev->sd_ioctl) (pSpkrSeqDev, 	USB_SPKR_IOCTL_GET_FORMAT_COUNT, (int) &fmtCount) != OK)	{	fprintf (fout, "IOCTL GET_FORMAT_COUNT returned ERROR\n");	return RET_CONTINUE;	}    fprintf (fout, "Speaker supports %d formats.\n", fmtCount);    if ((*pSpkrSeqDev->sd_ioctl) (pSpkrSeqDev, 	USB_SPKR_IOCTL_GET_FORMAT_LIST, (int) &pFmt) != OK)	{	fprintf (fout, "IOCTL GET_FORMAT_LIST returned ERROR\n");	return RET_CONTINUE;	}    for (i = 0; i < fmtCount; i++)	{	fprintf (fout, "format [%d]:\n", i);	fprintf (fout, "  interface = %d, alt setting = %d\n", 	    pFmt [i].interface, pFmt [i].altSetting);	fprintf (fout, "  endpoint = 0x%x, maxPacketSize = %d, delay = %d\n",	    pFmt [i].endpoint, pFmt [i].maxPacketSize, pFmt [i].delay);	fprintf (fout, "  formatTag = 0x%x, formatType = %d\n",	    pFmt [i].formatTag, pFmt [i].formatType);	switch (pFmt [i].formatType)	    {	    case USB_AUDIO_FORMAT_TYPE1:	    case USB_AUDIO_FORMAT_TYPE3:		fprintf (fout, "  channels = %d\n", pFmt [i].channels);		fprintf (fout, "  subFrameSize = %d\n", pFmt [i].subFrameSize);		fprintf (fout, "  bitRes = %d\n", pFmt [i].bitRes);		break;	    case USB_AUDIO_FORMAT_TYPE2:		fprintf (fout, "  maxBitRate = %d\n", pFmt [i].maxBitRate);		fprintf (fout, "  samplesPerFrame = %d\n", pFmt [i].samplesPerFrame);		break;	    default:		fprintf (fout, "  <<unrecognized format type>>\n");		break;	    }	}    return RET_CONTINUE;    }/***************************************************************************** parseWavFile - parses and displays info about a .wav file** Attempts to play the .wav file.** NOTE: If this function returns TRUE, the caller SHOULD NOT close the* wavFile.  That will be done automatically when playing is finished.* * RETURNS: OK if able to play file, else ERROR.*/LOCAL STATUS parseWavFile    (   

⌨️ 快捷键说明

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