Cancelling USB Transfers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cancelling USB Transfers

793 Views
chuckh
Contributor III

I have added a timeout in my code to make sure that my data being sent out on the BULK_IN pipe finishes in a certain time.  If it doesn't, I want to abort the transfer (aka flush it from the pipe).  I've tried using the USB_DCI_Cancel_Transfer/_usb_device_cancel_transfer() function, but that ooesn't seem to work properly.  I would expect that once I call that function, the g_winusb_endpoint_data.ep[index].bin_consumer and g_winusb_endpoint_data.ep[index].bin_producer would once again be equal.  I don't think that is the case.

What is the proper way to flush my pipe from my device?  Do I need to reset the endpoint somehow?


Thanks.

Labels (1)
0 Kudos
Reply
2 Replies

659 Views
chuckh
Contributor III

I've found that this works.  Any reason not to do this?

//Use this to cancel any outgoing USB transfers on a given pipe

uint8_t WinUsbClearSendPipe( uint_8 controller_ID, uint_8 ep_num)

{

  uint8_t status = USB_DCI_Cancel_Transfer(controller_ID, ep_num, USB_SEND);

  //Attempt to cancel transfer and update the consumer pointer

  if(status == USB_OK)

  {

  uint8_t index = USB_Map_Ep_To_Struct_Index(controller_ID, ep_num);

  g_winusb_endpoint_data.ep[index].bin_consumer++;

  }

  return status;

}

0 Kudos
Reply

659 Views
CarlosCasillas
NXP Employee
NXP Employee

Hello Chuck,

If the implementation is based on a consumer-producer scheme, it seems to be a valid procedure, just considering that the data that was previously stored on the buffer will not be deleted until overwriting it with a new transaction.

Anyway, if you are implementing a custom application, you could refer to the precompiled examples included on the installation folder, and compare how the transfers are managed.


Hope this will be useful for you.
Best regards!
/Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply