How does Init(LDD_TUserData *UserDataPtr) work

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How does Init(LDD_TUserData *UserDataPtr) work

ソリューションへジャンプ
1,567件の閲覧回数
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 解決策
1,182件の閲覧回数
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 返答(返信)
1,183件の閲覧回数
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 件の賞賛
返信
1,182件の閲覧回数
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 件の賞賛
返信
1,182件の閲覧回数
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 件の賞賛
返信
1,182件の閲覧回数
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 件の賞賛
返信