0

I am currently reading through DE0-Nano-SoC Computer System with ARM Cortex-A9 user guide i found a c code in it and i don't understand what does "+ 3" in "*(MPcore_private_timer_ptr + 3)" mean?

while (1)
{
*HPS_GPIO1_ptr = HPS_LEDG; // turn on/off LEDG
while (*(MPcore_private_timer_ptr + 3) == 0)
; // wait for timer to expire
*(MPcore_private_timer_ptr + 3) = 1; // reset timer flag bit
HPS_LEDG ^= bit_24_pattern; // toggle bit that controls LEDG
}
G.Ornill
  • 15
  • 1
  • 6

3 Answers3

1

*(MPcore_private_timer_ptr + 3) is the same as MPcore_private_timer_ptr[3]. You dereference an incremented pointer.

yar
  • 1,855
  • 13
  • 26
1

Following on for @yar's answer, MPcore_private_timer_ptr is a pointer to the base address of a memory mapped timer, that is the timer's registers all follow on from that address. The +3 offset takes you to a different register (in this case the interrupt status register) for that timer.

Colin
  • 3,394
  • 1
  • 21
  • 29
0

Blockquote

*(MPcore_private_timer_ptr + 3) = 1; // reset timer flag bit

Is synonimum of :

*(&MPcore_private_timer_ptr[3]) = 1; // reset timer flag bit

juansolsona
  • 186
  • 7