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

Author: Gladson Ncanana (gladson)
Posted on:

Rate this post
0 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

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.


Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 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.



Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.