Re: Gadgetfs question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 29 Jun 2010, Martinez, Aldo wrote:

> Hello everyone
> I'm trying to make a driver that, for now, just answers depending 
> on what is sent OUT from the host. 

Like the g_zero gadget in loopback mode?

> The problem is that apparently gadgetfs has a queue with the 
> usb_requests.

Why is that a problem?  After all, USB data should be sent over the bus 
in the order given by the gadget driver, which means it should be 
stored in a queue, right?

> So whatever I send to the driver I get the answer after 
> asking 2 or 3 times, i.e., I have to make two or three IN bulk transfers to get 
> what I want. 

Then it sounds like you've got a bug in your driver.

> I did some simple modifications to the usb.c example driver found in
> linux-usb.org. I used a global variable to access it from both threads:
> static char *buffer;
> 
> In empty_out_buf function I do a simple switch to assing value to the 
> global buffer depending on the value sent out by the host:
> 
>         switch (((char *)buf)[0]) {
>                 case 0x01:
>                         printf("case 0x01\n");
>                         memset(buffer, '1', nbytes);
>                         break;
>                 case 0x02:
>                         printf("case 0x02\n");
>                         memset(buffer, '2', nbytes);
>                         break;
>                 default:
>                         printf("case default\n");
>                         memset(buffer, 'd', nbytes);
>                         break;
>         }
> 
> The other modification was in simple_source_thread function. Where
> the "buffer" variable created by me is sent instead of the local 
> buf variable:
> status = write(source_fd, buffer, USB_BUFSIZE);
> 
> I'm using libusb to test on the host side, with the following functions: 
> libusb_bulk_transfer (devHandle, BULK_OUT, buffer, bufferSize, 
> 			&transferred, 500);
> libusb_bulk_transfer (devHandle, BULK_IN, buffer, bufferSize, 
> 			&transferred, 500);
> 
> When using a buffer size of 511 bytes or less until the third IN 
> bulk transfer I get, e.g., in case 0x01 the '1' I assigned before. 
> When the buffer size is of 512 or more I get the assigned value 
> in the second transfer.
> 
> Here is the usbmon trace, USB_BUFSIZE 511:
> f2adf880 32307.036783 S Bi:1:090:1 - 511 <
> f2adf880 32307.036843 C Bi:1:090:1 0 511 = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Here the host gets a reply without sending any data first.  That seems
like a bug, since your driver is supposed to answer depending on what
it receives from the host.  It may be the cause of your other problems.

> f2a78100 32333.300397 S Bo:1:090:1 - 511 = 01010101 01010101 01010101 01010101 01010101 01010101 01010101 01010101
> f2a78100 32333.300472 C Bo:1:090:1 0 511 >
> f2a30500 32349.364816 S Bi:1:090:1 - 511 <
> f2a30500 32349.364975 C Bi:1:090:1 0 511 = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> f2ba3400 32350.468457 S Bi:1:090:1 - 511 <
> f2ba3400 32350.468601 C Bi:1:090:1 0 511 = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> f2a97680 32351.268549 S Bi:1:090:1 - 511 <
> f2a97680 32351.268600 C Bi:1:090:1 0 511 = 31313131 31313131 31313131 31313131 31313131 31313131 31313131 31313131
> 
> USB_BUFSIZE 512:
> f2b86600 35192.622809 S Bi:1:091:1 - 512 <
> f2b86600 35192.622879 C Bi:1:091:1 0 512 = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> f2bd2280 35196.388595 S Bo:1:091:1 - 512 = 01010101 01010101 01010101 01010101 01010101 01010101 01010101 01010101
> f2bd2280 35196.388756 C Bo:1:091:1 0 512 >
> f6612080 35198.996722 S Bi:1:091:1 - 512 <
> f6612080 35198.996754 C Bi:1:091:1 0 512 = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> f2922680 35200.028271 S Bi:1:091:1 - 512 <
> f2922680 35200.028381 C Bi:1:091:1 0 512 = 31313131 31313131 31313131 31313131 31313131 31313131 31313131 31313131
> 
> 
> I've also noticed that when "usb" binary it first initialized it calls
> fill_in_buf function (1 or 2 depending on the buffer size as specified
> before).
> 
> Is there a form to flush the queue?

There's GADGETFS_FIFO_FLUSH.  (Really, you do need to read through the
relevant #include files before trying to do any serious programming.)  
It may not do what you want, however.

> Or how can I access 
> the information I want right in the next transfer?

That question is not well defined.  What exactly are you trying to
accomplish?  Try to be precise.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux