Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

absolute address accessing in NIOS2

Altera_Forum
Honored Contributor II
1,025 Views

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?
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
311 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
311 Views

Sorry didn&#39;t read it that well I think. It&#39;s still early http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif  

 

data = BASE_ADDRESS_OF_RAM_USED | 0x100; 

 

Good luck, 

 

Danny
0 Kudos
Altera_Forum
Honored Contributor II
311 Views

Thanks, Danny 

i just want to write the value-0xFF to the ram space which absolute address is 0x100. in other mcu software programming, i can do it in this way: 

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

*p = 0xFF; 

i wonder if it is the same in NIOS programming. 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif  

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/ohmy.gif
0 Kudos
Altera_Forum
Honored Contributor II
311 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
311 Views

Hi, Danny 

Because i have no hardware board of NIOS, so i can only to simulate this program. it seems ok. my board will arrive next week, then i can try the program in the hardware. 

Thanks again http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif  

 

Best Regards 

Yang
0 Kudos
Altera_Forum
Honored Contributor II
311 Views

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 &#39;volatile&#39; 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
0 Kudos
Reply