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

Strange problem with IORD_16DIRECT

Altera_Forum
Honored Contributor II
1,903 Views

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
Altera_Forum
Honored Contributor II
486 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
Altera_Forum
Honored Contributor II
486 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
Altera_Forum
Honored Contributor II
486 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
Altera_Forum
Honored Contributor II
486 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
Altera_Forum
Honored Contributor II
486 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
Reply