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 Isochronous Pipe



Hello,

I am trying to read an isochronous pipe in MacOS X. My code was written based on "USBSimpleExample". Functions such as "main", "dealWithDevice" , "dealWithInterface" and "dealWithPipes" are not rewritten almost. I succeeded in obtaining interface information of the pipe. But I cannot obtain a data from the pipe. Though I expect that there are problems in isocCallback and startISO, I cannot find it. I am looking for some informations to solve the problem. Especially, I need informations about functions such as "ReadIsochPipeAsync" and "CFRunLoopRun".

I hope someone can help me.

--
#include <stdio.h>
#include <mach/mach.h>
#include <CoreFoundation/CFNumber.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/usb/IOUSBLib.h>

#define ISO_PIPEREF 1	// iso pipe
#define ISO_PIPESIZE 64	//  iso endpoint packet size
#define ISO_REQCOUNT 1	// concurrent active requests
#define ISO_REQFRAMES 8	// frames per request
#define ISO_FUTURE 0	// delay to first frame
#define FRAME_COUNT 10

mach_port_t masterPort = 0;	// requires <mach/mach.h>
char utBuf[8096];
char inBuf[8096];
unsigned frameCounter = 0;
UInt64 nextFrame;

typedef struct
{
IOUSBInterfaceInterface **interface;
IOUSBIsocFrame frames[ISO_REQFRAMES];
UInt8 buffer[ISO_REQFRAMES * ISO_PIPESIZE];
} IsoRequest;

static IsoRequest isoRequests[ISO_REQCOUNT];

void isocCallback(IsoRequest *transfer, IOReturn result, void *extra)
{
int errs = 0, frame;

if(result != kIOReturnSuccess){
printInterpretedError("isocCallback with status", result);
if(result == kIOReturnUnderrun){
for(frame = 0; frame < ISO_REQFRAMES; frame++){
if(transfer->frames[frame].frReqCount != transfer->frames[frame].frActCount){
if(errs++ < 5){
fprintf(stderr, "Frame %d, req:%d, act:%d\n", frame, transfer->frameList[frame].frReqCount, transfer->frameList[frame].frActCount);
}
}
}
fprintf(stderr, "%d errs\n", errs);
}
}
else{
fprintf(stderr, "isocCallback with good status\n");
}
}


void startISO(IOUSBInterfaceInterface **intf)
{
IOReturn err;			
UInt8 direction, number, transferType, interval;
UInt16 maxPacketSize;
Unsigned i,j;
AbsoluteTime time;
CFRunLoopSourceRef source;
Double startTime =0, endTime = 0;
//long test_int=0;
UInt8 test_data[ISO_REQCOUNT][ISO_REQFRAMES * ISO_PIPESIZE];

err = (*intf)->GetPipeProperties(intf, ISO_PIPEREF, &direction, &number, &transferType, &maxPacketSize, &interval);
if (err)
{
printf("startISO: unable to get pipe properties for pipe %d, err = %08x€\n", ISO_PIPEREF, err);
return;
}


if(transferType!=kUSBIsoc || interval!=1 || maxPacketSize!=ISO_PIPESIZE || direction!=kUSBIn)
{
printf("startISO: pipe %d is unexpected type€n\n", ISO_PIPEREF);
return;
}
printf("startISO: pipe %d is OK\n", ISO_PIPEREF);


err = (*intf)->CreateInterfaceAsyncEventSource(intf, &source);
if (err){
printf("startISO: unable to create event source, err = %08x€\n", err);
return;
}

CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);

err = (*intf)->GetBusFrameNumber(intf,&nextFrame,&time);
if (err){
printf("startISO: can't get current frame,  err = %08x€\n", err);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
return;
}

frameCounter = 0;

for(i=0;i<ISO_REQCOUNT;i++)
{
isoRequests[i].interface = intf;

for(j=0;j<ISO_REQFRAMES;j++)
{
isoRequests[i].frames[j].frStatus=2;
isoRequests[i].frames[j].frReqCount=ISO_PIPESIZE;
isoRequests[i].frames[j].frActCount=0;
}
err = (*intf)->ReadIsochPipeAsync(intf,ISO_PIPEREF,isoRequests[i].buffer,nextFrame,ISO_REQFRAMES,isoRequests[i].frames, isoCallback, &isoRequests[i]);
if (err){
printf("startISO: ReadISochPipeAsync failed, err = %08x€\n", err);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
return;
}
nextFrame+=ISO_REQFRAMES;
}
printf("startISO: starting runloop\n");
CFRunLoopRun();
printf("startISO: runloop exited\n");


CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);

}

--
Tomoaki MARUYAMA

_______________________________________________
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.