]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - tb/tb_vector_gen.vhd
Wave_table initialization data format modified.
[fpga/pwm.git] / tb / tb_vector_gen.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
5
6 entity tb_vector_gen is
7 end tb_vector_gen;
8
9 --------------------------------------------------------------------------------
10
11 architecture testbench of tb_vector_gen is
12
13   constant period : time := 5 ns;
14   constant offset : time := 0 us;
15
16   constant LUT_DAT_W     : integer := 10;
17   constant LUT_ADR_W     : integer := 9;
18   constant LUT_INIT_FILE : string  := "../sin.lut";
19   constant IRF_ADR_W     : integer := 5;
20
21   constant WAVE_SIZE : integer := 2**LUT_ADR_W;
22   
23
24   signal ACK_O : std_logic;
25   signal CLK_I : std_logic;
26   signal RST_I : std_logic;
27   signal STB_I : std_logic;
28
29   signal IRF_ACK_I : std_logic;
30   signal IRF_ADR_O : std_logic_vector (IRF_ADR_W-1 downto 0);
31   signal IRF_CYC_O : std_logic;
32   signal IRF_DAT_I : std_logic_vector (15 downto 0);
33   signal IRF_DAT_O : std_logic_vector (15 downto 0);
34   signal IRF_STB_O : std_logic;
35   signal IRF_WE_O  : std_logic;
36   signal LUT_ADR_O : std_logic_vector (LUT_ADR_W-1 downto 0);
37   signal LUT_DAT_I : std_logic_vector (LUT_DAT_W-1 downto 0);
38   signal LUT_STB_O : std_logic;
39
40
41   subtype word_t is std_logic_vector (15 downto 0);
42   
43   signal dbg_mem0 : word_t    := conv_std_logic_vector(1,16);  -- read only by UUT
44   signal dbg_mem1 : word_t    := (others => '0');
45   signal dbg_mem2 : word_t    := (others => '0');
46   signal dbg_mem3 : word_t    := (others => '0');
47   signal dbg_ack  : std_logic := '0';
48
49 --------------------------------------------------------------------------------
50   
51 begin
52   
53   uut : entity work.vector_gen
54     port map (
55       ACK_O     => ACK_O,
56       CLK_I     => CLK_I,
57       RST_I     => RST_I,
58       STB_I     => STB_I,
59       IRF_ACK_I => IRF_ACK_I,
60       IRF_ADR_O => IRF_ADR_O,
61       IRF_CYC_O => open,
62       IRF_DAT_I => IRF_DAT_I,
63       IRF_DAT_O => IRF_DAT_O,
64       IRF_STB_O => IRF_STB_O,
65       IRF_WE_O  => IRF_WE_O,
66       LUT_ADR_O => LUT_ADR_O,
67       LUT_DAT_I => LUT_DAT_I,
68       LUT_STB_O => LUT_STB_O);
69
70   wave_table_1 : entity work.wave_table
71     generic map (
72       DAT_W     => LUT_DAT_W,
73       ADR_W     => LUT_ADR_W,
74       INIT_FILE => LUT_INIT_FILE)
75     port map (
76       ACK_O => open,
77       ADR_I => LUT_ADR_O,
78       CLK_I => CLK_I,
79       DAT_I => (others => '0'),
80       DAT_O => LUT_DAT_I,
81       STB_I => LUT_STB_O,
82       WE_I  => '0');
83
84   
85   SYSCON_CLK : process is
86   begin
87     CLK_I <= '0';
88     wait for offset;
89     loop
90       CLK_I <= '1';
91       wait for period/2;
92       CLK_I <= '0';
93       wait for period/2;
94     end loop;
95   end process;
96
97   SYSCON_RST : process is
98   begin
99     RST_I <= '0';
100     wait for offset;
101     wait for 0.75*period;
102     RST_I <= '1';
103     wait for 2*period;
104     RST_I <= '0';
105     wait;
106   end process;
107
108   
109   DBG_MEM : process (IRF_STB_O, CLK_I) is
110   begin
111     IRF_ACK_I <= IRF_STB_O and (IRF_WE_O or dbg_ack);
112
113     if rising_edge(CLK_I) then
114       dbg_ack <= IRF_STB_O;
115     end if;
116
117     if rising_edge(CLK_I) and IRF_STB_O = '1' then
118       if IRF_WE_O = '0' then
119         case conv_integer(IRF_ADR_O) is
120           when 0 => IRF_DAT_I <= dbg_mem0;
121           when 1 => IRF_DAT_I <= dbg_mem1;
122           when 2 => IRF_DAT_I <= dbg_mem2;
123           when 3 => IRF_DAT_I <= dbg_mem3;
124           when others => IRF_DAT_I <= (others => '0');
125         end case;
126       else
127         case conv_integer(IRF_ADR_O) is
128           when 1 => dbg_mem1 <= IRF_DAT_O;
129           when 2 => dbg_mem2 <= IRF_DAT_O;
130           when 3 => dbg_mem3 <= IRF_DAT_O;
131           when others => null;
132         end case;
133       end if;
134     end if;
135   end process;
136   
137 --------------------------------------------------------------------------------
138
139   UUT_FEED : process is
140   begin
141     STB_I <= '0';
142         
143     wait for offset;
144     wait for 4*period;
145
146     for i in 0 to WAVE_SIZE loop
147       dbg_mem0 <= (others => '0');
148       dbg_mem0(LUT_ADR_O'RANGE) <= conv_std_logic_vector(i, LUT_ADR_W);
149       
150       STB_I <= '1';
151       wait until rising_edge(CLK_I) and ACK_O = '1';
152       STB_I <= '0';
153       wait for 4*period;
154     end loop;
155     
156     wait;
157   end process;
158   
159 end testbench;
160