Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
834 Views

PIO communication between software and hardware

I have a system I'm attempting to build that needs to transfer data between the C software and the verilog HDL. I was attempting this using bidirectional PIOs. Now if I understand these correctly the output of a PIO gets written to the base address register of the PIO which is determined by the system.h 

 ie IOWR(PIO_0_BASE, 0, 0x1)  Now when this occurs and I am debuging the code in the Nios IDE no change is made to that address in memory. I can write to the offset of 1. Now dong some reading I believe this is due to the PIO in output mode only drives that value to the PIO connection but doesn't necessarily set it. So within the instantiaion of the Nios cpu I created a register that should hold this value of the PIO. However from what I can see this register does not get the data.  My question is two fold here. Is there a better way to communicate between software and hardware? I should mention that this data I am writing from software needs to go across the GPIO connectors on the DE2 evaluation board.  Or the easier route here is that am I missing something within my code or has anyone completed a similar design where you write data from software to a PIO that is stored in some register or memory location that can be written to a GPIO at a later (less than a second)?  Thanks for any help you can provide. If this sounds confusing and you think you can help please just ask for a better explanation since I tried to make this as general as possible without diving into code too much.

0 Kudos
2 Replies
Highlighted
Valued Contributor III

Re: PIO communication between software and hardware

Communicating from software to hardware using PIOs should work. 

 

But, I believe that there is a better way to communicate between hardware and software, but it could take some time to learn how to do it. This is to create an avalon bus connection in your verilog. Then create an SOPC Builder Core out of your verilog, using the Component Editor in SOPC Builder. If this is the path you wish to take I can provide you with more information. 

 

Back to the PIO: 

I have used the PIO to communicate over the GPIO on a DE2 board, and it worked. Here is my code. 

 

#include <system.h> void main (void) {    int * gpio = (int *) PIO_0_BASE;    (*gpio) = 0x26;    return; } 

 

If you post your code I could look at it. Otherwise, I don&#39;t really have any suggestions. 

 

- Blair
0 Kudos
Highlighted
Valued Contributor III

Re: PIO communication between software and hardware

Output only PIOs have write-only data registers. I&#39;m betting this is the source of your confusion. 

 

[EDIT]: Oops! Just saw that you&#39;re using bidi PIOs. The following equation determines what&#39;s read...relative to the base address for the component: 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

assign read_mux_out = ({1 {(address == 0)}} & data_in) | 

  ({1 {(address == 1)}} & data_dir);[/b] 

--- Quote End ---  

 

 

So you&#39;re in the same boat. You cannot read what you&#39;ve just written, without some more hardware work. 

 

Cheers, 

 

- slacker
0 Kudos