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

📄 usbtargmslib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 5 页
字号:
                g_usbDevQualDescr.maxPacketSize0 = USB_MIN_CTRL_PACKET_SIZE;

               /* Update the max packet size for bulk in and out endpoints */

                g_bulkOutEpDescr.maxPacketSize = 
                                       TO_LITTLEW(USB_MAX_HIGH_SPEED_BULK_SIZE);
                g_bulkInEpDescr.maxPacketSize = 
                                       TO_LITTLEW(USB_MAX_HIGH_SPEED_BULK_SIZE);
                }

            break;

    	case TARG_MNGMT_DISCONNECT:
            configurationSet (param, targChannel, 0);
     	    break;

        case TARG_MNGMT_SUSPEND:
        case TARG_MNGMT_RESUME:
    	default:
    	    break;
    	}

    return OK;
    }

#endif

/*******************************************************************************
*
* usbTargMsCallbackInfo - returns usbTargPrnLib callback table
* 
* This function returns the callback table pointer .
*
* RETURNS: N/A
*
* ERRNO:
*  none
*/

VOID usbTargMsCallbackInfo
    (
    struct usbTargCallbackTable ** ppCallbacks,	/*USB_TARG_CALLBACK_TABLE */
    pVOID			* pCallbackParam /* Callback Parameter */
    )
    {
    if (ppCallbacks != NULL)
        *ppCallbacks = &usbTargMsCallbackTable;

    if (pCallbackParam != NULL)
        *pCallbackParam = NULL;
    }

/*******************************************************************************
*
* usbMsBulkInErpInit - initialize the bulk-in ERP
*
* This function initializes the Bulk In ERP.
*
* RETURNS: OK, or ERROR if unable to submit ERP.
*
* ERRNO:
*  none 
*/

STATUS usbMsBulkInErpInit
    (
    UINT8		* pData,	/* pointer to data */
    UINT32		size,		/* size of data */
    ERP_CALLBACK	erpCallback,	/* erp callback */
    pVOID		usrPtr		/* user pointer */
    )
    {
    if (pData == NULL)
        return ERROR;

    if (g_bulkInInUse)
        return ERROR;

    memset (&g_bulkInErp, 0, sizeof (USB_ERP));

    g_bulkInErp.erpLen = sizeof (USB_ERP);
    g_bulkInErp.userCallback = erpCallback;
    g_bulkInErp.bfrCount = 1;
    g_bulkInErp.userPtr = usrPtr;

    g_bulkInErp.bfrList [0].pid = USB_PID_IN;
    g_bulkInErp.bfrList [0].pBfr = pData;
    g_bulkInErp.bfrList [0].bfrLen = size;

    g_bulkInInUse = TRUE;
    g_bulkInBfrValid = FALSE;

    if (usbTargTransfer (g_bulkInPipeHandle, &g_bulkInErp) != OK)
        {
        g_bulkInInUse = FALSE;
        return ERROR;
        }

    return OK;
    }


/***************************************************************************
*
* usbMsBulkOutErpInit - initialize the bulk-Out ERP
*
* This function initializes the bulk Out ERP.
*
* RETURNS: OK, or ERROR if unable to submit ERP.
*
* ERRNO: N/A
*/

STATUS usbMsBulkOutErpInit 
    (
    UINT8           * pData,		/* pointer to buffer */
    UINT32          size,		/* size of data */ 
    ERP_CALLBACK    erpCallback,	/* IRP_CALLBACK */
    pVOID           usrPtr		/* user pointer */
    )
    {
    if (pData == NULL)
        return ERROR;

    if (g_bulkOutInUse)
	    return ERROR;

    /* Initialize bulk ERP */

    memset (&g_bulkOutErp, 0, sizeof (USB_ERP));

    g_bulkOutErp.erpLen = sizeof (USB_ERP);
    g_bulkOutErp.userCallback = erpCallback;
    g_bulkOutErp.bfrCount = 1;
    g_bulkOutErp.userPtr = usrPtr;

    g_bulkOutErp.bfrList [0].pid = USB_PID_OUT;
    g_bulkOutErp.bfrList [0].pBfr = pData;
    g_bulkOutErp.bfrList [0].bfrLen = size;

    g_bulkOutInUse = TRUE;
    g_bulkOutBfrValid = FALSE;

    if (usbTargTransfer (g_bulkOutPipeHandle, &g_bulkOutErp) != OK)
        {
	g_bulkOutInUse = FALSE;
	return ERROR;
	}

    return OK;
    }

/*******************************************************************************
*
* usbMsIsConfigured - test if the device is configured
*
* This function checks whether the device is configured or not.
*
* RETURNS: TRUE or FALSE
*
* ERRNO:
*  none
*/

BOOL usbMsIsConfigured (void)
    {
    BOOL	retVal;

    retVal = (g_configuration == MS_CONFIG_VALUE)?TRUE:FALSE;

    return(retVal);
    }

/*******************************************************************************
*
* usbMsBulkInErpInUseFlagGet - get the Bulk-in ERP inuse flag
*
* This function is used to get the state of the Bulk-In ERP.
*
* RETURNS: TRUE or FALSE
*
* ERRNO:
*  none
*/

BOOL usbMsBulkInErpInUseFlagGet (void)
    {
    BOOL retVal = g_bulkInInUse;
    return(retVal);
    }

/*******************************************************************************
*
* usbMsBulkOutErpInUseFlagGet - get the Bulk-Out ERP inuse flag
*
* This function is used to get the state of the Bulk-OUT ERP.
*
* RETURNS: OK, or ERROR if unable to submit ERP.
*
* ERRNO:
*  none
*/

