Ejemplo n.º 1
0
/******************************************************************************
  Function:
    USB_DEVICE_RESULT USB_DEVICE_EndpointTransferCancel
    (
        USB_DEVICE_HANDLE usbDeviceHandle,
        USB_ENDPOINT_ADDRESS endpoint,
        USB_DEVICE_TRANSFER_HANDLE transferHandle
    );

  Summary:
    This function cancels a transfer scheduled on an endpoint.

  Description:
    Refer to usb_device.h for usage information.

  Returns:
    Refer to usb_device.h for usage information.

*/
USB_DEVICE_RESULT USB_DEVICE_EndpointTransferCancel
(
    USB_DEVICE_HANDLE usbDeviceHandle,
    USB_ENDPOINT_ADDRESS endpoint,
    USB_DEVICE_TRANSFER_HANDLE transferHandle
)
{
    USB_DEVICE_OBJ* devClientHandle;
    USB_DEVICE_IRP * irp ;
    USB_ERROR irpCancelError;

     /* Validate the handle */
    devClientHandle = _USB_DEVICE_ClientHandleValidate(usbDeviceHandle);
    if (devClientHandle == NULL)
    {
        SYS_DEBUG(0, "USB Device Layer: Invalid Client Handle");
        return(USB_DEVICE_RESULT_ERROR_DEVICE_HANDLE_INVALID);
    }

    if (transferHandle == USB_DEVICE_TRANSFER_HANDLE_INVALID)
    {
        SYS_DEBUG(0, "USB_Device_Endpoint_Transfer_Cancel: Invalid Transfer Handle");
        return USB_DEVICE_RESULT_ERROR;
    }
    irp =  (USB_DEVICE_IRP*)transferHandle;
    if (irp->status == USB_DEVICE_IRP_STATUS_PENDING)
    {
        irpCancelError = USB_DEVICE_IRPCancelAll(devClientHandle,endpoint );
        return irpCancelError;
    }

    SYS_DEBUG(0, "USB_Device_Endpoint_Transfer_Cancel: Transfer could not be cancelled");
    return USB_DEVICE_RESULT_ERROR;

}
Ejemplo n.º 2
0
USB_DEVICE_RESULT USB_DEVICE_EndpointWrite
(
    USB_DEVICE_HANDLE usbDeviceHandle,
    USB_DEVICE_TRANSFER_HANDLE * transferHandle,
    USB_ENDPOINT_ADDRESS endpoint,
    const void * data,
    size_t size,
    USB_DEVICE_TRANSFER_FLAGS flags
)
{
    int count = 0;
    USB_DEVICE_OBJ* devClientHandle;
    USB_ERROR irpSubmitError;
    SYS_MODULE_INDEX deviceInstanceNumber;
    USB_DEVICE_Q_SIZE_ENDPOINT* thisEndpointQueueSize;
    USB_DEVICE_IRP * irp = gUSBDeviceEndpointIRP;
    OSAL_RESULT osalError;
    *transferHandle = USB_DEVICE_TRANSFER_HANDLE_INVALID;


    /* Validate the handle */
    devClientHandle = _USB_DEVICE_ClientHandleValidate(usbDeviceHandle);
    if (devClientHandle == NULL)
    {
        SYS_DEBUG(0, "USB Device Layer: Invalid Client Handle");
        return(USB_DEVICE_RESULT_ERROR_DEVICE_HANDLE_INVALID);
    }

    /* Get Device Instance Number */
    deviceInstanceNumber = devClientHandle->usbDevLayerIndex;

    /* Get Handle to the Endpoint Queue Size structure */
    thisEndpointQueueSize  = &qSizeEndpoint[deviceInstanceNumber];

    /* Make sure that we are with in the queue size for this instance */
    if(thisEndpointQueueSize->qSizeCurrentEpWrite >= thisEndpointQueueSize->qSizeMaxEpWrite)
    {
        SYS_DEBUG(0, "Write Queue is full");
        return(USB_DEVICE_RESULT_ERROR_TRANSFER_QUEUE_FULL);
    }

    /*Obtain mutex to get access to a shared resource, check return value*/
    osalError = OSAL_MUTEX_Lock(&(devClientHandle->mutexEndpointIRP), OSAL_WAIT_FOREVER);
    if(osalError != OSAL_RESULT_TRUE)
    {
      /*Do not proceed lock was not obtained, or error occurred, let user know about error*/
      return (USB_DEVICE_RESULT_ERROR);
    }

    /* Check if the if there is free slot available in queue */
    for(count = 0; count < (USB_DEVICE_ENDPOINT_QUEUE_DEPTH_COMBINED) ; count ++ )
    {
        /* Search for a free IRP */
        if(irp->status <= USB_DEVICE_IRP_STATUS_COMPLETED_SHORT)
        {
            /* We found the IRP. Populate and submit */
            irp->data = (void *)data;
            irp->size = size;
            irp->flags = flags;
            irp->callback = &_USB_DEVICE_EndpointWriteCallBack;
            irp->userData = (uintptr_t)devClientHandle;
            (* transferHandle) = ( USB_DEVICE_TRANSFER_HANDLE )irp;
            (thisEndpointQueueSize->qSizeCurrentEpWrite)++;
            irpSubmitError = USB_DEVICE_IRPSubmit( devClientHandle, endpoint, irp);

            /*Release mutex, done with shared resource*/
            osalError = OSAL_MUTEX_Unlock(&(devClientHandle->mutexEndpointIRP));
            if(osalError != OSAL_RESULT_TRUE)
            {
                /*Do not proceed lock was not obtained, or error occurred, let user know about error*/
                return (USB_DEVICE_RESULT_ERROR);
            }
            return(irpSubmitError);
        }
        irp ++;
    }
    
    /* We could not find a spare IRP */
    SYS_DEBUG(0, "USB Device Endpoint Write: Transfer queue is full");
    return USB_DEVICE_RESULT_ERROR_TRANSFER_QUEUE_FULL;
}
Ejemplo n.º 3
0
USB_DEVICE_RESULT USB_DEVICE_EndpointWrite
(
    USB_DEVICE_HANDLE usbDeviceHandle,
    USB_DEVICE_TRANSFER_HANDLE * transferHandle,
    USB_ENDPOINT_ADDRESS endpoint,
    const void * data,
    size_t size,
    USB_DEVICE_TRANSFER_FLAGS flags
)
{
    int count = 0;
    USB_DEVICE_OBJ* devClientHandle;
    USB_ERROR irpSubmitError;
    SYS_MODULE_INDEX deviceInstanceNumber;
    USB_DEVICE_Q_SIZE_ENDPOINT* thisEndpointQueueSize;
    USB_DEVICE_IRP * irp ;
    OSAL_RESULT osalError;
    *transferHandle = USB_DEVICE_TRANSFER_HANDLE_INVALID;
    OSAL_CRITSECT_DATA_TYPE IntState;


    /* Validate the handle */
    devClientHandle = _USB_DEVICE_ClientHandleValidate(usbDeviceHandle);
    if (devClientHandle == NULL)
    {
        SYS_DEBUG(0, "USB Device Layer: Invalid Client Handle");
        return(USB_DEVICE_RESULT_ERROR_DEVICE_HANDLE_INVALID);
    }

    /* Get Device Instance Number */
    deviceInstanceNumber = devClientHandle->usbDevLayerIndex;

    /* Get Handle to the Endpoint Queue Size structure */
    thisEndpointQueueSize  = &qSizeEndpoint[deviceInstanceNumber];

    /* Make sure that we are with in the queue size for this instance */
    if(thisEndpointQueueSize->qSizeCurrentEpWrite >= thisEndpointQueueSize->qSizeMaxEpWrite)
    {
        SYS_DEBUG(0, "Write Queue is full");
        return(USB_DEVICE_RESULT_ERROR_TRANSFER_QUEUE_FULL);
    }

    /*Obtain mutex to get access to a shared resource, check return value*/
    osalError = OSAL_MUTEX_Lock(&(devClientHandle->mutexEndpointIRP), OSAL_WAIT_FOREVER);
    if(osalError != OSAL_RESULT_TRUE)
    {
      /*Do not proceed lock was not obtained, or error occurred, let user know about error*/
      return (USB_DEVICE_RESULT_ERROR);
    }

    /* Check if the if there is free slot available in queue */
    for(count = 0; count < (USB_DEVICE_ENDPOINT_QUEUE_DEPTH_COMBINED) ; count ++ )
    {
        if(gUSBDeviceEndpointIRP[count].status <
                (USB_DEVICE_IRP_STATUS)USB_DEVICE_IRP_FLAG_DATA_PENDING)
        {
            /* This means the IRP is free. Configure the IRP
             * update the current queue size and then submit */
            irp = &gUSBDeviceEndpointIRP[count]; 
            irp->data = (void *)data;
            irp->size = size;
            irp->flags = flags;
            irp->callback = &_USB_DEVICE_EndpointWriteCallBack;
            irp->userData = (uintptr_t)devClientHandle;
            (* transferHandle) = ( USB_DEVICE_TRANSFER_HANDLE )irp;
            
            /* Prevent other tasks pre-empting this sequence of code */ 
            IntState = OSAL_CRIT_Enter(OSAL_CRIT_TYPE_HIGH);
            (thisEndpointQueueSize->qSizeCurrentEpWrite)++;
            OSAL_CRIT_Leave(OSAL_CRIT_TYPE_HIGH, IntState);
            
            irpSubmitError = USB_DEVICE_IRPSubmit( devClientHandle, endpoint, irp);
            
            /* If IRP Submit function returned any error, then invalidate the
               Transfer handle.  */
            if (irpSubmitError != USB_ERROR_NONE )
            {
                /* Prevent other tasks pre-empting this sequence of code */ 
                IntState = OSAL_CRIT_Enter(OSAL_CRIT_TYPE_HIGH);
                /* Update the read queue size */ 
                (thisEndpointQueueSize->qSizeCurrentEpWrite)--;
                OSAL_CRIT_Leave(OSAL_CRIT_TYPE_HIGH, IntState);
                *transferHandle = USB_DEVICE_TRANSFER_HANDLE_INVALID;
            }
            
            /*Release mutex, done with shared resource*/
            osalError = OSAL_MUTEX_Unlock(&(devClientHandle->mutexEndpointIRP));
            if(osalError != OSAL_RESULT_TRUE)
            {
                /*Do not proceed lock was not obtained, or error occurred, let user know about error*/
                return (USB_DEVICE_RESULT_ERROR);
            }
            return(irpSubmitError);
        }
    }
    
    /*Release mutex, done with shared resource*/
    osalError = OSAL_MUTEX_Unlock(&(devClientHandle->mutexEndpointIRP));
    if(osalError != OSAL_RESULT_TRUE)
    {
        /*Do not proceed, unlock was not completed, or error occurred, let user know about error*/
        return (USB_DEVICE_RESULT_ERROR);
    }
    /* We could not find a spare IRP */
    SYS_DEBUG(0, "USB Device Endpoint Write: Transfer queue is full");
    return USB_DEVICE_RESULT_ERROR_TRANSFER_QUEUE_FULL;
}