Author Message
 LOSTISLAND
 Posted: Jun 25, 2012 - 11:16 AM
 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

 jayjay1974
 Posted: Jun 25, 2012 - 12:22 PM
 Joined: Oct 30, 2002 Posts: 5720 Location: The Netherlands
 Those are function pointers. http://en.wikipedia.org/wiki/Function_pointer

 clawson
 Posted: Jun 25, 2012 - 01:18 PM
 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). _________________

 LOSTISLAND
 Posted: Jun 25, 2012 - 06:07 PM
 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.

 Display posts from previous:  All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 Jump to: Select a forum Forum index|--[AVR (8-bit) Technical Forums]|   |-- AVR forum|   |-- XMEGA forum|   |-- AVR Wireless forum|   |-- AVR GCC forum|   |-- AVR Studio 5 and Atmel Studio 6 forum|   |-- AVR studio 4 forum|   |-- AVRfreaks Academy forum|   |-- AVR Tutorials|--[AVR Software Framework]|   |-- AVR Software Framework|--[AVR32 (32-bit) Technical Forums]|   |-- AVR32 Linux Forum|   |-- AVR32 General (standalone)|   |-- AVR32 Software Tools|   |-- AVR32 Hardware|--[General Electronics Technical Forums]|   |-- General Electronics|   |-- Atmel Security Products|--[Non-technical forums]|   |-- AVRfreaks.net Housekeeping|--[Non-topical forums]|   |-- Off-topic forum|   |-- AVRfreaks Trading Post
All times are GMT + 1 Hour