usbFunctionSetup - 8 Bytes?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Guest

usbFunctionSetup - 8 Bytes?

Post by Guest » Thu Sep 23, 2010 10:27 am

Code: Select all

 usbMsgLen_t usbFunctionSetup(uchar setupData[8])
{
    usbRequest_t *rq = (void *)setupData;   // cast to structured data for parsing
    switch(rq->bRequest){
    case 1:
        setLEDStatus(rq->wValue.bytes[0]);  // evaluate low byte only
        return 0;                           // no data block sent or received
    }
    return 0;                               // ignore all unknown requests
}


I know this is basic stuff,I'm trying to figure out how this function receives 8 separate bytes and stores it in to this structure:

Code: Select all

 typedef struct usbRequest{
    uchar       bmRequestType;
    uchar       bRequest;
    usbWord_t   wValue;
    usbWord_t   wIndex;
    usbWord_t   wLength;
}usbRequest_t;


My guess is that it takes 1 byte at a time until an ACK is received. Each time a byte is received how is the data parsed separately into its appropriate place?

Code: Select all

switch(rq->bRequest)

Does this line point to the structure usbRequest and not usbRequest_t?

_frank26080115

Re: usbFunctionSetup - 8 Bytes?

Post by _frank26080115 » Thu Sep 23, 2010 5:55 pm

The casting is done where it says "usbRequest_t *rq = (void *)setupData; // cast to structured data for parsing"

the structure of type "usbRequest_t" is 8 bytes long, thus you can easily obtain the request from this 8 bytes of data that is received by "usbFunctionSetup", that's what casting does, http://en.wikipedia.org/wiki/Type_conversion


My guess is that it takes 1 byte at a time until an ACK is received. Each time a byte is received how is the data parsed separately into its appropriate place?


This is wrong, the 8 bytes have already been received by the time that "usbFunctionSetup" is called.

Does this line point to the structure usbRequest and not usbRequest_t?


I don't understand this question because the word "usbRequest" does not appear anywhere. "usbRequest_t" is the name given to the structure type, while "rq" is the name given to a pointer that points to an instance of "usbRequest_t" converted from "setupData", and "bRequest" is a member of the "usbRequest_t" structure that "rq" is pointing at.

jay.elle
Posts: 13
Joined: Tue Aug 17, 2010 11:12 am

Re: usbFunctionSetup - 8 Bytes?

Post by jay.elle » Fri Sep 24, 2010 12:09 am

This is wrong, the 8 bytes have already been received by the time that "usbFunctionSetup" is called.


Thanks Frank,

Could you please note some function that does this in the code and/or provide a simple explanation?
--
The wiki provides a very good explanation and shows great usage examples, but it's very high level and leaves me asking a lot of questions.

I'm unsure of how to understand and make use of this code, meaning do i use it as something high level / functions or would there be great benefit to understand all of the functions?

_frank26080115

Re: usbFunctionSetup - 8 Bytes?

Post by _frank26080115 » Sat Sep 25, 2010 2:58 am

read http://www.beyondlogic.org/usbnutshell/ ... etupPacket

actually, read all the chapters

jay.elle
Posts: 13
Joined: Tue Aug 17, 2010 11:12 am

Re: usbFunctionSetup - 8 Bytes?

Post by jay.elle » Sat Sep 25, 2010 4:43 am

_frank26080115 wrote:read http://www.beyondlogic.org/usbnutshell/ ... etupPacket

actually, read all the chapters



I did read all of the chapters. I think I need to study the code, just not too sure of how much because i'll start wondering how the asm code works.

_frank26080115

Re: usbFunctionSetup - 8 Bytes?

Post by _frank26080115 » Sun Sep 26, 2010 5:12 am

I have no idea what you don't understand, is it the typecasting?

jay.elle
Posts: 13
Joined: Tue Aug 17, 2010 11:12 am

Re: usbFunctionSetup - 8 Bytes?

Post by jay.elle » Mon Oct 04, 2010 3:19 pm

_frank26080115 wrote:I have no idea what you don't understand, is it the typecasting?


I got way ahead of myself and tried to take in too much information. I didn't even build the project and mess with it at that point, which is what i'm doing right now.
---
So far i flashed my metaboard with the custom class example that ships with the driver, but i can't build the host side application.

I started with libusb1.0 and realized i needed the legacy version so i backtracked all the way to libusb-0.1.10a. Everything seemed to install fine and my project can find usb.h, but now i've got different errors and i have no idea what they mean :? any ideas?

Code: Select all

Samantha-Darkos-Mac-Pro:commandline SamanthaDarko$ gcc set-led.c
Undefined symbols:
  "_usb_close", referenced from:
      _main in ccdDCuMX.o
  "_usbOpenDevice", referenced from:
      _main in ccdDCuMX.o
  "_usb_init", referenced from:
      _main in ccdDCuMX.o
  "_usb_control_msg", referenced from:
      _main in ccdDCuMX.o
      _main in ccdDCuMX.o
  "_usb_strerror", referenced from:
      _main in ccdDCuMX.o
      _main in ccdDCuMX.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Samantha-Darkos-Mac-Pro:commandline SamanthaDarko$


Do i have to do something with the makefile?

Thanks,

jay.elle
Posts: 13
Joined: Tue Aug 17, 2010 11:12 am

Re: usbFunctionSetup - 8 Bytes?

Post by jay.elle » Mon Oct 04, 2010 8:31 pm

omg it works!

i dont know anything about linux if it isn't that obvious. doing a make all "compiled?" a program for me which i was able to run from the terminal.

can anyone make a suggestion on what i should do next? my gut tells me to mess around with the functions.

Post Reply