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

Strange problem with IORD_16DIRECT

Hi, 

 

I have a 16-bit pio (input) in my sopc and I want to access the data through IORD_16DIRECT. The data shown on the port is 0x00, 0x01, 0x02....0xff (verified through signaltap). However, the received data after IORD_16DIRECT is 0x01, 0x03, 0x05.... Please give me some help on that!! 

 

Below is my code: 

alt_u16 data_temp; 

for(j=0;j<1400;j++){ 

data_temp = IORD_16DIRECT(PIO_DATA_BASE, 0); 

if(data_temp&0x100==0x100){ 

data_t[j] = data_temp; 

else 

j--; 

}
0 Kudos
5 Replies
Highlighted
Valued Contributor III
7 Views

Why the data shown is 0x00, 0x01 on signal tap instead it should be 0x0000, 0x0001 as it is a 16 bit PIO

0 Kudos
Highlighted
Valued Contributor III
7 Views

I don't see any synchronization system in your code, so you have no way of defining or detecting when you read the PIO port. 

If the PIO port input changes faster than your software can read it, then you'll miss some values.
0 Kudos
Highlighted
Valued Contributor III
7 Views

Hi Daxiwen, 

 

This code (if(data_temp&0x100==0x100)) is for synchronization, I keep reading the port, if the 9th bit is high, it means data is coming. 

 

For the speed, I got the same result when I use 500K and 2M clock in my verilog code. So I guess it is not the reason. Is there any special mechanism for PIO 16bits? 

 

 

--- Quote Start ---  

I don't see any synchronization system in your code, so you have no way of defining or detecting when you read the PIO port. 

If the PIO port input changes faster than your software can read it, then you'll miss some values. 

--- Quote End ---  

0 Kudos
Highlighted
Valued Contributor III
7 Views

Is your pio returning the next value on each read request? 

Are you decoding the address lines properly? 

 

Although you are using IORD_16DIRECT() the bus cycle requested by the nios cpu will be a 32bit one (with all byte enables asserted). Since your slave is 16bit it will see 2 read cycles, one for address 0 and one for address 2 (not sure what the address line is called by then! - might be A0 relative to your slave). 

 

In practise it is best to use 32bit slaves and set the high bits to zero on reads.
0 Kudos
Highlighted
Valued Contributor III
7 Views

The PIO doesn't contain bytenables so any access to it should be atomic and not split into multiple transactions by the fabric. 

 

I recommend you use the access macros that come with the PIO so that you don't have to worry about your offsets. IORD_16DIRECT uses 2 byte offsets by the way. The macros are defined in "altera_avalon_pio_regs.h" in the directory: \ip\sopc_builder_ip\altera_avalon_pio\inc
0 Kudos