EmbDev.net

Forum: ARM programming with GCC/GNU tools Casting in C/C++


von Gladson N. (gladson)


Rate this post
useful
not useful
Hi Guys
I have a piece of code for flashing an LED using AT91R40807 on an
AT91EB40 evaluation board.I'm having difficult understanding the
following portion using casting

 #define led_mask = (led1|led2|led3)
 void flashled(int color) {

  *(unsigned int*)(0xFFFOO10) = led_mask
  *(unsigned int*)(0xFFFOO00) = led_mask
  *(unsigned int*)(0xFFFOO34) = led_mask
  ....continues

my question is why were these memory addresses chosen "IN PARTICUALR"
when masking.As far as I know they just represent the location of the
output enable register,enable register and clear output data register
respectively.Probably you can tell me what actually happens with casting
used like this.

G

von Clifford S. (clifford)


Rate this post
useful
not useful
I am not sure if I understand exactly what it is you are asking; but the
addresses are first cast to pointer types and then derefenced you modify
their content.

The cast is necessary to provide the absolute address with a 'type',
i.e. it says this address points to an 'int'. Without providing type in
this way, the compiler would not know how many bits to write.

Clifford

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.