There is a question about the dual motor S32 project form NXP

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

There is a question about the dual motor S32 project form NXP

590 Views
edenli
Contributor V

Hi Guys,

I read the C-code about the dual motor demo board ,there is a question shown as below:

The C-code from the Project as below:

/*
* Declaration macro keeps all necessary settings for single/dual
* motor control application under one command.
*/
#define DECLARATION(param, uni3_param, pospe_param, cb_param, enc_avaliable, res_avaliable)  static pmsmDrive_t  param = { CFOC_DEFAULT,\
uni3_param##_CFG_DEFAULT,\
pospe_param##_CFG_DEFAULT,\
enc_avaliable,\
res_avaliable,\
MPC5643L_BGA257_##cb_param##_DEFAULT,\
CNTR_STATE_DEFAULT,\
SCALAR_CNTR_STATE_DEFAULT};

My analysis and question:

AS i use the 'define' before,

#define A  5  --- equal to A=5; According to the similar to analyze it that DECLARATION = param,but it  seems not right,The reason is that the parameters order of DECLARATION is (1)param, (2)uni3_param, (3)pospe_param, (4)cb_param, (5)enc_avaliable, (6)res_avaliable ,but the assignment is (1)CFOC_DEFAULT (2)uni3_param##_CFG_DEFAULT (3)pospe_param##_CFG_DEFAULT,\(4) enc_avaliable,\(5) res_avaliable,\ (6)MPC5643L_BGA257_##cb_param##_DEFAULT,\(7)CNTR_STATE_DEFAULT,\

(8)SCALAR_CNTR_STATE_DEFAULT};

1# The order and the numbers is the same, Why adding the CNTR_STATE_DEFAULT and SCALAR_CNTR_STATE_DEFAULT?

2# How to comprehend the uni3_param##_CFG_DEFAULT?

3#Assign the order of the Value is rignt?

0 Kudos
2 Replies

488 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi edenli‌,

The ## operator is called the concatenation or token pasting. and its job is to concatenate whatever comes before ## with whatever stand after it.

For the rest of the questions - keep in mind that the macro DECLARATION is used to construct a STRUCT called M1 or M2 of type pmsmDrive_t. If you think about that macro this way - i think you will have no issues to understand what it is expanding for and figure the answers by yourself :-)

Hope this helps!

Daniel 

0 Kudos

488 Views
edenli
Contributor V

Hi Daniel,

Haha:smileyhappy:,Thank you !

0 Kudos