]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - tb/tb_vector_scale.vhd
Wave_table initialization data format modified.
[fpga/pwm.git] / tb / tb_vector_scale.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_scale is
7 end tb_vector_scale;
8
9 --------------------------------------------------------------------------------
10
11 architecture testbench of tb_vector_scale is
12
13   constant period : time := 500 ns;
14   constant offset : time := 0 us;
15
16   constant IRF_ADR_W : integer := 5;
17   
18
19   signal ACK_O : std_logic;
20   signal CLK_I : std_logic;
21   signal RST_I : std_logic;
22   signal STB_I : std_logic;
23
24   signal IRF_ACK_I : std_logic;
25   signal IRF_ADR_O : std_logic_vector (IRF_ADR_W-1 downto 0);
26   signal IRF_CYC_O : std_logic;
27   signal IRF_DAT_I : std_logic_vector (15 downto 0);
28   signal IRF_DAT_O : std_logic_vector (15 downto 0);
29   signal IRF_STB_O : std_logic;
30   signal IRF_WE_O  : std_logic;
31
32   signal MUL_A    : std_logic_vector (15 downto 0);
33   signal MUL_B    : std_logic_vector (15 downto 0);
34   signal MUL_PROD : std_logic_vector (31 downto 0);
35
36
37   subtype word_t is std_logic_vector (15 downto 0);
38   
39   signal dbg_mem0x05 : word_t    := (others => '0');
40   signal dbg_mem0x10 : word_t    := (others => '0');
41   signal dbg_mem0x11 : word_t    := (others => '0');
42   signal dbg_ack     : std_logic := '0';
43
44 --------------------------------------------------------------------------------
45   
46 begin
47
48   uut : entity work.vector_scale
49     generic map (
50       IRF_ADR_W  => IRF_ADR_W,
51       BASE       => 0,
52       SCALE_OFF  => 5,
53       PHASE_BASE => 16,
54       VECTOR_OFF => 0,
55       SCALED_OFF => 1,
56       VECTOR_W   => 10)
57     port map (
58       ACK_O     => ACK_O,
59       CLK_I     => CLK_I,
60       RST_I     => RST_I,
61       STB_I     => STB_I,
62       MUL_A     => MUL_A,
63       MUL_B     => MUL_B,
64       MUL_PROD  => MUL_PROD,
65       IRF_ACK_I => IRF_ACK_I,
66       IRF_ADR_O => IRF_ADR_O,
67       IRF_DAT_I => IRF_DAT_I,
68       IRF_DAT_O => IRF_DAT_O,
69       IRF_STB_O => IRF_STB_O,
70       IRF_WE_O  => IRF_WE_O);
71
72   multiplier_1 : entity work.multiplier
73     port map (
74       A    => MUL_A,
75       B    => MUL_B,
76       prod => MUL_PROD);
77
78   
79   SYSCON_CLK : process is
80   begin
81     CLK_I <= '0';
82     wait for offset;
83     loop
84       CLK_I <= '1';
85       wait for period/2;
86       CLK_I <= '0';
87       wait for period/2;
88     end loop;
89   end process;
90
91   SYSCON_RST : process is
92   begin
93     RST_I <= '0';
94     wait for offset;
95     wait for 0.75*period;
96     RST_I <= '1';
97     wait for 2*period;
98     RST_I <= '0';
99     wait;
100   end process;
101
102   
103   DBG_MEM : process (IRF_STB_O, CLK_I) is
104   begin
105     IRF_ACK_I <= IRF_STB_O and (IRF_WE_O or dbg_ack);
106
107     if rising_edge(CLK_I) then
108       dbg_ack <= IRF_STB_O;
109     end if;
110
111     if rising_edge(CLK_I) and IRF_STB_O = '1' then
112       if IRF_WE_O = '0' then
113         case conv_integer(IRF_ADR_O) is
114           when 16#05# => IRF_DAT_I <= dbg_mem0x05;
115           when 16#10# => IRF_DAT_I <= dbg_mem0x10;
116           when 16#11# => IRF_DAT_I <= dbg_mem0x11;
117           when others =>
118             IRF_DAT_I <= (others => '0');
119             report "Reading from non-existing register" severity warning;
120         end case;
121       else
122         case conv_integer(IRF_ADR_O) is
123           --when 16#05# => dbg_mem0x05 <= IRF_DAT_O;
124           --when 16#10# => dbg_mem0x10 <= IRF_DAT_O;
125           when 16#11# => dbg_mem0x11 <= IRF_DAT_O;
126           when others =>
127             report "Writing to read-only registers" severity error;
128         end case;
129       end if;
130     end if;
131   end process;
132   
133 --------------------------------------------------------------------------------
134
135   UUT_FEED : process is
136   begin
137     STB_I <= '0';
138     
139     wait for offset;
140     wait for 4*period;
141
142     for i in 0 to 10 loop
143       dbg_mem0x10 <= "0000000111111111";
144       
145       dbg_mem0x05 <= conv_std_logic_vector(i*(2**10), 16);
146
147       wait for 0.75*period;
148       STB_I <= '1';
149       wait for 0.25*period;
150       wait until rising_edge(CLK_I) and ACK_O = '1';
151       wait for 0.25*period;
152       STB_I <= '0';
153       wait for 0.75*period;
154
155       wait for 4*period;
156     end loop;
157     
158     wait;
159   end process;
160   
161 end testbench;
162