On 6/13/2017 6:50 PM, Clark Sann wrote:
>
> But what I really need to know is how do I interpret this statement:
>
> #define GPIO0_SETDATAOUT (*(volatile uint32_t *)*(GPIO0_BASE + 0x190))
>
> One way I use it is as follows:
>
> GPIO0_SETDATAOUT = 1u << PWM2A_OFFSET;
>
> What I don't understand is how I intrepret the first statement, especially the
> bolded part. I understand the meaning of #define and I understand the simple
> GPIO0BASE + 0x190 offset math. What I don't understand is the bolded part. It
> looks like it is a pointer to a pointer to a uint32_t, but that doesn't make
> sense to me. I don't see the need for double indirection. And I'm not too clear
> on the difference between a uint32 and a uint32_t.
>
> Can someone give me a plain english translation for the #define statement?
The #define results in a simple text replacement prior to the C
compiler actually running. The actual code that would be compiled is
something like:
*(volatile uint32_t *)*(GPIO0_BASE + 0x190)) = 1u << PWM2A_OFFSET;
Basically this takes the value of GPIO0_BASE + 0x190 (the address of
the SETDATAOUT register), casts it to a volatile uint32_t pointer, and
stores the result of the right-hand side of the equals to the address
being pointed to.
This is all very basic C code...just read up on some tutorials
regarding the C pre-processor (the #dfine), pointer handling (the *'s)
and the volatile keyword.
Breaking the first bit down to hopefully help you out a bit:
uint32_t : a 32-bit unsigned value
uint32_t * : a pointer to a 32-bit unsigned value
volatile uint32_t * : a pointer to a 32-bit unsigned value that
may change in ways the compiler doesn't expect (ie: don't optimize
away all the reads/writes to this value)
*(volatile uint32_t *) : The actual 32-bit unsigned data value at
the address contained in the following expression
--
Charles Steinkuehler
cha...@steinkuehler.net