]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - tb/tb_mcc.vhd
738cc10aad141ecf17eaf829d848f766e4b399c9
[fpga/pwm.git] / tb / tb_mcc.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_mcc is
7 end tb_mcc;
8
9 --------------------------------------------------------------------------------
10
11 architecture testbench of tb_mcc is
12
13   constant period : time := 1 us;
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
37   signal LUT_ADR_O : std_logic_vector (LUT_ADR_W-1 downto 0);
38   signal LUT_DAT_I : std_logic_vector (LUT_DAT_W-1 downto 0);
39   signal LUT_STB_O : std_logic;
40
41   
42   subtype word_t is std_logic_vector (15 downto 0);
43   
44   signal dbg_mem0 : word_t    := "0000000000000010";  -- read only by mcc_master
45   signal dbg_mem1 : word_t    := (others => '0');     -- read only by vector_gen
46   signal dbg_mem2 : word_t    := (others => '0');
47   signal dbg_mem3 : word_t    := (others => '0');
48   signal dbg_mem4 : word_t    := (others => '0');
49   signal dbg_ack  : std_logic := '0';
50
51 --------------------------------------------------------------------------------
52
53 begin
54
55   uut : entity work.mcc
56     generic map (
57       LUT_ADR_W => LUT_ADR_W,
58       LUT_DAT_W => LUT_DAT_W,
59       IRF_ADR_W => IRF_ADR_W)
60     port map (
61       ACK_O      => ACK_O,
62       CLK_I      => CLK_I,
63       RST_I      => RST_I,
64       STB_I      => STB_I,
65       LUT_STB_O  => LUT_STB_O,
66       LUT_ADR_O  => LUT_ADR_O,
67       LUT_DAT_I  => LUT_DAT_I,
68       IRC_DAT_I  => (others => '0'),
69       PWM_DAT_O  => open,
70       PWM1_STB_O => open,
71       PWM2_STB_O => open,
72       PWM3_STB_O => open,
73       IRF_ACK_I  => IRF_ACK_I,
74       IRF_ADR_O  => IRF_ADR_O,
75       IRF_DAT_I  => IRF_DAT_I,
76       IRF_DAT_O  => IRF_DAT_O,
77       IRF_STB_O  => IRF_STB_O,
78       IRF_WE_O   => IRF_WE_O);
79
80   wave_table_1 : entity work.wave_table
81     generic map (
82       DAT_W     => LUT_DAT_W,
83       ADR_W     => LUT_ADR_W,
84       INIT_FILE => LUT_INIT_FILE)
85     port map (
86       ACK_O => open,
87       ADR_I => LUT_ADR_O,
88       CLK_I => CLK_I,
89       DAT_I => (others => '0'),
90       DAT_O => LUT_DAT_I,
91       STB_I => LUT_STB_O,
92       WE_I  => '0');
93   
94   
95   SYSCON_CLK : process is
96   begin
97     CLK_I <= '0';
98     wait for offset;
99     loop
100       CLK_I <= '1';
101       wait for period/2;
102       CLK_I <= '0';
103       wait for period/2;
104     end loop;
105   end process;
106
107   SYSCON_RST : process is
108   begin
109     RST_I <= '0';
110     wait for offset;
111     wait for 0.75*period;
112     RST_I <= '1';
113     wait for 2*period;
114     RST_I <= '0';
115     wait;
116   end process;
117
118   
119   DBG_MEM : process (IRF_STB_O, CLK_I) is
120   begin
121     IRF_ACK_I <= IRF_STB_O and (IRF_WE_O or dbg_ack);
122
123     if rising_edge(CLK_I) then
124       dbg_ack <= IRF_STB_O;
125     end if;
126
127     if rising_edge(CLK_I) and IRF_STB_O = '1' then
128       if IRF_WE_O = '0' then
129         case conv_integer(IRF_ADR_O) is
130           when 0 => IRF_DAT_I <= dbg_mem0;
131           when 1 => IRF_DAT_I <= dbg_mem1;
132           when 2 => IRF_DAT_I <= dbg_mem2;
133           when 3 => IRF_DAT_I <= dbg_mem3;
134           when 4 => IRF_DAT_I <= dbg_mem4;
135           when others => IRF_DAT_I <= (others => '0');
136         end case;
137       else
138         case conv_integer(IRF_ADR_O) is
139           when 2 => dbg_mem2 <= IRF_DAT_O;
140           when 3 => dbg_mem3 <= IRF_DAT_O;
141           when 4 => dbg_mem4 <= IRF_DAT_O;
142           when others => null;
143         end case;
144       end if;
145     end if;
146   end process;
147   
148 --------------------------------------------------------------------------------
149
150   UUT_FEED : process is
151   begin
152     STB_I <= '0';
153         
154     wait for offset;
155     wait for 4*period;
156
157     for i in 0 to 1 loop
158       dbg_mem1 <= conv_std_logic_vector(i, 16);
159       
160       STB_I <= '1';
161       wait until rising_edge(CLK_I) and ACK_O = '1';
162       STB_I <= '0';
163       wait for 4*period;
164     end loop;
165     
166     wait;
167   end process;
168   
169 end testbench;
170