Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Slow pipe operation..... it continues to drive me crazy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Slow pipe operation..... it continues to drive me crazy



Hi everyone,

While reviewing Fernando's code suggestion I realized that I had implemented this solution already. So nothing new was being presented.

However, I took this chance to review the code and refactor it to make it more versatile as Fernando's suggestion is, in terms of concurrent read submission (with the for loop for submission and the refcon passing).

While doing this refactor I realized that I had 2 things terribly wrong in my code:

- I was reading 4096 bytes to a 64 length FRAME_PACKET struture which is 64 length. But I was omly processing 16 of this units........ That explains the missing data. This is because in libusb there are two parameters passed to transfers. Buffer size and transfer length. Here is simpler.

- The variable that counts the usefull bytes from my packets (for a frame constitution) was declared as non static, so it was becoming 0 every transfer callback call. No frames were actually being processed at all.

Basicly I had already the code well since the first time I wrote to the list with sync readings in what regards to USB communication.


Now I just have to thank you for the time you spent helping me. It was not a waste of time because this problem was also usefull to learn how to make async calls to USB bus in OSX.


This API is very simple to use. Great work!

Once again thx for the support.

With my best regards,

Nuno



On 05/20/2010 09:05 PM, Fernando Urbina wrote:
You can do something like this -- note, this is not complete, but it does show you how to queue up the multiple reads:

typedef struct
{
	UInt32		size;
	void *		buffer;
} MyRefconData;

MyRefconData			gTheData[kNumberOfConcurrentTransfers];
CFRunLoopSourceRef		gCFSource;
IOUSBInterfaceInterface245**	gInterface;
UInt8				gPipeRef = 0;

//================================================================================================
//
//	MyAsyncCallBackFunction
//
//	Called when our asynchronous read completes
//
//================================================================================================
//
void
MyAsyncCallBackFunction(void *refCon, IOReturn result, void *arg0)
{
	IOReturn						kr = kIOReturnSuccess;
     	MyRefconData *					myData = ( MyRefconData *) refCon;

	// At this point, we would do something with this data, like looking for a SOF

	// Process the Data received	

	// Re-issue the read
	kr = (**gInterface).ReadPipeAsync(	gInterface,			//
						gPipeRef,			// pipeRef
						myData->buffer,			// * buf
						myData->size,			// size,
						MyAsyncCallBackFunction,	// Callback
						refCon);			// Refcon

	return;
}


//================================================================================================ // // ReadFromPipeAsync // // Will issue multiple reads to the given pipe // //================================================================================================ // IOReturn ReadFromPipeAsync() { IOReturn kr; // First, we need to create an async event source and add it to our runloop // kr = (*gInterface)->CreateInterfaceAsyncEventSource(gInterface,&gCFSource); require_string(kr == kIOReturnSuccess, Exit, USBErrorToString(kr)); CFRunLoopAddSource(CFRunLoopGetCurrent(), gCFSource, kCFRunLoopDefaultMode); for ( UInt32 i = 0; i< kNumberOfConcurrentTransfers; i++) { // Fill out our refcon gTheData[i].buffer = XXXXX; gTheData[i].size = YYYY; // Queue up the first read kr = (**gInterface).ReadPipeAsync( gInterface, // gPipeRef, // pipeRef gTheData[i].buffer, // * buf gTheData[i].size, // size, MyAsyncCallBackFunction, // Callback (void *)&gTheData[i]); // Refcon if ( kr != kIOReturnSuccess ) { printf("ReadIsochPipeAsync returns 0x%x\n",kr); } } Exit: return kIOReturnSuccess; }


_______________________________________________ Do not post admin requests to the list. They will be ignored. Usb mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Slow pipe operation..... it continues to drive me crazy (From: email@hidden)
 >Re: Slow pipe operation..... it continues to drive me crazy (From: Fernando Urbina <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.