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

📄 device.c

📁 usb2 driver for vxwokrs
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* Check if the Bus Index is valid */    if ((USBD_MAX_BUS_NUM <= uBusIndex) ||        (gUSBBusInfoList[uBusIndex].hDefaultPipe == 0))        {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "usbdGetFreeAddress() Failed: Invalid parameters.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;        }    /* Initialize the output parameter pAddress to zero*/    *pAddress = 0;    /* Lock the bus operation before updating the device address map */    OS_WAIT_FOR_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock,                      OS_WAIT_INFINITE);    /*     * For each byte in the device address map of the bus find the bit     * position which is free.     */    for (uOuterIndex = 0; uOuterIndex < USBD_ADDRESS_MAP_SIZE; uOuterIndex++)        {        /* To check if the first bit position in the address map byte is free*/        uPower = 1;        /* Check if any bit position is 0 in the byte uOuterIndex */        if (0xFF !=            (0xFF & gUSBBusInfoList[uBusIndex].uDeviceAddressMap[uOuterIndex]))            {            /* Find the exact free bit position within each byte */            for (uInnerIndex = 1; uInnerIndex <= 8; uInnerIndex++)                {                if (0 ==                    (gUSBBusInfoList[uBusIndex].uDeviceAddressMap[uOuterIndex]&                     uPower))                    {                    /*                     * If the position is free then compute pAddress                     * and return                     */                    *pAddress = (uOuterIndex * 8) + uInnerIndex;                     /* Release the lock after updating device address map */                     OS_RELEASE_EVENT(                         gUSBBusInfoList[uBusIndex].busOperationLock);                     OS_LOG_MESSAGE_LOW(                         USBD,                         "Exiting usbdGetFreeAddress()  Function.\n",                         0,                         0,                         0,                         0);                    return USBHST_SUCCESS;                    }                /* Compute uPower to find the availability of next bit */                uPower = uPower << 1;                } /* End of FOR loop with uInnerIndex */            } /* End of IF */        } /* End of FOR loop with uOuterIndex */    /* Release the lock after updating the device address map */    OS_RELEASE_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock);    OS_LOG_MESSAGE_HIGH(        USBD,        "usbdGetFreeAddress() Function Failed: No free address avilable.\n",        0,        0,        0,        0);    /* When there is no free bit position available return USBHST_FAILURE. */    return USBHST_FAILURE;    } /* End of function usbdGetFreeAddress() *//***************************************************************************** usbdReserveAddress - reserves the specified address on the specified bus** This function is used to reserve teh specified address on the specified * bus** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if the address is not found** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbdReserveAddress    (    UINT8 uBusIndex,   /* Bus Index which device is connected */    UINT8 uAddress     /* Address to be reserved              */    )    {    UINT8 uOuterIndex = 0; /* Loop counter for byte pos in address map */    UINT8 uInnerIndex = 0; /* Loop counter for bit pos in byte of address map */    UINT8 uPower = 0;      /* bit position within a byte */    OS_LOG_MESSAGE_LOW(USBD,                       "Entering usbdReserveAddress() Function.\n",                       0,                       0,                       0,                       0);    /* Check if the Bus Index and device address are valid */    if ((USBD_MAX_BUS_NUM <= uBusIndex) ||        (gUSBBusInfoList[uBusIndex].hDefaultPipe == 0) ||        (uAddress == 0) ||        (uAddress > 127))        {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "usbdReserveAddress() Failed: Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;        }    /*     * To get the byte postion and bit position from the uAddress     * 1. Decrement the uAddress by 1     * 2. Get the outerindex by dividing uAddress by 8     * 3. Get the inner index  as ((taking mod of uAddress with 8) + 1)     */    /* Decrement the address by one */    uAddress--;    /* Get the byte position in the device address map */    uOuterIndex = uAddress / 8;    /* Get the bit position within the byte */    uInnerIndex = uAddress%8 + 1;    /* To check if the first bit position in the address map byte is free */     uPower = 1;    /* Compute the exact bit position in the byte */    uPower = uPower << (uInnerIndex - 1);    /*     * If the bit position corresponding to the device address is free then set     * the bit position and update global bus info list and return     * USBHST_SUCCESS.     */    if (0 == ((gUSBBusInfoList[uBusIndex].uDeviceAddressMap[uOuterIndex]) &              uPower))        {        /* Lock the bus operation before updating the device address map */        OS_WAIT_FOR_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock,                          OS_WAIT_INFINITE);        /* Set the address bit in device address map of global bus info list */        gUSBBusInfoList[uBusIndex].uDeviceAddressMap[uOuterIndex] |= uPower;        /* Release the lock after updating the device address map */        OS_RELEASE_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock);        OS_LOG_MESSAGE_LOW(USBD,                           "Exiting usbdReserveAddress() Function.\n",                           0,                           0,                           0,                           0);        return USBHST_SUCCESS;        }    OS_LOG_MESSAGE_HIGH(USBD,                        "usbdReserveAddress() Failed:could not get the given \                            free bit position in the device address map.\n",                        0,                        0,                        0,                        0);    /* Could not find the given free bit position in the device addressmap */    return USBHST_FAILURE;    } /* End of function usbdReserveAddress() *//***************************************************************************** usbdReleaseAddress - releases the specified address on the specified bus** This function releases the specified address on the specified bus** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if the address is not found** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbdReleaseAddress    (    UINT8 uBusIndex,   /* Bus Index which device is connected */    UINT8 uAddress     /* Address to be reserved              */    )    {    UINT8 uOuterIndex = 0; /* Loop counter for byte pos in address map */    UINT8 uInnerIndex = 0; /* Loop counter for bit pos in byte of address map */    UINT8 uPower = 0;      /* bit position within a byte */     OS_LOG_MESSAGE_LOW(USBD,                       "Entering usbdReleaseAddress() Function.\n",                       0,                       0,                       0,                       0);    /* Check if the Bus Index and device address are valid */    if ((USBD_MAX_BUS_NUM <= uBusIndex) ||        (gUSBBusInfoList[uBusIndex].hDefaultPipe == 0) ||        (uAddress == 0) ||        (uAddress > 127))        {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "usbdReleaseAddress() Failed: Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;        }    /*     * To get the byte postion and bit position from the uAddress     * 1. Decrement the uAddress by 1     * 2. Get the outerindex by dividing uAddress by 8     * 3. Get the inner index  as ((taking mod of uAddress with 8) + 1)     */    /* Decrement the address by one */    uAddress--;    /* Get the byte position in the device address map */    uOuterIndex = uAddress/8;    /* Get the bit position within the byte */    uInnerIndex = uAddress%8 + 1;    /* To check if the first bit position in the address map byte is free*/    uPower = 1;    /* Compute the exact bit position in the byte */    uPower = uPower << (uInnerIndex - 1);    /* Lock the bus operation before updating the device address map */    OS_WAIT_FOR_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock,                      OS_WAIT_INFINITE);    /*     * If the bit position corresponding to the device address is set then free     * the bit position and update global bus info list and return     * USBHST_SUCCESS.     */    if (uPower ==         (gUSBBusInfoList[uBusIndex].uDeviceAddressMap[uOuterIndex] & uPower))        {        /* Release the address bit in device address map of bus info list */        gUSBBusInfoList[uBusIndex].uDeviceAddressMap[uOuterIndex] =            gUSBBusInfoList[uBusIndex].uDeviceAddressMap[uOuterIndex] &            ~(uPower);        /* Release the lock after updating the device address map */        OS_RELEASE_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock);        OS_LOG_MESSAGE_LOW(USBD,                           "Exiting usbdReleaseAddress() Function.\n",                           0,                           0,                           0,                           0);        return USBHST_SUCCESS;        }    /* Release the lock after updating the device address map */    OS_RELEASE_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock);    OS_LOG_MESSAGE_HIGH(USBD,                        "usbdReleaseAddress() Failed:could not get the given \                            bit position in the device address map.\n",                        0,                        0,                        0,                        0);    /* Could not find the given bit position in the device addressmap */    return USBHST_FAILURE;    } /* End of function usbdReleaseAddress() *//***************************************************************************** usbdIsValidEndpoint - validates the endpoint descriptor** This function is used to validate the endpoint descriptor obtained in* <pEndpointDesc>.** RETURNS: TRUE, FALSE if the endpoint is invalid** ERRNO: None** \NOMANUAL*/LOCAL BOOL usbdIsValidEndpoint    (    pUSBD_DEVICE_INFO           pDeviceInfo,   /* Ptr to device info         */    pUSBHST_ENDPOINT_DESCRIPTOR pEndpointDesc  /* Ptr to endpoint descriptor */    )    {    UINT16 uMaxPacketSize = 0;    /* Max pkt size of the endpoint */    OS_LOG_MESSAGE_LOW(USBD,                       "Entering usbdIsValidEndpoint() Function.\n",                       0,                       0,                       0,                       0);    /* Convert the max packet size to the CPU endian */    uMaxPacketSize = OS_UINT16_LE_TO_CPU(pEndpointDesc->wMaxPacketSize);    /* if the end point transfer type is control */    if (USBHST_CONTROL_TRANSFER == (pEndpointDesc->bmAttributes & 0x03))        {        /* if the device speed if LOW */        if (pDeviceInfo->uDeviceSpeed == USBHST_LOW_SPEED)            {            /* Max packet size should be 8 bytes */            if (uMaxPacketSize != 8)                {                OS_LOG_MESSAGE_HIGH(                    USBD,                    "usbdIsValidEndpoint() Failed Invalid  max packet size.\n",                    0,                    0,                    0,                    0);                /* Invalid max packet size */                return FALSE;                }            } /* End if the device is LOW speed*/        /* if the device speed if FULL */        else if (pDeviceInfo->uDeviceSpeed == USBHST_FULL_SPEED)            {            /* Max packet size should be 8,16,32,64 bytes */            if ((uMaxPacketSize != 8) &&                (uMaxPacketSize != 16) &&                (uMaxPacketSize != 32) &&                (uMaxPacketSize != 64))                {                OS_LOG_MESSAGE_HIGH(                    USBD,                    "usbdIsValidEndpoint() Failed: Invalid max packet size.\n",                    0,                    0,                    0,                    0);

⌨️ 快捷键说明

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