Altera_Forum
Honored Contributor
13 years agoCould not read 8 bit data from custom ram
Hi every body!
I'm a newbie in SOPC system design. I'm trying to create a custom ip, which has an internal RAM (declare as an array) and contacts with NIOS via Avalon MM bus. I'm using DE2 and this is my code for that ip:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
entity PIXELS_BUFFER is
port(
--- NIOS
clock: IN STD_LOGIC;
reset: IN STD_LOGIC;
address: IN STD_LOGIC_VECTOR(3 downto 0); -- for testing
chipselect: IN STD_LOGIC;
byteenable: IN STD_LOGIC;
writedata: IN STD_LOGIC_VECTOR(7 downto 0); -- 8-bit data
readdata: OUT STD_LOGIC_VECTOR(7 downto 0); -- 8-bit data
write: IN STD_LOGIC;
read: IN STD_LOGIC
);
end PIXELS_BUFFER;
architecture Behavioral of PIXELS_BUFFER is
type ram_type is array (0 to 15) of std_logic_vector(7 downto 0);
--- ROM definition
signal RAM_CONTENT: ram_type := (
"00000000",
"00000001",
"00000010",
"00000011",
"00000100",
"00000101",
"00000110",
"00000111",
"00001000",
"00001001",
"00001010",
"00001011",
"00001100",
"00001101",
"00001110",
"00001111"
);
begin
process(clock, reset, address, chipselect, byteenable, read, write, writedata)
begin
if(rising_edge(clock)) then
if(chipselect='1') then
if(read='1') then
readdata <= RAM_CONTENT(conv_integer(address));
end if;
if(write='1') then
RAM_CONTENT(conv_integer(address)) <= writedata;
end if;
end if;
end if;
end process;
end Behavioral;
In SOPC, I added my IP as:
signal | Interface | Signal type | WIDTH|Direction
clock | clock | clk | 1 | IN
reset | reset | reset | 1 | IN
address | avalon_slave_0 | address | 4 | IN
chipselect | avalon_slave_0 | chipselect | 1 | IN
byteenable | avalon_slave_0 | byteenable | 1 | IN
writedata | avalon_slave_0 | writedata | 7 | IN
readdata | avalon_slave_0 | readdata | 7 | OUT
write | avalon_slave_0 | write | 1 | IN
read | avalon_slave_0 | read | 1 | IN
my first work is reading RAM_CONTENT but i saw wrong result in my NIOS :((
# include <stdio.h>
# include <io.h> // using IORD_8DIRECT
# include "system.h" // using PIXELS_BUFFER_0_BASE
int main()
{
int i;
printf("Hello from Nios II!\n");
for(i=0; i<16; i++)
// read byte by byte
printf("Addr: %i\t%i \n", i, IORD_8DIRECT(PIXELS_BUFFER_0_BASE, i));
return 0;
}
Results:
Addr: 0 0
Addr: 1 0
Addr: 2 1
Addr: 3 2
Addr: 4 3
Addr: 5 4
Addr: 6 5
Addr: 7 6
Addr: 8 7
Addr: 9 8
Addr: 10 9
Addr: 11 10
Addr: 12 11
Addr: 13 12
Addr: 14 13
Addr: 15 14
Why did it show that? I had no delay when transfering data to avalon bus, or no wait cycle in SOPC IP. Attach file is my project. Could anybody help me? Thanks^^