title: Reading hardware register in C program
body: <p>Let say there is a 32 bits register defined as <code>TIMER</code> and its 32 bits address <code>TIMER_ADDR</code> in the memory (DDRAM).</p>
  
  <pre><code>uint32_t TIMER_ADDR; // 32 bits address declared as uint32_t
  </code></pre>
  
  <p>The layout of TIMER is defined as:</p>
  
  <pre><code>struct timer {
      uint32_t start:1;
      uint32_t mode: 3;
      uint32_t init: 4;
      uint32_t value:24
  }
  </code></pre>
  
  <p>Later I defined a local var loc_timer as:</p>
  
  <pre><code>struct timer loc_timer;
  </code></pre>
  
  <p>How can I to read this register to a local register in the program so I can modify the content </p>
  
  <pre><code>loc_timer.mode = 4;
  loc_timer.init = 10;
  </code></pre>
  
  <p>and write it back to register <code>TIMER</code> ?</p>
  
  <p>something like </p>
  
  <pre><code>(*(uint32_t *))&amp;loc_timer = (*((uint32_t *)(TIMER_ADDR))); // read
  (*((uint32_t *)(TIMER_ADDR))) = (*(uint32_t *))&amp;loc_timer; // write
  </code></pre>
  
  <p>but it does not work :-(</p>