Exemplo n.º 1
0
void _USB_DEVICE_AUDIO_IRPCancelAll(USB_DEVICE_AUDIO_INDEX iAudio)
{
    USB_DEVICE_AUDIO_INSTANCE * thisAudioInstance = &gUsbDeviceAudioInstance[iAudio];
    uint8_t noOfStreamingInterface; 
    uint8_t count;
    uint8_t activeInterfaceSetting;
    USB_DEVICE_AUDIO_STREAMING_INTERFACE* streamingInterface;
    uint8_t endpointAddress;

    /* Find out howmany Streaming interfaces are supported by this Audio Instance*/
    noOfStreamingInterface = thisAudioInstance->infCollection.numStreamingInf;

    /* We have to cancel IRPs submitted for all of the streams */
    for (count=0; count < noOfStreamingInterface; count++)
    {
        /* Get pointer current streaing interface */
        streamingInterface = &thisAudioInstance->infCollection.streamInf[count];

        /* Find out active alternate setting*/
        activeInterfaceSetting = streamingInterface->activeSetting;

        if (streamingInterface->alterntSetting[activeInterfaceSetting].numEndPoints)
        {
          /* Retrive Isochronus Data Endpoint address */
          endpointAddress = streamingInterface->alterntSetting[activeInterfaceSetting].isoDataEp.epAddr;

          /* Double if this not Endpoint 0*/
          if (endpointAddress !=0)
          {
            /* Cancel all IRPs on this Endpoint */
            USB_DEVICE_IRPCancelAll(gUsbDeviceAudioInstance[iAudio].devLayerHandle,  endpointAddress);
          }
          if (streamingInterface->alterntSetting[activeInterfaceSetting].numEndPoints == 2)
          {
              /* If there are Two Endpoints, second Endpoint is a Sync Endpoint */
              endpointAddress = streamingInterface->alterntSetting[activeInterfaceSetting].isoSyncEp.epAddr;

              /* Double if this not Endpoint 0*/
              if (endpointAddress !=0)
              {
                /* Cancel all IRPs on this Endpoint */
                USB_DEVICE_IRPCancelAll(gUsbDeviceAudioInstance[iAudio].devLayerHandle,  endpointAddress);
              }
          }
        }
        
    }
}
Exemplo n.º 2
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;

}
Exemplo n.º 3
0
void _USB_DEVICE_CDC_EndpointDisable
(
    USB_DEVICE_HANDLE deviceHandle, 
    USB_DEVICE_CDC_ENDPOINT * deviceCDCEndpoint
)
{
    if(deviceCDCEndpoint->isConfigured)
    {
        USB_DEVICE_IRPCancelAll(deviceHandle, deviceCDCEndpoint->address);
        USB_DEVICE_EndpointDisable(deviceHandle, deviceCDCEndpoint->address);
        deviceCDCEndpoint->isConfigured = false;
    }
}
Exemplo n.º 4
0
/* Function:
   void _USB_DEVICE_AUDIO_SetupPacketHandler
   (
       USB_DEVICE_AUDIO_INDEX iAudio ,
       USB_SETUP_PACKET * setupPkt
   )

  Summary:
    Handles a fresh SETUP packet received from Host.

  Description:
    Handles a fresh SETUP packet received from Host.

  Returns:
    This is a local function and should not be called directly by the
    application.
*/
void _USB_DEVICE_AUDIO_SetupPacketHandler 
(
    USB_DEVICE_AUDIO_INDEX iAudio , 
    USB_SETUP_PACKET * setupPkt
)
{
    uint8_t audioControlInterfaceId;
    uint8_t interfaceId;
    uint8_t curAlternateSetting;
    uint8_t prevAlternateSetting;
    uint8_t streamIntfcIndex;
    uint8_t noOfEndpoints;
    USB_ENDPOINT ep; 
    uint16_t maxPacketSize;
    USB_DEVICE_HANDLE usbDeviceHandle;
    USB_DEVICE_AUDIO_EVENT event;
    USB_DEVICE_AUDIO_EVENT_DATA_INTERFACE_SETTING_CHANGED interfaceInfo;
    USB_ERROR endpointEnableResult; 
    USB_DEVICE_AUDIO_STREAMING_INTERFACE_ALTERNATE_SETTING *pCurAlternateStng;
    USB_DEVICE_AUDIO_STREAMING_INTERFACE_ALTERNATE_SETTING *pPrevAlternateStng;
    USB_DEVICE_AUDIO_STREAMING_INTERFACE *pStreamingInterface;
    
    uint16_t adjustedMaxPacketSize =1;

    /* Obtain pointer to the Audio Instance that is being addressed*/
    USB_DEVICE_AUDIO_INSTANCE* audioInstance = &gUsbDeviceAudioInstance[iAudio];

    /* Obtain pointer to the Audio Interface collection*/
    USB_DEVICE_AUDIO_INTERFACE_COLLECTION *curInfCollection =
            &(audioInstance->infCollection);

    /* Get the Device Layer handle */
    usbDeviceHandle = gUsbDeviceAudioInstance[iAudio].devLayerHandle;
    
    /* Check if the request is a standard interface request*/
    if (  (setupPkt->RequestType == USB_SETUP_REQUEST_TYPE_STANDARD)
       && (setupPkt->Recipient == USB_SETUP_REQUEST_RECIPIENT_INTERFACE))

    {
        /* We have received Standard Set request */

        /* retrieve interface number from the Setup packet */
        interfaceId = setupPkt->bIntfID;

        /* retrieve audio Control interface number*/
        audioControlInterfaceId = curInfCollection->bControlInterfaceNum;
        
        switch(setupPkt->bRequest)
        {
            case USB_REQUEST_SET_INTERFACE:
                curAlternateSetting = setupPkt->bAltID;
                if (interfaceId == audioControlInterfaceId)
                {
                    /*SET INTERFACE command was received to Audio Control
                      Interface */
                    curInfCollection->bControlAltSetng = curAlternateSetting;
                }
                else
                {
                    /*An Audio Streaming interface has received SET INTERFACE
                      command */
                    streamIntfcIndex = interfaceId - audioControlInterfaceId - 1;

                    /* Get pointer to the current audio streaming interface */
                    pStreamingInterface = &(curInfCollection->streamInf[streamIntfcIndex]);
                    
                    /* Get pointer to the Interface Alternate setting. */
                    pCurAlternateStng
                    = &(pStreamingInterface->alterntSetting[curAlternateSetting]);
                    
                    /* Find out how many endpoint are present for this Interface
                     * Alternate setting */
                    noOfEndpoints = pCurAlternateStng->numEndPoints;

                    if ((noOfEndpoints) && (curAlternateSetting))
                    {
                        /* We have to enable the endpoint only if this alternate
                         setting has at least one endpoint and the alternate
                         setting is a non zero value */
                        
                        /*Retrieve endpoint size */
                        ep = pCurAlternateStng->isoDataEp.epAddr;
                        
                        /* retrieve max packet size. */
                        maxPacketSize
                             = pCurAlternateStng->isoDataEp.epMaxPacketSize;

                        /* maxpacket size should be adjusted to upper power of
                           two. As per the PIC32MZ USB module requirement.*/
                        if (maxPacketSize)
                        {
                            while(adjustedMaxPacketSize < maxPacketSize)
                                adjustedMaxPacketSize <<= 1;
                        }
                        else
                            adjustedMaxPacketSize = 0;
                        /* Enable Isochronous Data Endpoint */
                        endpointEnableResult = USB_DEVICE_EndpointEnable
                        (
                            usbDeviceHandle ,
                            0,
                            ep ,
                            USB_TRANSFER_TYPE_ISOCHRONOUS ,
                            adjustedMaxPacketSize
                        );
                        if (endpointEnableResult != USB_ERROR_NONE)
                        {
                            SYS_ASSERT (false, "Endpoint not Enabled");
                        }

                        if (noOfEndpoints == 2)
                        {
                            /* If number of Endpoints is Two, then it is sure
                             * that this alternate setting reports a Isochronous
                             * Sync Endpoint. Enable the Sync Endpoint. */
                        }

                        //Change Audio Instance object state to Initialized.
                        pStreamingInterface->state
                                    = USB_DEVICE_AUDIO_STRMNG_INTFC_INITIALIZED;
                    }
                    else //alternateSetting  = 0
                    {
                        if (pStreamingInterface->state
                                   == USB_DEVICE_AUDIO_STRMNG_INTFC_INITIALIZED)
                        {
                            //Disable the Endpoint in the previous Active Alternate setting.
                            prevAlternateSetting = pStreamingInterface->activeSetting;

                            //get a pointer to the previous alternate setting.
                            pPrevAlternateStng = &(pStreamingInterface->alterntSetting[prevAlternateSetting]);

                            //Get endpoint no of the previous alternate setting
                            ep = pPrevAlternateStng->isoDataEp.epAddr;

                            //Disable the Endpoint
                            USB_DEVICE_EndpointDisable(usbDeviceHandle ,ep);


                            if (noOfEndpoints == 2)
                            {
                                /* If number of Endpoints is Two, then it is sure
                                * that this alternate setting reports a Isochronous
                                * Sync Endpoint. Disable the Sync Endpoint. */
                            }
                            curInfCollection->streamInf[streamIntfcIndex].state
                                = USB_DEVICE_AUDIO_STRMNG_INTFC_NOT_INITIALIZED;
                            USB_DEVICE_IRPCancelAll(usbDeviceHandle,  ep);
                        }  
                    }

                    /* Remember the new alternate setting received */
                    curInfCollection->streamInf[streamIntfcIndex].activeSetting 
                    = curAlternateSetting;


                    /* Notify application about the SET_INTERFACE request */
                    interfaceInfo.interfaceNumber = interfaceId;
                    interfaceInfo.interfaceAlternateSetting = curAlternateSetting;
                    audioInstance->appEventCallBack
                    (
                        iAudio,
                        USB_DEVICE_AUDIO_EVENT_INTERFACE_SETTING_CHANGED,
                        &interfaceInfo,
                        0
                    );
                }
                /* Send an Acknowledgement to the Host */ 
                USB_DEVICE_ControlStatus( usbDeviceHandle,
                                USB_DEVICE_CONTROL_STATUS_OK);
            break;
            case USB_REQUEST_GET_INTERFACE:
                if (interfaceId == audioControlInterfaceId)
                {
                    curAlternateSetting = curInfCollection->bControlAltSetng;
                }
                else
                {
                    streamIntfcIndex = interfaceId - audioControlInterfaceId - 1;
                    curAlternateSetting
                    = curInfCollection->streamInf[streamIntfcIndex].activeSetting;
                }

                USB_DEVICE_ControlSend( usbDeviceHandle,
                        (void *)&curAlternateSetting, 1);
                break;
            default:
                break;

        }      
    }//end of if((setupPkt->bmRequestType ==
    else if ( (setupPkt->RequestType == USB_SETUP_REQUEST_TYPE_CLASS )
            && (setupPkt->Recipient == USB_SETUP_REQUEST_RECIPIENT_INTERFACE))
    {
        /* We have recived a Audio Class specific Interface request */
        switch (setupPkt->bRequest)
        {
            case USB_AUDIO_CS_SET_CUR:
                event = USB_DEVICE_AUDIO_EVENT_CONTROL_SET_CUR;
                break;
            case USB_AUDIO_CS_GET_CUR:
                event = USB_DEVICE_AUDIO_EVENT_CONTROL_GET_CUR;
                break;
            case USB_AUDIO_CS_SET_MIN:
                event = USB_DEVICE_AUDIO_EVENT_CONTROL_SET_MIN;
                break;
            case USB_AUDIO_CS_GET_MIN:
                event = USB_DEVICE_AUDIO_EVENT_CONTROL_GET_MIN;
                break;
            case USB_AUDIO_CS_SET_MAX:
                event = USB_DEVICE_AUDIO_EVENT_CONTROL_SET_MAX;
                break;
            case USB_AUDIO_CS_GET_MAX:
                event = USB_DEVICE_AUDIO_EVENT_CONTROL_GET_MAX;
                break;
            case USB_AUDIO_CS_SET_RES:
                event = USB_DEVICE_AUDIO_EVENT_CONTROL_SET_RES;
                break;
            case USB_AUDIO_CS_GET_RES:
                event = USB_DEVICE_AUDIO_EVENT_CONTROL_GET_RES;
                break;
            case USB_AUDIO_CS_SET_MEM:
                event = USB_DEVICE_AUDIO_EVENT_ENTITY_SET_MEM;
                break;
            case USB_AUDIO_CS_GET_MEM:
                event = USB_DEVICE_AUDIO_EVENT_ENTITY_GET_MEM;
                break;
            case USB_AUDIO_CS_GET_STAT:
                event = USB_DEVICE_AUDIO_EVENT_ENTITY_GET_STAT;
                break;
            default:
            /* Unknown request. Stall the request */
                event = 0;
                USB_DEVICE_ControlStatus(audioInstance->devLayerHandle,
                                               USB_DEVICE_CONTROL_STATUS_ERROR);
        }
        if (( audioInstance->appEventCallBack) && (event))
        {
            /* inform the application about the request */
            /* the application needs to handle both EP and entity specific 
               requests */
           audioInstance->appEventCallBack ( iAudio, event, setupPkt, 0);
        }        
    }// end of else if
}//end of function _USB_DEVICE_AUDIO_SetupPacketHandler