Forum Discussion

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

Interface to dual port ram memory

Hi,

I want to access (read/write) dual port ram in my sopc system. How could I do that in my Nios II program?

Thanks,

Caridee

8 Replies

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

    You can use either the IORD/IOWR macros, or directly use C pointers. In the latter case, you must go through the alt_remap_uncached() function to define your pointer, to be sure you bypass the data cache.

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

    Through the IOWR macro:

    IOWR(YOUR_DPRAM_BASE,reg,value)

    Where reg is the 32-bit register number (reg = 0 will write at YOUR_DPRAM_BASE, reg = 1 will write at YOUR_DPRAM_BASE+4, etc...) and value is the 32-bit value to write.

    Using pointers:

    int *myPointer = (int*)alt_remap_uncached(YOUR_DPRAM_BASE,YOUR_DPRAM_SPAN);
    myPointer = value1;
    myPointer = value2;

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

    Hi Daixiwen,

    Thanks for the codes... i will try it out...

    by the way, i am a abit new in using macro. can u pls explain to me why

    reg = 0 and reg = 1 are differ from 4 bytes?

    Thanks again,

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

    The IORD/WR macros read and write 32-bit registers directly. That's why when you increase the register number by one, the macro will access the next 32 bits, i.e. the next 4 bytes.