Page 1 of 1

main.c on v-usb

Posted: Tue Oct 25, 2011 6:41 am
by ardiansyah_mrit
any one i need help about below meaning code :

Code: Select all

uchar   usbFunctionRead(uchar *data, uchar len) //??????????????? *data dan len
{
    if(len > bytesRemaining)
        len = bytesRemaining;
    eeprom_read_block(data, (uchar *)0 + currentAddress, len);
    currentAddress += len;
    bytesRemaining -= len;
    return len;
}


i'm not understand about "(uchar *data, uchar len)"..??

Re: main.c on v-usb

Posted: Tue Oct 25, 2011 12:05 pm
by Daid
Then learn a bit about C before you touch micro-controllers.

Re: main.c on v-usb

Posted: Thu Nov 10, 2011 1:34 am
by 1.21Gigawatts
uchar is how some compilers designate an unsigned char, equivalent to winavr's uint8_t.

Does that help?

Re: main.c on v-usb

Posted: Thu Nov 10, 2011 3:12 am
by ulao
uchar *data : This is nothing more then a pointer to address in memory. uchar ( unsigned char ) is the size you need to hold that address. Pointers are a big part of C, I suggest you read up on them.

uchar len : Here we are setting len to a type uchar ( not a pointer this time ). len will be the length of the data in this case.

So you use data to point to the data in memory and len to figure out how long the data goes.

If len was 2
data -> [byte 0][byte 1]

Re: main.c on v-usb

Posted: Thu Nov 10, 2011 9:58 am
by ardiansyah_mrit
thank's all for reply's,

i undenrstand now, but can you explain to me about uchar len in this function and uchar len in usbfunctionWrite()..??

is there any difference between these two variables ?

what the meaning about
len was 2 => [byte 0] [byte 1]...??

best regard

Re: main.c on v-usb

Posted: Thu Nov 10, 2011 6:45 pm
by 1.21Gigawatts
Oh, you really do need to do some reading about the C language before you go any further. Particularly, your question about the two len variables points to a lack of understanding about a variable's scope. There's plenty of tutorials on the web, or you can get any number of books. But you're going to be lost if you just try to dice into this code.