Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
LOSTISLAND
PostPosted: Jun 25, 2012 - 11:16 AM
Hangaround


Joined: May 05, 2010
Posts: 200


Hi all,
Could anyone say what’s happening here ?
Is there any tutorial explaining how to make use of pointers in this way ?

Code:
#define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)

/* USB Endpoint Events Callback Pointers */
void (* const USB_P_EP[16]) (uint32_t event) = {
  P_EP(0),
  P_EP(1),
  P_EP(2),
  P_EP(3),
  P_EP(4),
  P_EP(5),
  P_EP(6),
  P_EP(7),
  P_EP(8),
  P_EP(9),
  P_EP(10),
  P_EP(11),
  P_EP(12),
  P_EP(13),
  P_EP(14),
  P_EP(15),
};

Thanks in advanced
 
 View user's profile Send private message  
Reply with quote Back to top
jayjay1974
PostPosted: Jun 25, 2012 - 12:22 PM
Raving lunatic


Joined: Oct 30, 2002
Posts: 5720
Location: The Netherlands

Those are function pointers.

http://en.wikipedia.org/wiki/Function_pointer
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jun 25, 2012 - 01:18 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62324
Location: (using avr-gcc in) Finchingfield, Essex, England

The form of a function pointer definition is:
Code:
return-type (*name_of_fn_ptr)(input-type [varname], input-type [varname]...)

The simplest would be for a function of the form:
Code:
void a_function(void);

in which case the definition of a pointer to this kind of function would be:
Code:
void (* ptr)(void);

and now you could say:
Code:
ptr = a_function;

and assign the address of a_function() to that variable. If a_function were more complex:
Code:
int a_function(long l, char * array);

then the function pointer definition would need to be more complex:
Code:
int (* ptr)(long, char 8);

and once again you could use:
Code:
ptr = a_function;

Now if you wanted to create a load of function pointers in an array you just add an index to it:
Code:
int (* ptr[8])(long, char 8);

So ptr[] is an array of 8 pointers to functions that return an int and take a long and a char pointer. You could then say:
Code:
ptr[3] = a_function;
ptr[7] = another_function; // of that same type
and so on

BTW is the above code you quote from LUFA or ASF by any chance? End point call backs are a bit like "soft interrupts". It gives the USB stack the chance to call back a function you can provide if you need to know when a certain even has occurred (such as data arriving on an endpoint).

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
LOSTISLAND
PostPosted: Jun 25, 2012 - 06:07 PM
Hangaround


Joined: May 05, 2010
Posts: 200


Thanks alot ,
Quote:
BTW is the above code you quote from LUFA or ASF by any chance? End point call backs are a bit like "soft interrupts". It gives the USB stack the chance to call back a function you can provide if you need to know when a certain even has occurred (such as data arriving on an endpoint).

It's from USBHID sample of CMSIS for LPC17xx on uVision4 IDE.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits