How does Init(LDD_TUserData *UserDataPtr) work

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How does Init(LDD_TUserData *UserDataPtr) work

Jump to solution
1,568 Views
pratiekbhadrana
Contributor III

I have been analysing the generated code from PEx for a while now. The Init() function returns a pointer to the private structure/device structure. Which we then use for all subsequent methods as the first parameter in order to specify which device is being called.

 

BUT - where does the *UserDataPtr come from? I searched in the components ".c" as well as ".h" file. It must be something I overlooked, but now I am really not getting where this pointer comes from. Or is it that a Null Pointer need not be declared and initialized?

 

If you need any more details, please let me know I will post screenshots.

 

Thanks

Labels (1)
0 Kudos
Reply
1 Solution
1,183 Views
BlackNight
NXP Employee
NXP Employee

That UserDataPtr comes from your application. You can pass NULL if you don't need such a pointer.

That pointer points to your own data structure where you can have in it whatever you want/need.

For example you can initialize device, and add with the user data pointer your own data to the device handle.

Whenever you get callbacks, you can then get that data through that pointer.

Erich

View solution in original post

0 Kudos
Reply
4 Replies
1,184 Views
BlackNight
NXP Employee
NXP Employee

That UserDataPtr comes from your application. You can pass NULL if you don't need such a pointer.

That pointer points to your own data structure where you can have in it whatever you want/need.

For example you can initialize device, and add with the user data pointer your own data to the device handle.

Whenever you get callbacks, you can then get that data through that pointer.

Erich

0 Kudos
Reply
1,183 Views
pratiekbhadrana
Contributor III

When I mouse over to LDD_TUserData it shows that that is actually a typedef for void. So what its actually doing is void *UserDataPtr. It is mentioned that this is the RTOS Device Structure pointer. What does that mean? Wikipedia says that void *x makes x a NULL pointer. So I suppose that is default because I am programming bareboard with no seleceted OS? But I still can't figure out what is this RTOS Device Structure.

0 Kudos
Reply
1,183 Views
BlackNight
NXP Employee
NXP Employee

void *ptr is a pointer to 'void', and in C this is a pointer to 'anything'. A void pointer is an unspecified type pointer, and used for these kind of things.

I don't know to which Wikipedia article you are referring, but to me this is pretty basic C language.

0 Kudos
Reply
1,183 Views
pratiekbhadrana
Contributor III

Sorry for the confusion. What I meant was void * ptr with ptr = 0 results in a null pointer. I just added the Wikipedia reference to clear doubts if any...

Thanks for your answer Erich

0 Kudos
Reply