Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
996 Views

readdata address for avalon slave interface

HI All, 

 

I had connected my own created component to the avalon switch fabric using avalon slave interface. 

The base address for the component was 0x5040. 

I wish to read out the data given out by the slave interface but I'm not sure the exact address for it. 

May I know the way to determine the address for readdata? 

 

Thanks 

HY
0 Kudos
5 Replies
Altera_Forum
Honored Contributor I
37 Views

I assume you are reading from it using Nios II. I would use this macro assuming it's a 32-bit slave port (and include io.h): 

 

IORD_32DIRECT(BASE, OFFSET); 

 

The BASE would be 5040, but I would get that from system.h so that it's not hardcoded. The OFFSET field is a multiple of 4 since it's a 32-bit read macro. So if you have 32-bit registers in the component called A, B, C, D you would use offsets 0, 4, 8, and 12 to access them individually. 

 

The reason why you use macros like these is it ensures that Nios II data cache (if present) is bypassed and the access reaches the slave port. Even if you don't have a data cache I recommend using these macros so that your software is portable to Nios II CPUs that contain a data cache.
Altera_Forum
Honored Contributor I
37 Views

HI Omen, 

 

Thanks for your info sharing. 

I noticed NIOS2 basically provide API for user to access hardware directly. 

Does it mean NIOS2 application is still a program which being executed by the host PC processor? 

 

Thanks 

HY
Altera_Forum
Honored Contributor I
37 Views

The Nios II application executes *on* the Nios II processor (i.e. Nios is the host). That IO macro is part of the board support package so that your Nios II software can access memory locations in the system. 

 

Are you using Nios II or something else to access the slave, I assumed you are using Nios II since this post is in the Nios section of the Altera forum. If you wanted to access the slave without Nios II you would need some other mastering component to issue the reads and writes. For example you could connect the slave to the JTAG to Avalon bridge and access your slave over JTAG using system console.
Altera_Forum
Honored Contributor I
37 Views

HI Omen, 

 

I'm actually using NIO2 to access the slave. 

I tried system console before and it allowed me to direct access the memory location. 

I'm thinking is it possible to send some data from c program through the system console to access the slave. 

 

Thanks 

HY
Altera_Forum
Honored Contributor I
37 Views

System console is not capable of being hosted on Nios II. System console can use the Nios II core to access memory but if you are already writing Nios II code to access the slave I wouldn't bother overcomplicating things by throwing system console into the mix. 

 

The IO macros are all you need to access the slave. For example lets say I want to write the values of 0 to 9 to the 4th 32-bit location in the slave I would do something like this: 

 

# include "io.h" 

# include "system.h" 

 

void main() { 

int i; 

 

for(i=0;i<10;i++) { IOWR_32DIRECT(SLAVE_BASE, 4*(3), i); } 

 

The 4* is to make sure my offsets are 4-byte aligned since it's a 32-bit write macro, and the (3) is because I'm accessing the 3rd 32-bit offset into the slave. SLAVE_BASE is defined in system.h (it'll have the name of whatever your component is called)
Reply