Forum Discussion

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

absolute address accessing in NIOS2

HI, eveyone:

i just a beginner of NIOS, i have a quetion about software development of absolute address's accessing.

for example, the system have one 1kbytes ram, its start avalon address is 0x0, and length is 0x3ff. i want to access the space which address is 0x100 in my program. can i use pointer of C language like this?

unsigned char *p=(unsigned char *)0x100;

when i want to know what's byte's data, then x=*p; when i want to give this byte's data, then *p=0xff;

how about another way to access absolute address in NIOS2 IDE? is there any document about this?

6 Replies

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

    Hi oceanx,

    if I understand what it is that you want maybe I can help you. If you want to give your data an offset en you have a base address, you should do it like this:

    data = BASE_ADDRESS_OF_RAM_USED | 0x(hex-value);

    this way your offset should be added with the base adress, which can be found in system.h. And data should be declared as a pointer....

    Cheers,

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

    Hi oceanx,

    did you try to do it?! Because I think that also should work... You are using the volatile statement.... In my eyes that also should work... Please let me know if it did.

    Cheers,

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

    Hi oceanx,

    I think that looks basically fine. However, what you might have problems with is the data cache (if you have one installed in your system) - the write might be stored there instead of written to main memory. I suggest you check the IOWR and IORD macros which are provided in HAL to bypass the cache:

    Nios2 Documentation states that the 'volatile' keyword does not do the job because of a the cache machanism used in Nios2 (I believe it is called write-back cache).

    <Nios II kit path>/components/altera_nios2/HAL/inc/io.h

    Cheers,

    -pkumpula