]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - tb/tb_pwm_min.vhd
PWM3 wrapper for 3 PWMs entities.
[fpga/pwm.git] / tb / tb_pwm_min.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_pwm_min is
7 end tb_pwm_min;
8
9 --------------------------------------------------------------------------------
10
11 architecture testbench of tb_pwm_min is
12
13   constant period : time := 1 us;
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_DAT_I : std_logic_vector (15 downto 0);
27   signal IRF_DAT_O : std_logic_vector (15 downto 0);
28   signal IRF_STB_O : std_logic;
29   signal IRF_WE_O  : std_logic;
30
31   subtype word_t is std_logic_vector (15 downto 0);
32
33   signal dbg_ack : std_logic := '0';
34   
35   signal dbg_mem0x06 : word_t := (others => '0');
36   signal dbg_mem0x11 : word_t := (others => '0');
37   signal dbg_mem0x15 : word_t := (others => '0');
38   signal dbg_mem0x19 : word_t := (others => '0');
39
40 --------------------------------------------------------------------------------
41   
42 begin
43
44   uut : entity work.pwm_min
45     generic map (
46       IRF_ADR_W  => IRF_ADR_W,
47       PWM_W      => 10,
48       BASE       => 0,
49       PWMMIN_OFF => 16#06#,
50       P_BASE     => 16#10#,
51       P_SIZE     => 4,
52       PWM_OFF    => 1)
53     port map (
54       ACK_O     => ACK_O,
55       CLK_I     => CLK_I,
56       RST_I     => RST_I,
57       STB_I     => STB_I,
58       IRF_ACK_I => IRF_ACK_I,
59       IRF_ADR_O => IRF_ADR_O,
60       IRF_DAT_I => IRF_DAT_I,
61       IRF_DAT_O => IRF_DAT_O,
62       IRF_STB_O => IRF_STB_O,
63       IRF_WE_O  => IRF_WE_O);
64   
65   
66   SYSCON_CLK : process is
67   begin
68     CLK_I <= '0';
69     wait for offset;
70     loop
71       CLK_I <= '1';
72       wait for period/2;
73       CLK_I <= '0';
74       wait for period/2;
75     end loop;
76   end process;
77
78   SYSCON_RST : process is
79   begin
80     RST_I <= '0';
81     wait for offset;
82     wait for 0.75*period;
83     RST_I <= '1';
84     wait for 2*period;
85     RST_I <= '0';
86     wait;
87   end process;
88
89   
90   DBG_MEM : process (IRF_STB_O, CLK_I) is
91   begin
92     IRF_ACK_I <= IRF_STB_O and (IRF_WE_O or dbg_ack);
93
94     if rising_edge(CLK_I) then
95       dbg_ack <= IRF_STB_O;
96     end if;
97
98     if rising_edge(CLK_I) and IRF_STB_O = '1' then
99       if IRF_WE_O = '0' then
100         case conv_integer(IRF_ADR_O) is
101           when 16#11# => IRF_DAT_I <= dbg_mem0x11;
102           when 16#15# => IRF_DAT_I <= dbg_mem0x15;
103           when 16#19# => IRF_DAT_I <= dbg_mem0x19;
104           when others =>
105             IRF_DAT_I <= (others => 'X');
106             report "Reading from non-readable register" severity warning;
107         end case;
108       else
109         case conv_integer(IRF_ADR_O) is
110           when 16#06# => dbg_mem0x06 <= IRF_DAT_O;
111           when others =>
112             report "Writing to read-only registers" severity error;
113         end case;
114       end if;
115     end if;
116   end process;
117   
118 --------------------------------------------------------------------------------
119
120   UUT_FEED : process is
121   begin
122     STB_I <= '0';
123     
124     wait for offset;
125     wait for 4*period;
126
127     for i in 0 to 0 loop
128       dbg_mem0x11 <= "0000000111111111";
129       dbg_mem0x15 <= "0000000000100000";
130       dbg_mem0x19 <= "0000000001000000";
131       
132       wait for 0.75*period;
133       STB_I <= '1';
134       wait for 0.25*period;
135       wait until rising_edge(CLK_I) and ACK_O = '1';
136       wait for 0.25*period;
137       STB_I <= '0';
138       wait for 0.75*period;
139
140       wait for 4*period;
141     end loop;
142     
143     wait;
144   end process;
145   
146 end testbench;
147