Hi Lothar, danke, der Tipp war Gold wert!
also, falls es jemanden hier interessiert, ich habe jetzt folgendes:
Ein 'ram256x32_init_pkg.vhd' mit folgendem Inhalt:
1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 |
|
4 | package ram256x32_init_pkg is
|
5 |
|
6 | -- Define our RAM size and type
|
7 | type t_ram is array (0 to 255) of std_logic_vector (31 downto 0);
|
8 |
|
9 | -- Now let's just define some default values if we instantiate our RAM
|
10 | constant C_INIT_RAM_0 : t_ram := ( -- All data is 'zero'
|
11 | others => (others => '0')
|
12 | );
|
13 | constant C_INIT_RAM_1 : t_ram := ( -- Data for a particular instance
|
14 | 0 => x"0A04_0001",
|
15 | 1 => x"0003_0003",
|
16 | others => x"0000_0000"
|
17 | );
|
18 | constant C_INIT_RAM_2 : t_ram := ( -- Data for another particular instance
|
19 | 0 => x"0123_0001",
|
20 | 7 => x"0234_0003",
|
21 | others => x"0000_0000"
|
22 | );
|
23 |
|
24 | end;
|
25 |
|
26 | --package body ram256x32_init_pkg is
|
27 |
|
28 | --end package body;
|
Dann ein in VHDL beschriebenes RAM mit einem Port read/write und einem
anderen Port read:
1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 |
|
4 | use work.ram256x32_init_pkg.all;
|
5 |
|
6 | entity ram256x32 is
|
7 | generic (
|
8 | INIT_RAM : t_ram := C_INIT_RAM_0
|
9 | );
|
10 | port (
|
11 | clk : in std_logic; -- FPGA clock
|
12 | rst : in std_logic; -- synchronous reset
|
13 | rea : in std_logic; -- read enable port A
|
14 | wea : in std_logic; -- write enable port A
|
15 | addra : in std_logic_vector (7 downto 0); -- read/write address port A
|
16 | dia : in std_logic_vector (31 downto 0); -- write data port A
|
17 | doa : out std_logic_vector (31 downto 0) := (others => '0'); -- read data port A
|
18 | reb : in std_logic; -- read enable port B
|
19 | web : in std_logic; -- write enable port B
|
20 | addrb : in std_logic_vector (7 downto 0); -- read/write address port B
|
21 | dib : in std_logic_vector (31 downto 0); -- write data port B
|
22 | dob : out std_logic_vector (31 downto 0) := (others => '0') -- read data port B
|
23 | );
|
24 | end ram256x32;
|
25 |
|
26 | architecture rtl of ram256x32 is
|
27 |
|
28 | signal ram : t_ram := INIT_RAM;
|
29 |
|
30 | begin
|
31 |
|
32 | --
|
33 | -- Port A is used as read/write port
|
34 | --
|
35 | proc_a : process (clk)
|
36 | begin
|
37 | if rising_edge (clk) then
|
38 | if wea = '1' then
|
39 | ram (to_integer (unsigned (addra))) <= dia;
|
40 | elsif rea = '1' then
|
41 | doa <= ram(to_integer (unsigned (addra)));
|
42 | end if;
|
43 | end if;
|
44 | end process;
|
45 |
|
46 | --
|
47 | -- Port B is used as read-only port
|
48 | --
|
49 | proc_b : process (clk)
|
50 | begin
|
51 | if rising_edge (clk) then
|
52 | if reb = '1' then
|
53 | dob <= ram (to_integer (unsigned (addrb)));
|
54 | end if;
|
55 | end if;
|
56 | end process;
|
57 |
|
58 | end rtl;
|
Dann wird das ganze von irgendeinem Teil des Designs (package
einbinden!) wie folgt aufgerufen:
1 | ram_inst : entity work.ram256x32
|
2 | generic map (
|
3 | INIT_RAM => C_INIT_RAM_0 -- init with 'zero' (or another defined INIT value...)
|
4 | )
|
5 | port map (
|
6 | clk => clk,
|
7 | rst => rst,
|
8 | -- Port A is connected to the r/w logic
|
9 | rea => '1',
|
10 | wea => w_ena_port_a,
|
11 | addra => w_addr_port_a,
|
12 | dia => w_data_port_a,
|
13 | doa => open,
|
14 | -- Port B is connected to the r logic
|
15 | reb => '1',
|
16 | web => '0',
|
17 | addrb => r_addr_port_b,
|
18 | dib => x"0000_0000",
|
19 | dob => r_data_port_b
|
20 | );
|
Muss ich noch testen, aber scheint zu funktionieren!
Vlt. kann das ja irgendjemand auch noch gebrauchen...