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

📄 usbprinterlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 4 页
字号:
             status =EIO;         else             status = OK;         break;	case SIO_BAUD_SET:	/* set baud rate */	case SIO_BAUD_GET:	/* get baud rate */	case SIO_HW_OPTS_SET:   /* optional, not supported */	case SIO_HW_OPTS_GET:   /* optional, not supported */	case SIO_HUP:	/* hang up is not supported */	default:	    /* unknown/unsupported command. */	    status = ENOSYS;	}    OSS_MUTEX_RELEASE (prnMutex);    return status;    }/***************************************************************************** usbPrinterTxStartup - start the interrupt transmitter** This function will be called when characters are available for transmission* to the printer.  ** RETURNS: OK, or EIO if unable to start transmission to printer** ERRNO: none** \NOMANUAL*/LOCAL int usbPrinterTxStartup    (    SIO_CHAN *pChan	/* channel to start */    )    {    pUSB_PRN_SIO_CHAN pSioChan = (pUSB_PRN_SIO_CHAN) pChan;    int status = OK;    OSS_MUTEX_TAKE (prnMutex, OSS_BLOCK);    if (initiateOutput (pSioChan) != OK)	status = EIO;    OSS_MUTEX_RELEASE (prnMutex);    return status;    }/***************************************************************************** usbPrinterCallbackInstall - install ISR callbacks to get/put chars** This driver allows interrupt callbacks for transmitting characters* and receiving characters.=** RETURNS: OK on success, or ENOSYS for an unsupported callback type.** ERRNO: none** \NOMANUAL*/LOCAL int usbPrinterCallbackInstall    (    SIO_CHAN *pChan,	    /* channel */    int callbackType,	    /* type of callback */    STATUS (*callback) (void *tmp, ...),  /* callback */    void *callbackArg	    /* parameter to callback */    )    {    pUSB_PRN_SIO_CHAN pSioChan = (pUSB_PRN_SIO_CHAN) pChan;    switch (callbackType)	{	case SIO_CALLBACK_GET_TX_CHAR:	    pSioChan->getTxCharCallback = (STATUS (*)()) (callback);	    pSioChan->getTxCharArg = callbackArg;	    return OK;	case SIO_CALLBACK_PUT_RCV_CHAR:	    pSioChan->putRxCharCallback = (STATUS (*)()) (callback);	    pSioChan->putRxCharArg = callbackArg;	    return OK;	default:	    return ENOSYS;	}    }/***************************************************************************** usbPrinterPollOutput - output a character in polled mode** The USB printer driver supports only interrupt-mode operation.  Therefore,* this function always returns the error ENOSYS.** RETURNS: ENOSYS** ERRNO: none** \NOMANUAL*/LOCAL int usbPrinterPollOutput    (    SIO_CHAN *pChan,    char outChar    )    {    return ENOSYS;    }/***************************************************************************** usbPrinterPollInput - poll the device for input** The USB printer driver supports only interrupt-mode operation.  Therefore,* this function always returns the error ENOSYS.** RETURNS: ENOSYS** ERRNO: none** \NOMANUAL*/LOCAL int usbPrinterPollInput    (    SIO_CHAN *pChan,    char *thisChar    )    {    return ENOSYS;    }/***************************************************************************** usbPrinterDevInit - initialize USB printer SIO driver** Initializes the USB printer SIO driver.  The USB printer SIO driver* maintains an initialization count, so calls to this function may be* nested.** RETURNS: OK, or ERROR if unable to initialize.** ERRNO:* \is* \i S_usbPrinterLib_OUT_OF_RESOURCES* Sufficient resources not available** \i S_usbPrinterLib_USBD_FAULT* Error in USBD layer* \ie*/STATUS usbPrinterDevInit (void)    {    /* If not already initialized, then initialize internal structures     * and connection to USBD.     */    if (initCount == 0)	{	/* Initialize lists, structures, resources. */	memset (&sioList, 0, sizeof (sioList));	memset (&reqList, 0, sizeof (reqList));	prnMutex = NULL;	usbdHandle = NULL;	if (OSS_MUTEX_CREATE (&prnMutex) != OK)	    return doShutdown (S_usbPrinterLib_OUT_OF_RESOURCES);	/* Establish connection to USBD */	if (usbdClientRegister (PRN_CLIENT_NAME, 				&usbdHandle) 			      != OK ||	    usbdDynamicAttachRegister (usbdHandle,				       USB_CLASS_PRINTER,				       USB_SUBCLASS_PRINTER, 				       USBD_NOTIFY_ALL,				       usbPrinterAttachCallback) 				    != OK)		{		return doShutdown (S_usbPrinterLib_USBD_FAULT);		}	}    initCount++;    return OK;    }/***************************************************************************** usbPrinterDevShutdown - shuts down printer SIO driver** This function shutdowns the printer SIO driver when <initCount> becomes 0** RETURNS: OK, or ERROR if unable to shutdown.** ERRNO:* \is* \i S_usbPrinterLib_NOT_INITIALIZED* Printer not initialized* \ie*/STATUS usbPrinterDevShutdown (void)    {    /* Shut down the USB printer SIO driver if the initCount goes to 0. */    if (initCount == 0)	return ossStatus (S_usbPrinterLib_NOT_INITIALIZED);    if (--initCount == 0)	return doShutdown (OK);    return OK;    }/***************************************************************************** usbPrinterDynamicAttachRegister - Register printer attach callback** <callback> is a caller-supplied function of the form:** \cs* typedef (*USB_PRN_ATTACH_CALLBACK)*     (*     pVOID arg,*     SIO_CHAN *pSioChan,*     UINT16 attachCode*     );* \ce** usbPrinterLib will invoke <callback> each time a USB printer* is attached to or removed from the system.  <arg> is a caller-defined* parameter which will be passed to the <callback> each time it is* invoked.  The <callback> will also be passed a pointer to the * SIO_CHAN structure for the channel being created/destroyed and* an attach code of USB_PRN_ATTACH or USB_PRN_REMOVE.** RETURNS: OK, or ERROR if unable to register callback** ERRNO:* \is* \i S_usbPrinterLib_BAD_PARAM* Bad Parameters received** \i S_usbPrinterLib_OUT_OF_MEMORY* System out of memory* \ie*/STATUS usbPrinterDynamicAttachRegister    (    USB_PRN_ATTACH_CALLBACK callback,	/* new callback to be registered */    pVOID arg		    /* user-defined arg to callback */    )    {    pATTACH_REQUEST pRequest;    pUSB_PRN_SIO_CHAN pSioChan;    int status = OK;    /* Validate parameters */    if (callback == NULL)	return ossStatus (S_usbPrinterLib_BAD_PARAM);    OSS_MUTEX_TAKE (prnMutex, OSS_BLOCK);    /* Create a new request structure to track this callback request. */    if ((pRequest = OSS_CALLOC (sizeof (*pRequest))) == NULL)	status = S_usbPrinterLib_OUT_OF_MEMORY;    else	{	pRequest->callback = callback;	pRequest->callbackArg = arg;	usbListLink (&reqList, pRequest, &pRequest->reqLink, LINK_TAIL);		/* Perform an initial notification of all currrently attached	 * printer devices.	 */	pSioChan = usbListFirst (&sioList);	while (pSioChan != NULL)	    {	    if (pSioChan->connected)		(*callback) (arg, (SIO_CHAN *) pSioChan, USB_PRN_ATTACH);	    pSioChan = usbListNext (&pSioChan->sioLink);	    }	}    OSS_MUTEX_RELEASE (prnMutex);    return ossStatus (status);    }/***************************************************************************** usbPrinterDynamicAttachUnregister - Unregisters printer attach callback** This function cancels a previous request to be dynamically notified for* printer attachment and removal.  The <callback> and <arg> paramters must* exactly match those passed in a previous call to * usbPrinterDynamicAttachRegister().** RETURNS: OK, or ERROR if unable to unregister callback** ERRNO:* \is* \i  S_usbPrinterLib_NOT_REGISTERED* Could not register the attachment callback* \ie*/STATUS usbPrinterDynamicAttachUnRegister    (    USB_PRN_ATTACH_CALLBACK callback,	/* callback to be unregistered */    pVOID arg		    /* user-defined arg to callback */    )    {    pATTACH_REQUEST pRequest;    int status = S_usbPrinterLib_NOT_REGISTERED;    OSS_MUTEX_TAKE (prnMutex, OSS_BLOCK);    pRequest = usbListFirst (&reqList);    while (pRequest != NULL)	{	if (callback == pRequest->callback && arg == pRequest->callbackArg)	    {	    /* We found a matching notification request. */	    destroyAttachRequest (pRequest);	    status = OK;	    break;	    }	pRequest = usbListNext (&pRequest->reqLink);	}    OSS_MUTEX_RELEASE (prnMutex);    return ossStatus (status);    }/***************************************************************************** usbPrinterSioChanLock - Marks SIO_CHAN structure as in use** A caller uses usbPrinterSioChanLock() to notify usbPrinterLib that* it is using the indicated SIO_CHAN structure.  usbPrinterLib maintains* a count of callers using a particular SIO_CHAN structure so that it * knows when it is safe to dispose of a structure when the underlying* USB printer is removed from the system.  So long as the "lock count"* is greater than zero, usbPrinterLib will not dispose of an SIO_CHAN* structure.** RETURNS: OK, or ERROR if unable to mark SIO_CHAN structure in use.** ERRNO: none*/STATUS usbPrinterSioChanLock    (    SIO_CHAN *pChan	/* SIO_CHAN to be marked as in use */    )    {    pUSB_PRN_SIO_CHAN pSioChan = (pUSB_PRN_SIO_CHAN) pChan;    pSioChan->lockCount++;    return OK;    }/***************************************************************************** usbPrinterSioChanUnlock - Marks SIO_CHAN structure as unused** This function releases a lock placed on an SIO_CHAN structure.  When a* caller no longer needs an SIO_CHAN structure for which it has previously* called usbPrinterSioChanLock(), then it should call this function to* release the lock.** NOTE: If the underlying USB printer device has already been removed* from the system, then this function will automatically dispose of the* SIO_CHAN structure if this call removes the last lock on the structure.* Therefore, a caller must not reference the SIO_CHAN again structure after* making this call.** RETURNS: OK, or ERROR if unable to mark SIO_CHAN structure unused** ERRNO:* \is* \i S_usbPrinterLib_NOT_LOCKED* No lock to unclock* \ie*/STATUS usbPrinterSioChanUnlock    (    SIO_CHAN *pChan	/* SIO_CHAN to be marked as unused */    )    {    pUSB_PRN_SIO_CHAN pSioChan = (pUSB_PRN_SIO_CHAN) pChan;    int status = OK;    OSS_MUTEX_TAKE (prnMutex, OSS_BLOCK);    if (pSioChan->lockCount == 0)	status = S_usbPrinterLib_NOT_LOCKED;    else	{	/* If this is the last lock and the underlying USB printer is	 * no longer connected, then dispose of the printer.	 */	if (--pSioChan->lockCount == 0 && !pSioChan->connected)	    destroySioChan (pSioChan);	}    OSS_MUTEX_RELEASE (prnMutex);    return ossStatus (status);    }/* end of file. */

⌨️ 快捷键说明

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