SPI_MCR_SMPL_PT_MASK SPI_MCR_SMPL_PT_SHIFT SPI_MCR_SMPL_PT (x)

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

SPI_MCR_SMPL_PT_MASK SPI_MCR_SMPL_PT_SHIFT SPI_MCR_SMPL_PT (x)

599 Views
nikivendola
Contributor III

Hi all,

can anyone explain the behavior of:
#define SPI_MCR_SMPL_PT_MASK 0x300u
#define SPI_MCR_SMPL_PT_SHIFT 8
#define SPI_MCR_SMPL_PT (x) (((uint32_t) (((uint32_t (x)) << SPI_MCR_SMPL_PT_SHIFT)) & SPI_MCR_SMPL_PT_MASK)
How are they used? Because I have a 3 to register?

0 Kudos
3 Replies

430 Views
EarlOrlando
Senior Contributor II

Hello Niki,

These are macros that let to make a more readable code.

A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. This is done by the C preprocessor so it does not waste CPU resources.

If you see the SPIx_MCR field description you will see that the field SMPL_PT is in the register SPIx_MCR in the bits 8 and 9. You can use the shift macro as follows (where x is the desired value to write in the SAMPL_PT field​):

SPIx_MCR = x << SPI_MCR_SMPL_PT_SHIFT;

It lets you write the value that you want in the register shifted SPI_MCR_SMPL_PT_SHIFT times so it is in its respective field. Also, you can mask that value to be ensure that you are not writing values in other fields through the SPI_MCR_SMPL_PT_MASK mask. It would be used as follows:

SPIx_MCR = (x << SPI_MCR_SMPL_PT_SHIFT) & SPI_MCR_SMPL_PT_MASK;

The mask has the bits of the desired field as 1 and the other bits as 0. Also, there is another macro that combines these two macros. This third macro receives an argument that will replace the contents of the macro so it does all the above work.

SPIx_MCR = SPI_MCR_SMPL_PT(x);

pastedImage_1.png

Best regards,

Earl.

/* If this post answers your question please click over the Correct answer button. */

430 Views
nikivendola
Contributor III

ok, thank you very much for your response.
But this knowledge where I can read them, there is a manual / book for these things?

I can also use it to read for example from the register POPR ??

0 Kudos

430 Views
EarlOrlando
Senior Contributor II

This is done by the C preprocessor, it is not exclusive from Freescale. You can find a lot of information about this in the net. I think the link below has a good information about macros.

Macros - The C Preprocessor

Best regards,

Earl.

/* If this post answers your question please click over the Correct answer button. */