BOOL usbMsBulkOutErpInUseFlagGet (void)
    {
    BOOL	retVal = g_bulkOutInUse;
    return(retVal);
    }

/*******************************************************************************
*
* usbMsBulkInErpInUseFlagSet - set the Bulk-In ERP inuse flag
*
* This function is used to set the state of Bulk - IN ERP flag. <state> is the
* state to set.
*
* RETURNS: N/A
*
* ERRNO:
*  none
*/
void usbMsBulkInErpInUseFlagSet
    (
    BOOL state
    )
    {
    g_bulkInInUse = state;
    return;
    }


/*******************************************************************************
*
* usbMsBulkOutErpInUseFlagSet - set the Bulk-Out ERP inuse flag
*
* This function is used to set the state of Bulk - OUT ERP flag. <state> is the
* state to set.
*
* RETURNS: N/A
*
* ERRNO:
*  none
*/
void usbMsBulkOutErpInUseFlagSet
    (
    BOOL	state		/* State to set */
    )
    {
    g_bulkOutInUse = state;
    return;
    }

#ifdef USE_MS_TEST_DATA
/*******************************************************************************
*
* usbMsTestTxCallback - invoked after test data transmitted
*
* This function is invoked after the Bulk IN test data is transmitted. It sets
* the bulk IN flag to <false>.
*
* RETURNS: N/A
*
* ERRNO:
*  none
*/
void usbMsTestTxCallback
    (
    pVOID	p
    )
    {
    g_bulkInInUse = FALSE;
    return;
    }


/***************************************************************************
*
* usbMsTestRxCallback - invoked after test data is received
*
* This function is invoked after the Bulk OUT test data is transmitted. It sets
* the bulk OUT flag to <false>.
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void usbMsTestRxCallback
    (
    pVOID	p
    )
    {
    g_bulkOutInUse = FALSE;
    return;
    }
#endif

#ifdef USB_DEBUG_PRINT
/***************************************************************************
*
* usbDbgPrintOn - switch on debug printing
*
* This function is used to switch on the debug printing. This function is
* used only for degugging purpose.
*
* RETURNS: N/A
*
* ERRNO: N/A
*
*\NOMANUAL
*/

void usbDbgPrintOn (void)
    {
    g_usbDbgPrint = TRUE;
    return;
    }


/***************************************************************************
*
* usbDbgPrintOff - switch off debug printing
*
* This function is used to switch off the debug printing. 
*
* RETURNS: N/A
*
* ERRNO: N/A
*
*\NOMANUAL
*/

void usbDbgPrintOff
    (
    void
    )
    {
    g_usbDbgPrint = FALSE;
    return;
    }


/***************************************************************************
*
* usbDbgPrint - print the formatted debug statement
*
* This function implements the code for printign the debug messages
*
* RETURNS: N/A
*
* ERRNO:
*  none
*
*\NOMANUAL
*/

void usbDbgPrint
    (
    char *fmt,
    ...
    )
    {
    va_list	ap;
    char	* p;
    char	* pBuf;
    int		val =0;
    int		cnt = 0;

    if (g_usbDbgPrint == FALSE)
        return;

    va_start(ap, fmt);
    memset(&g_buf[0],0,BUF_SIZE);

    pBuf = &g_buf[0];

    for (p = fmt; *p != '\0'; p++)
        {
        if (*p != '%')
            {
            if (cnt < BUF_SIZE)
                {
                *pBuf++ = *p;
                cnt++;
                continue;
                }
            else
                goto EXIT;
            }

        switch(*++p)
            {
            case 'd':
            case 'x':
                val = va_arg(ap, int);
                if ((cnt + 2*sizeof(int)) < BUF_SIZE)
                    {
                    sprintf(pBuf,"%x",val);
                    while(*pBuf != '\0')
                        {
                        pBuf++;
                        cnt++;
                        }
                    }
                else
                    goto EXIT;
                break;
            default:
                break;
            }
        }

EXIT:
    va_end(ap);
    DEBUG_PRINT(g_buf);
    return;
    }

/*******************************************************************************
*
* usbMsTargError - print the error message
*
* This function is called whenver any error occurs. It is used to print
* appropiate error messaged dependign on the error status set. 
*
* RETURNS: N/A
*
* ERRNO: N/A
*
*\NOMANUAL
*/

void usbMsTargError (void)
    {

    int	error = errnoGet();

    switch(error)
        {
        case S_usbTcdLib_BAD_PARAM:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_BAD_PARAM\n");
            break;
        case S_usbTcdLib_BAD_HANDLE:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_BAD_HANDLE\n");
            break;
        case S_usbTcdLib_OUT_OF_MEMORY:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_OUT_OF_MEMORY\n");
            break;
        case S_usbTcdLib_OUT_OF_RESOURCES: 
            usbDbgPrint("usbMsTargError: S_usbTcdLib_OUT_OF_RESOURCES\n");
            break;
        case S_usbTcdLib_NOT_IMPLEMENTED:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_NOT_IMPLEMENTED\n");
            break;
        case S_usbTcdLib_GENERAL_FAULT:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_GENERAL_FAULT\n");
            break;
        case S_usbTcdLib_NOT_INITIALIZED:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_NOT_INITIALIZED\n");
            break;
        case S_usbTcdLib_INT_HOOK_FAILED:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_INT_HOOK_FAILED\n");
            break;
        case S_usbTcdLib_HW_NOT_READY:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_HW_NOT_READY\n");
            break;
        case S_usbTcdLib_NOT_SUPPORTED:
            usbDbgPrint("usbMsTargError: S_usbTcdLib_NOT_SUPPORTED\n");
            break;
        case S_usbTcdLib_ERP_CANCELED:
            usbD

⌨️ 快捷键说明

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