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 5

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

powered by: WebSVN 2.1.0

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