📄 urb.c
字号:
/* urb.c - USB request block handler routines *//* Copyright 2004 Wind River Systems, Inc. This software includes software licensed to Wind River Systems, Inc. by Wipro, Ltd. Wind River licensees may use this software according to the terms of their Wind River license agreement(s) applicable to this software.*//*Modification history--------------------01b,11oct04,ami Apigen Changes01a,23jun03,cfc Changing the code to WRS standards*//*DESCRIPTIONThis module provides interfaces to communicate with the USB Device. The classdrivers can use these interfaces to1. Issue USB Standard Requests to the device.2. Issue Class Specific or Vendor Specific using data transfers on the Default Control Endpoint.3. Perform all data transfers to the device.4. Cancel data transfers.This file is included by the usbd.c source file.INCLUDE FILES : none*//*INTERNAL ******************************************************************************* * Filename : urb.c * * Copyright : * * THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO * LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING * ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE * 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY * ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY * PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE * ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL. * THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF * THIS COPYRIGHT AS PER APPLICABLE LAWS. * * * Description : This module provides interfaces to communicate with the * USB Device. The class drivers can use these interfaces to * 1. Issue USB Standard Requests to the device. * 2. Issue Class Specific or Vendor Specific using data * transfers on the Default Control Endpoint. * 3. Perform all data transfers to the device. * 4. Cancel data transfers. * ******************************************************************************//**************************************************************************** usbdComputeCRC - compute the 16-bit CRC value for the passed data buffer** This function computes the 16-bit CRC value for the passed data buffer** RETURNS: UINT16, 16-bit CRC value for the data buffer** ERRNO: None** \NOMANUAL*/LOCAL UINT16 usbdComputeCRC ( UCHAR *pBuffer, /* Pointer to data buffer */ UINT16 uLength /* Number of bytes in buffer */ ) { UINT16 uHold = CRC16_INITIAL_HOLD; /* Hold is initially 00011111b */ UINT16 uIndex = 0; /* To hold the loop index */ OS_LOG_MESSAGE_LOW(USBD,"usbdComputeCRC() Function.\n",0,0,0,0); /* Compute the CRC for the complete bytes */ for (uIndex = 0; uIndex < uLength ; uIndex++) { /* Compute CRC for the byte */ uHold = usbdComputeCRCForByte(pBuffer[uIndex], uHold); } /* Invert the CRC */ uHold ^= CRC16_MASK; uHold &= CRC16_MASK; OS_LOG_MESSAGE_LOW(USBD,"Exiting usbdComputeCRC().\n",0,0,0,0); /* Return the CRC computed */ return uHold; } /* End of function USBD_ComputeCRC *//**************************************************************************** usbdReverseHold16 - reverse the 16-bit hold value** This function reverses the 16-bit hold value.** RETURNS: UINT16, 16-bit reversed value for the hold value** ERRNO: None** \NOMANUAL*/LOCAL UINT16 usbdReverseHold16 ( UINT16 uHold /* Hold value to be reversed */ ) { UINT16 uReversedHold = 0; /* Reversed hold bit */ UINT16 uIndex = 0; /* Loop counter */ OS_LOG_MESSAGE_LOW(USBD, "Entering usbdReverseHold16() Function.\n", 0, 0, 0, 0); /* Compute the reversed hold bit */ for (uIndex = 0; uIndex < 16; uIndex++) { uReversedHold <<= 1; if (0x01 == (uHold & 0x01)) { uReversedHold |= 0x01; } uHold >>= 1; } OS_LOG_MESSAGE_LOW(USBD,"Exiting usbdReverseHold16() Function.\n",0,0,0,0); /* Return the reversed hold bit */ return uReversedHold; } /* End of function USBD_ReverseHold16 *//**************************************************************************** usbdComputeCRCForByte - compute 16-Bit CRC value for passed 8-bit data** This function is used to compute the 16-bit CRC value for the passed* 8-bit data.** RETURNS: UINT16, 16-bit reversed value for the 8-Bit data** ERRNO: None** \NOMANUAL*/LOCAL UINT16 usbdComputeCRCForByte ( UCHAR cData, /* 8 bit value */ UINT16 uHold /* 16 bit initial hold value */ ) { UCHAR cNextBit = 0x00; /* Next bit in the data buffer */ UCHAR cShiftedHoldBit = 0x00; /* Hold bit shifted */ UINT16 uIndex; /* Loop index counter */ OS_LOG_MESSAGE_LOW(USBD, "Entering usbdComputeCRCForByte() Function.\n", 0, 0, 0, 0); /* Compute the CRC for the byte */ for (uIndex = 0; uIndex < 8; uIndex++) { /* Obtain the next bit */ cNextBit = (UCHAR)(cData & 0x01); /* Shift the data */ cData >>= 1; /* Compute the shifted hold bit */ if (0x01 == (uHold & 0x01)) { cShiftedHoldBit = 0x01; } else { cShiftedHoldBit = 0x00; } /* * Check whether the next bit is equal to 1 or equal to 0. If it is not * equal to 1 and not equal to 0, do not do anything and continue the * loop. */ if ((0x00 != cNextBit) && (0x01 != cNextBit)) { continue; } /* Check whether the next bit is equal to 0 */ if (cShiftedHoldBit == cNextBit) { /* Push 0 into the hold bit */ uHold >>= 1; uHold &= CRC16_MASK; } else { /* Push 0 into the hold bit */ uHold >>= 1; uHold &= CRC16_MASK; uHold = usbdReverseHold16(uHold); uHold ^= CRC16_GENERATOR_POLY; uHold = usbdReverseHold16(uHold); } } OS_LOG_MESSAGE_LOW(USBD, "Exiting usbdComputeCRCForByte() Function.\n", 0, 0, 0, 0); /* Return the CRC */ return uHold; } /* End of function usbdComputeCRCForByte *//**************************************************************************** usbHstCompletionCallback - called on the event of completion of submitted URB** This is a callback function that is called on the event completion of the * URB that is submitted. This function release the event.** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if parameter is not valid** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHstCompletionCallback ( pUSBHST_URB pUrb /* Ptr to USB Request Block */ ) { OS_LOG_MESSAGE_LOW(USBD, "Entering usbHstCompletionCallback() Function.\n", 0, 0, 0, 0); /* Check if pContext is valid */ if ((NULL == pUrb) || (NULL == pUrb->pContext)) { OS_LOG_MESSAGE_HIGH( USBD, "usbHstCompletionCallback() Failed: URB context is NULL.\n", 0, 0, 0, 0); return USBHST_FAILURE; } /* Release the event */ OS_RELEASE_EVENT((OS_EVENT_ID)pUrb->pContext); OS_LOG_MESSAGE_LOW(USBD, "Exiting usbHstCompletionCallback() Exit.\n", 0, 0, 0, 0); return USBHST_SUCCESS; } /* End of function usbHstCompletionCallback *//**************************************************************************** usbHstGetDescriptor - get USB Descriptor** This function is used to issue GET_DESCRIPTOR USB Standard Request..** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if parameter is not valid** ERRNO: None*/USBHST_STATUS usbHstGetDescriptor ( UINT32 hDevice, /* USB device handle */ UINT8 uDescType, /* Type of descriptor */ UINT8 uDescIndex, /* Index of config or string descr */ UINT16 swLangID, /* Language ID in case of string descr */ UINT32 *puSize, /* Ptr to store number of bytes fetched */ UCHAR *pBuffer /* Ptr to buffer to hold fetched data */ ) { /* To store the device info */ pUSBD_DEVICE_INFO pDeviceInfo = NULL; /* To store the usb status returned on submission of request */ USBHST_STATUS nReturnStatus = USBHST_FAILURE; /* WindView Instrumentation */ USB_USBD_LOG_EVENT( USB_USBD_WV_REQUEST, "Entering usbHstGetDescriptor() Function.", USB_USBD_WV_FILTER); OS_LOG_MESSAGE_LOW(USBD, "Entering usbHstGetDescriptor() Function.\n", 0, 0, 0, 0); /* Check if puSize and buffer are valid */ if ((NULL == puSize) || (NULL == pBuffer)) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstGetDescriptor() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* * Check if uDescType is device, configuration, qualifier,other speed device * configuration or string. * If not any of these then return USBHST_INVALID_PARAMETER. * If uDescType is device or qualifier then uDescIndex should be zero. * Else if uDescType is configuration or string then uDescIndex can be * zero or non zero value. */ if ((uDescType != USBHST_CONFIG_DESC) && (uDescType != USBHST_STRING_DESC)) { if (uDescIndex != 0) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstGetDescriptor() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } if ((uDescType != USBHST_DEVICE_DESC)) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstGetDescriptor() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } } /* 2.0 compliant */ if ((USBHST_CONFIG_DESC != uDescType) && (USBHST_STRING_DESC != uDescType)&& (USBHST_OTHER_SPEED_CONFIG_DESC != uDescType)) { if (0 != uDescIndex) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstGetDescriptor() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } if ((USBHST_DEVICE_DESC != uDescType)&& (USBHST_DEVICE_QUALIFIER_DESC != uDescType)) { OS_LOG_MESSAGE_MEDIUM( USBD, "USBHST_GetDescriptor() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } } /* * If uDescType is string then swLangID should be non zero. * Otherwise swLangID is zero */ if (((USBHST_STRING_DESC == uDescType) && (0 == swLangID)) || ((USBHST_STRING_DESC != uDescType) && (0 != swLangID)))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -