OpenCores
URL https://opencores.org/ocsvn/iicmb/iicmb/trunk

Subversion Repositories iicmb

[/] [iicmb/] [trunk/] [src_tb/] [iicmb_m_sq_arb_tb.vhd] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sshuv2
 
2
--==============================================================================
3
--                                                                             |
4
--    Project: IIC Multiple Bus Controller (IICMB)                             |
5
--                                                                             |
6
--    Module:  Testbench for iicmb_m_sq. Testing arbitration and clock         |
7
--             synchronization.                                                |
8
--    Version:                                                                 |
9
--             1.0,   April 29, 2016                                           |
10
--                                                                             |
11
--    Author:  Sergey Shuvalkin, (sshuv2@opencores.org)                        |
12
--                                                                             |
13
--==============================================================================
14
--==============================================================================
15
-- Copyright (c) 2016, Sergey Shuvalkin                                        |
16
-- All rights reserved.                                                        |
17
--                                                                             |
18
-- Redistribution and use in source and binary forms, with or without          |
19
-- modification, are permitted provided that the following conditions are met: |
20
--                                                                             |
21
-- 1. Redistributions of source code must retain the above copyright notice,   |
22
--    this list of conditions and the following disclaimer.                    |
23
-- 2. Redistributions in binary form must reproduce the above copyright        |
24
--    notice, this list of conditions and the following disclaimer in the      |
25
--    documentation and/or other materials provided with the distribution.     |
26
--                                                                             |
27
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
28
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   |
29
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  |
30
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE    |
31
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR         |
32
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF        |
33
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    |
34
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN     |
35
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)     |
36
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  |
37
-- POSSIBILITY OF SUCH DAMAGE.                                                 |
38
--==============================================================================
39
 
40
 
41
library ieee;
42
use ieee.std_logic_1164.all;
43
use ieee.numeric_std.all;
44
 
45
library iicmb;
46
use iicmb.iicmb_pkg.all;
47
 
48
use work.test.all;
49
 
50
 
51
--==============================================================================
52
entity iicmb_m_sq_arb_tb is
53
end entity iicmb_m_sq_arb_tb;
54
--==============================================================================
55
 
56
--==============================================================================
57
architecture beh of iicmb_m_sq_arb_tb is
58
 
59
  constant c_f_clk   : real      := 100000.0; -- in kHz
60
  constant c_f_scl_0 : real      :=    100.0; -- in kHz
61
  constant c_f_scl_1 : real      :=     66.0; -- in kHz
62
  constant c_p_clk   : time      := integer(1000000000.0/c_f_clk) * 1 ps; -- Period of 'clk' in ps.
63
 
64
  ------------------------------------------------------------------------------
65
  component iicmb_m_sq is
66
    generic
67
    (
68
      g_bus_num     :       positive range 1 to 16 := 1;
69
      g_f_clk       :       real                   := 100000.0;
70
      g_f_scl_0     :       real                   :=    100.0;
71
      g_f_scl_1     :       real                   :=    100.0;
72
      g_f_scl_2     :       real                   :=    100.0;
73
      g_f_scl_3     :       real                   :=    100.0;
74
      g_f_scl_4     :       real                   :=    100.0;
75
      g_f_scl_5     :       real                   :=    100.0;
76
      g_f_scl_6     :       real                   :=    100.0;
77
      g_f_scl_7     :       real                   :=    100.0;
78
      g_f_scl_8     :       real                   :=    100.0;
79
      g_f_scl_9     :       real                   :=    100.0;
80
      g_f_scl_a     :       real                   :=    100.0;
81
      g_f_scl_b     :       real                   :=    100.0;
82
      g_f_scl_c     :       real                   :=    100.0;
83
      g_f_scl_d     :       real                   :=    100.0;
84
      g_f_scl_e     :       real                   :=    100.0;
85
      g_f_scl_f     :       real                   :=    100.0;
86
      g_cmd         :       seq_cmd_type_array     := c_empty_array
87
    );
88
    port
89
    (
90
      clk           : in    std_logic;
91
      s_rst         : in    std_logic;
92
      cs_start      : in    std_logic;
93
      cs_busy       :   out std_logic;
94
      cs_status     :   out std_logic_vector(2 downto 0);
95
      scl_i         : in    std_logic_vector(0 to g_bus_num - 1);
96
      sda_i         : in    std_logic_vector(0 to g_bus_num - 1);
97
      scl_o         :   out std_logic_vector(0 to g_bus_num - 1);
98
      sda_o         :   out std_logic_vector(0 to g_bus_num - 1)
99
    );
100
  end component iicmb_m_sq;
101
  ------------------------------------------------------------------------------
102
 
103
  ------------------------------------------------------------------------------
104
  component wire_mdl is
105
    generic
106
    (
107
      g_resistance_0       :       real       := 1.0; -- In Ohms
108
      g_resistance_1       :       real       := 1.0; -- In Ohms
109
      g_capacitance        :       real       := 1.0; -- In pF
110
      g_initial_level      :       bit        := '0'
111
    );
112
    port
113
    (
114
      sig_in               : in    bit;
115
      sig_out              :   out real;
116
      sig_out_l            :   out bit
117
    );
118
  end component wire_mdl;
119
  ------------------------------------------------------------------------------
120
 
121
  ------------------------------------------------------------------------------
122
  component i2c_slave_model is
123
    generic
124
    (
125 4 sshuv2
      I2C_ADR : integer
126 2 sshuv2
    );
127
    port
128
    (
129
      scl     : inout std_logic;
130
      sda     : inout std_logic
131
    );
132
  end component i2c_slave_model;
133
  ------------------------------------------------------------------------------
134
 
135 4 sshuv2
  constant c_slave_addr : std_logic_vector(6 downto 0) := "0100001";
136
  constant c_i2c_adr    : integer                      := to_integer(unsigned(c_slave_addr));
137 2 sshuv2
 
138 4 sshuv2
  signal   clk          : std_logic := '0';
139
  signal   s_rst        : std_logic := '1';
140 2 sshuv2
 
141 4 sshuv2
  signal   cs_start_0   : std_logic := '0';
142
  signal   cs_busy_0    : std_logic;
143
  signal   cs_status_0  : std_logic_vector(2 downto 0);
144 2 sshuv2
 
145 4 sshuv2
  signal   cs_start_1   : std_logic := '0';
146
  signal   cs_busy_1    : std_logic;
147
  signal   cs_status_1  : std_logic_vector(2 downto 0);
148 2 sshuv2
 
149 4 sshuv2
  signal   scl_o_0      : std_logic_vector(0 to 0) := (others => '1');
150
  signal   sda_o_0      : std_logic_vector(0 to 0) := (others => '1');
151
  signal   scl_o_1      : std_logic_vector(0 to 0) := (others => '1');
152
  signal   sda_o_1      : std_logic_vector(0 to 0) := (others => '1');
153
  signal   scl          : std_logic_vector(0 to 0) := (others => 'H');
154
  signal   sda          : std_logic_vector(0 to 0) := (others => 'H');
155
 
156 2 sshuv2
  type real_vector is array (natural range <>) of real;
157 4 sshuv2
  signal   scl_real     : real_vector(0 to 0);
158
  signal   sda_real     : real_vector(0 to 0);
159
  signal   scl_quant    : bit_vector(0 to 0);
160
  signal   sda_quant    : bit_vector(0 to 0);
161
  signal   scl_nquant   : bit_vector(0 to 0) := (others => '1');
162
  signal   sda_nquant   : bit_vector(0 to 0) := (others => '1');
163 2 sshuv2
 
164
begin
165
 
166
  clk   <= not(clk) after c_p_clk / 2;
167
  s_rst <= '1', '0' after 113 ns;
168
 
169
  ------------------------------------------------------------------------------
170
  -- Generate signal to launch the sequencer #0
171
  process
172
  begin
173
    cs_start_0 <= '0';
174
    wait for 2000 ns;
175
    wait until rising_edge(clk);
176
    cs_start_0 <= '1';
177
    wait until rising_edge(clk);
178
    cs_start_0 <= '0';
179
    wait;
180
  end process;
181
  ------------------------------------------------------------------------------
182
 
183
  ------------------------------------------------------------------------------
184
  -- Generate signal to launch the sequencer #1
185
  process
186
  begin
187
    cs_start_1 <= '0';
188
    wait for 2000 ns;
189
    wait until rising_edge(clk);
190
    cs_start_1 <= '1';
191
    wait until rising_edge(clk);
192
    cs_start_1 <= '0';
193
    wait;
194
  end process;
195
  ------------------------------------------------------------------------------
196
 
197
  ------------------------------------------------------------------------------
198
  dut_inst0 : iicmb_m_sq
199
    generic map
200
    (
201
      g_bus_num   => 1,
202
      g_f_clk     => c_f_clk,
203
      g_f_scl_0   => c_f_scl_0,
204
      g_cmd       =>
205
        (
206 4 sshuv2
          scmd_wait(1),                                -- Wait for 1 ms
207
          scmd_set_bus(0),                             -- Select bus #0
208
          scmd_write_byte(c_slave_addr, x"03", x"4A"), -- Write byte
209
          scmd_write_byte(c_slave_addr, x"05", x"27")  -- Write byte
210 2 sshuv2
        )
211
    )
212
    port map
213
    (
214
      clk         => clk,
215
      s_rst       => s_rst,
216
      cs_start    => cs_start_0,
217
      cs_busy     => cs_busy_0,
218
      cs_status   => cs_status_0,
219
      scl_i       => to_stdlogicvector(scl_quant),
220
      sda_i       => to_stdlogicvector(sda_quant),
221
      scl_o       => scl_o_0,
222
      sda_o       => sda_o_0
223
    );
224
  ------------------------------------------------------------------------------
225
 
226
  ------------------------------------------------------------------------------
227
  dut_inst1 : iicmb_m_sq
228
    generic map
229
    (
230
      g_bus_num   => 1,
231
      g_f_clk     => c_f_clk,
232
      g_f_scl_0   => c_f_scl_1,
233
      g_cmd       =>
234
        (
235 4 sshuv2
          scmd_wait(1),                                -- Wait for 1 ms
236
          scmd_set_bus(0),                             -- Select bus #0
237
          scmd_write_byte(c_slave_addr, x"03", x"4A"), -- Write byte
238
          scmd_write_byte(c_slave_addr, x"05", x"67")  -- Write byte
239 2 sshuv2
        )
240
    )
241
    port map
242
    (
243
      clk         => clk,
244
      s_rst       => s_rst,
245
      cs_start    => cs_start_1,
246
      cs_busy     => cs_busy_1,
247
      cs_status   => cs_status_1,
248
      scl_i       => to_stdlogicvector(scl_quant),
249
      sda_i       => to_stdlogicvector(sda_quant),
250
      scl_o       => scl_o_1,
251
      sda_o       => sda_o_1
252
    );
253
  ------------------------------------------------------------------------------
254
 
255
  scl(0) <= '0' when (scl_o_0(0) = '0') else 'Z';
256
  sda(0) <= '0' when (sda_o_0(0) = '0') else 'Z';
257
  scl(0) <= '0' when (scl_o_1(0) = '0') else 'Z';
258
  sda(0) <= '0' when (sda_o_1(0) = '0') else 'Z';
259
  scl(0) <= 'H'; -- Pull-up
260
  sda(0) <= 'H'; -- Pull-up
261
 
262
  ----------------------------------------------------------------------------
263
  wire_mdl_inst_0 : wire_mdl
264
    generic map
265
    (
266
      g_resistance_0       => 40.0,
267
      g_resistance_1       => 4000.0,
268
      g_capacitance        => 200.0, -- In pF
269
      g_initial_level      => '1'
270
    )
271
    port map
272
    (
273
      sig_in               => scl_nquant(0),
274
      sig_out              => scl_real(0),
275
      sig_out_l            => scl_quant(0)
276
    );
277
  ----------------------------------------------------------------------------
278
 
279
  ----------------------------------------------------------------------------
280
  wire_mdl_inst_1 : wire_mdl
281
    generic map
282
    (
283
      g_resistance_0       => 40.0,
284
      g_resistance_1       => 4000.0,
285
      g_capacitance        => 200.0, -- In pF
286
      g_initial_level      => '1'
287
    )
288
    port map
289
    (
290
      sig_in               => sda_nquant(0),
291
      sig_out              => sda_real(0),
292
      sig_out_l            => sda_quant(0)
293
    );
294
  ----------------------------------------------------------------------------
295
 
296
  ----------------------------------------------------------------------------
297
  i2c_slave_model_inst0 : i2c_slave_model
298
    generic map
299
    (
300 4 sshuv2
      I2C_ADR => c_i2c_adr
301 2 sshuv2
    )
302
    port map
303
    (
304
      scl     => scl(0),
305
      sda     => sda(0)
306
    );
307
  ----------------------------------------------------------------------------
308
 
309
  scl_nquant <= to_bitvector(to_x01(scl));
310
  sda_nquant <= to_bitvector(to_x01(sda));
311
 
312
end architecture beh;
313
--==============================================================================
314
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.