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++
12606 Discussions

How to use a custom component

Altera_Forum
Honored Contributor II
1,673 Views

Hi, 

 

My teacher asks me to write directly from NIOS in the memory of chip. 

The addresses of the chip are multiplexed and the ports are bidir. 

I have written a state machine in vhdl and create a custom component (avalon tristate slave). 

 

I have tried to read and write in registry like that : 

 

// write *(custom_component_base + addr) = data; // read dataread = *(custom_component_base + addr); 

 

but it doesn't work. NIOS IDE dislike the star and says :  

error: invalid type argument of `unary *' 

 

Do you know how to do that ? 

 

Thank you, 

 

Mig
0 Kudos
9 Replies
Altera_Forum
Honored Contributor II
492 Views

Hi Mig, 

 

Try explicitly casting the expression in brackets to a pointer e.g. 

 

*((int*)(custom_component_base + addr)) = data;  

 

// read 

dataread = *((int*)(custom_component_base + addr)); 

 

Alternatively, define custom_component_base as a pointer rather than an integer type. If you do that, make sure that the offset that you add to the base address is correct for the pointer type, e.g. 

 

int *ptr=1000; 

 

*ptr=1; 

*(ptr+1)=2; 

 

would write to addresses 1000 and 1004 because an int is 4 bytes. 

 

whereas 

 

char *ptr=1000; 

 

*ptr=1; 

*(ptr+1)=2; 

 

would write to addresses 1000 and 1001 because a char is 1 byte. 

 

 

Cheers 

 

sb 

 

0 Kudos
Altera_Forum
Honored Contributor II
492 Views

Hi, 

 

Thanks again sharkybaba ! 

 

I have tried your code. There is no errors, but the program don't do what I want : I always read 0xFFFFFFFF. 

 

I think there's something that I don't understand... In fact, I need to access to FPGA's pins directly from NIOS without using PIOs because I need speed. Should I use a custom component to do that ?
0 Kudos
Altera_Forum
Honored Contributor II
492 Views

Could you explain a bit more about how your system is set up? It may be that you can do what you want without custom logic. 

 

0 Kudos
Altera_Forum
Honored Contributor II
492 Views

ok, 

I'm always on my robotic project. 

We need to load maps and photos in the robot by plugging a USB Key. 

At the beginning I would use a FTDI chip for controlling the USB, but in my school we have a lot of Phillips ISP1581 so I didn't have the choice... 

 

The datas and the addresses are multiplexed on this chip. 

The datasheet is here if you need it : visit my website (http://pdfdata.datasheetsite.com/pdf1/philips/isp1581.pdf

 

I need from nios to write and read in registers of this chip. For example the scratch register which is located at the address 0x78. 

I cannot use PIOs, my teacher doesn't want because they aren't enough fast. 

 

Do you have an idea ? 

 

Thank you 

 

 

0 Kudos
Altera_Forum
Honored Contributor II
492 Views

Do you have to use the multiplexed address/data bus option? If you could use the device according to Fig.11 of the datasheet (separate address and data buses, separate read and write signals) it would be straightforward with no custom logic required.  

 

I've never interfaced between NIOS and a device with multiplexed buses. I'd try searching the forums and Altera website to see if there are any examples. 

 

0 Kudos
Altera_Forum
Honored Contributor II
492 Views

Use the split mode is easier for the DMA control and the communications are faster. 

 

Thanks
0 Kudos
Altera_Forum
Honored Contributor II
492 Views

I've just found a solution and it works well ! 

I have done a new component without including my hdl file and without any conduits. 

Then I have wired it in QII with my HDL and it works very well. 

 

I can read and write with the line you've mentionned. 

Just be careful when you send the adress, I don&#39;t why, NIOS delete the first two LSB&#39;s on the adress. That&#39;s why, if you want to write something to 0x78 you should define your adress like that : 0x78<<2 

 

Thank you again sharkybaba ! 

I hope I would be able to help you a day. 

 

Cheers ;)
0 Kudos
Altera_Forum
Honored Contributor II
492 Views

I&#39;ve just found a solution and it works well ! 

I have done a new component without including my hdl file and without any conduits. 

Then I have wired it in QII with my HDL and it works very well. 

 

I can read and write with the line you&#39;ve mentionned. 

Just be careful when you send the adress, I don&#39;t why, NIOS delete the first two LSB&#39;s on the adress. That&#39;s why, if you want to write something to 0x78 you should define your adress like that : 0x78<<2 

 

Thank you again sharkybaba ! 

I hope I would be able to help you a day. 

 

Cheers ;)
0 Kudos
Altera_Forum
Honored Contributor II
492 Views

Avalon Slaves will always receive the address that is aligned to its data width. So, if you issue a write to byte address x10, it will send address x10 to a 8-bit wide slave, address x08 to a 16-bit wide slave, and address x04 to a 32-bit wide slave. If that is what you were experiencing, then it is just the way the avalon spec works.  

 

Kevin
0 Kudos
Reply