Cannot understand port control register initialization code.

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

Cannot understand port control register initialization code.

597 Views
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

Labels (1)
0 Kudos
2 Replies

371 Views
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 Kudos

371 Views
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 Kudos