Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

USB software crashes system in high speed



Hello,

I am really hoping someone will point out a dumb error(as usual) in my software and everything will suddenly work. :D

This software is based on the USBSimple example. I modified it to read from an isochronous IN endpoint, and it worked perfectly in full speed mode.

However, when I test my device running in high speed mode, the software crashes the entire computer. I either get a white-on-black system crash error text on my screen and have to turn off the computer, or i get the "reset your computer" message.

It seems like it has something to do with the memory allocation, but like I said the exact same code work in full speed, and I am only allocating 16 bytes with malloc, and handing the buffer to ReadIsochPipeAsync. I use free() at the end.

The weird thing is that the data is read and written to the file, which makes me feel the error happens in free(). I tried removing free but that results in the "reboot your computer error".

I am not sure if this is a problem with my code, or maybe ReadIsochPipeAsync is doing something strange with the buffer.

I have attached my transferData() function where all gets done after the device is open/configured, etc. Everything happens successfully until this point, and i am sure the device is connecting at high-speed according to USB prober. It is also reading all descriptors correctly.

Thanks in advance!

--------------------------------

#define MAX_READ_FRAME 1
#define REQ_COUNT 16
double  endTime = 0;

void
MyCallBackFunction(void *dummy, IOReturn result, void *arg0)
{
//  UInt8	inPipeRef = (UInt32)dummy;

endTime = CFAbsoluteTimeGetCurrent();
printf("MyCallbackfunction: %d, %d, %d\n", (int)dummy, (int)result, (int)arg0);
printf("transferData: END %lf\n", CFAbsoluteTimeGetCurrent());
CFRunLoopStop(CFRunLoopGetCurrent());
}


void transferData(IOUSBInterfaceInterface **intf, UInt8 inPipeRef, UInt8 outPipeRef)
{
IOReturn err;
CFRunLoopSourceRef cfSource;
int i;
UInt64 frame;
AbsoluteTime atTime;
IOUSBIsocFrame frameList[MAX_READ_FRAME];
int file;
double startTime, intervalTime;
UInt32 actCount = 0;
char *inBuf = 0;


inBuf = malloc(MAX_READ_FRAME*REQ_COUNT);
if(inBuf != NULL)
printf("transferData: %d bytes allocated\n", (MAX_READ_FRAME*REQ_COUNT));
else
{
printf("transferData: malloc() error!\n");
return;
}
file = open("USBdump.raw", O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG);
if(!file)
{
printf("transferData: open() failed!\n");
return;
}
else
printf("transferData: open() succeeded\n");

err = (*intf)->CreateInterfaceAsyncEventSource(intf, &cfSource);
if (err)
{
printf("transferData: unable to create event source, err = %08x\n", err);
return;
}
else
printf("transferData: created event source\n");
CFRunLoopAddSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
err = (*intf)->GetBusFrameNumber(intf, &frame, &atTime);
if(err)
{
printf("transferData: GetBusFrameNumber failed err = %08x\n", err);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
return;
}
else
printf("transferData: got frame number\n");
frame = frame + 10;
for(i = 0; i < MAX_READ_FRAME; i++)
{
frameList[i].frStatus = 2;
frameList[i].frReqCount = REQ_COUNT; //Transfer per frame, optimal should be 5x256
}
startTime = CFAbsoluteTimeGetCurrent();
printf("transferData: BEGIN %lf\n", startTime);
err = (*intf)->ReadIsochPipeAsync(intf, inPipeRef, inBuf, frame, (UInt32) MAX_READ_FRAME, frameList, (IOAsyncCallback1)MyCallBackFunction, (void*)(UInt32)inPipeRef);
if (err)
{
printf("transferData: ReadPipeAsyncFailed, err = %08x\n", err);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
return;
}
printf("transferData: calling CFRunLoopRun\n");
CFRunLoopRun();
printf("transferData: returned from CFRunLoopRun\n");
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
for(i = 0; i < MAX_READ_FRAME; i++)
actCount = actCount + frameList[i].frActCount;
write(file, inBuf, actCount);
intervalTime = endTime - startTime;
printf("transferData: %d bytes read in %lf sec = %lf bytes/sec\n", actCount, intervalTime, (double) (actCount/intervalTime));
printf("%d %d %d %d %d %d\n", inBuf[0], inBuf[1], inBuf[2], inBuf[3], inBuf[4], inBuf[5]);
free(inBuf);
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden

This email sent to email@hidden


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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.