How does Init(LDD_TUserData *UserDataPtr) work

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How does Init(LDD_TUserData *UserDataPtr) work

跳至解决方案
1,253 次查看
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

标签 (1)
0 项奖励
回复
1 解答
868 次查看
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 项奖励
回复
4 回复数
869 次查看
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 项奖励
回复
868 次查看
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 项奖励
回复
868 次查看
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 项奖励
回复
868 次查看
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 项奖励
回复