Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Pointer to timer registers

The following line creates a pointer to a structure used to access a timer:

struct TIMER_REGS *TIMER = (struct TIMER_REGS *)(TIMER_BASE | 0x80000000);

This works when my timer's base address is 0x00000020

If I change the base address to 0x00000000, it does not work -- meaning code interfacing the structure is not interfacing the timer registers.

I "borowed" this code after finding it in an internet search and I am not understanding the last part. Why is an offset (if that is what it is) being added to the base address? What is the underlying mechanic?

Thanks for your help,

Mike

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The "offset" is just a way to put to 1 the bit 31 of the address. This instructs the CPU to bypass the data cache, as it should when accessing hardware.

    Another way to access the hardware is to include the *_regs.h file provided with the module, and call its IORD_* / IOWR_* macros, instead of using a structure.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks Daixwen,

    I Called the Altera FAE and he believed the MSB in the address was a cache bypass.

    My problem was really me being foolish. I wasn't rebuilding in Quartus after changing in SOPC builder. Duh!

    Thanks again.