Cannot understand port control register initialization code.

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

Cannot understand port control register initialization code.

1,211 次查看
oliviachristyva
Contributor III

Hi,

I am a beginner in coding and I cannot understand port control register initialization used in this code. Can anyone explain me this line by line. Or can you give me some information to how and from where to learn this.

 

/*PORTD_PCR3:ISF=0,MUX=4*/

PORTD_PCR3 = (uint32_t)((PORTD_PCR3&(uint32_t)~(uint32_t)(

                              PORT_PCR_ISF_MASK) |

                              PORT_PCR_MUX(0x03)

                              )) | (uint32_t) (

                           PORT_PCR_MUX(0x04)

                           ));

 

 

 

regards,

olivia

标签 (1)
0 项奖励
回复
2 回复数

985 次查看
guenter_loettrich
NXP Employee
NXP Employee

Hi Olivia,

this is the C- language coding style for example used by SDK. I admit this is quite hard to understand if you are not that experienced.

It does the following:

It clears and sets certain bits (ISF and MUX) in the port control register PORTD_PCR3 by keeping all other bits in that register untouched. This is done by first reading the content of PCR3 and forming a constant using AND (&) and OR (|) and NOT (~) operations and then writing back the new value to PCR3. (uint32_t) is just a type cast to have all the constants like PORT_PCR_ISF_MASK and macros in 32-bit format. This is good coding style as the target register PORTD_PCR3 is a 32-bit register.

Some compilers may produce warnings if the typecasts are missing.

There is lots of literature available how such sometimes "weird" C-language coding can be translated in more human readable format.

br

Guenter

0 项奖励
回复

985 次查看
MarekTrmac
NXP Employee
NXP Employee

Hi Olivia,

I cannot help with your question directly, but there is available Pins tool (desktop version or web version on http://mcuxpresso.nxp.com/) allowing to generate routing code for you.

Regards

Marek

0 项奖励
回复