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 2

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
      i2c_adr : std_logic_vector(6 downto 0)
126
    );
127
    port
128
    (
129
      scl     : inout std_logic;
130
      sda     : inout std_logic
131
    );
132
  end component i2c_slave_model;
133
  ------------------------------------------------------------------------------
134
 
135
  signal   clk         : std_logic := '0';
136
  signal   s_rst       : std_logic := '1';
137
 
138
  signal   cs_start_0  : std_logic := '0';
139
  signal   cs_busy_0   : std_logic;
140
  signal   cs_status_0 : std_logic_vector(2 downto 0);
141
 
142
  signal   cs_start_1  : std_logic := '0';
143
  signal   cs_busy_1   : std_logic;
144
  signal   cs_status_1 : std_logic_vector(2 downto 0);
145
 
146
  signal   scl_o_0     : std_logic_vector(0 to 0) := (others => '1');
147
  signal   sda_o_0     : std_logic_vector(0 to 0) := (others => '1');
148
  signal   scl_o_1     : std_logic_vector(0 to 0) := (others => '1');
149
  signal   sda_o_1     : std_logic_vector(0 to 0) := (others => '1');
150
  signal   scl         : std_logic_vector(0 to 0) := (others => 'H');
151
  signal   sda         : std_logic_vector(0 to 0) := (others => 'H');
152
 
153
  type real_vector is array (natural range <>) of real;
154
  signal   scl_real    : real_vector(0 to 0);
155
  signal   sda_real    : real_vector(0 to 0);
156
  signal   scl_quant   : bit_vector(0 to 0);
157
  signal   sda_quant   : bit_vector(0 to 0);
158
  signal   scl_nquant  : bit_vector(0 to 0) := (others => '1');
159
  signal   sda_nquant  : bit_vector(0 to 0) := (others => '1');
160
 
161
begin
162
 
163
  clk   <= not(clk) after c_p_clk / 2;
164
  s_rst <= '1', '0' after 113 ns;
165
 
166
  ------------------------------------------------------------------------------
167
  -- Generate signal to launch the sequencer #0
168
  process
169
  begin
170
    cs_start_0 <= '0';
171
    wait for 2000 ns;
172
    wait until rising_edge(clk);
173
    cs_start_0 <= '1';
174
    wait until rising_edge(clk);
175
    cs_start_0 <= '0';
176
    wait;
177
  end process;
178
  ------------------------------------------------------------------------------
179
 
180
  ------------------------------------------------------------------------------
181
  -- Generate signal to launch the sequencer #1
182
  process
183
  begin
184
    cs_start_1 <= '0';
185
    wait for 2000 ns;
186
    wait until rising_edge(clk);
187
    cs_start_1 <= '1';
188
    wait until rising_edge(clk);
189
    cs_start_1 <= '0';
190
    wait;
191
  end process;
192
  ------------------------------------------------------------------------------
193
 
194
  ------------------------------------------------------------------------------
195
  dut_inst0 : iicmb_m_sq
196
    generic map
197
    (
198
      g_bus_num   => 1,
199
      g_f_clk     => c_f_clk,
200
      g_f_scl_0   => c_f_scl_0,
201
      g_cmd       =>
202
        (
203
          scmd_wait(1),                             -- Wait for 1 ms
204
          scmd_set_bus(0),                          -- Select bus #0
205
          scmd_write_byte("0100001", x"03", x"4A"), -- Write byte
206
          scmd_write_byte("0100001", x"05", x"27")  -- Write byte
207
        )
208
    )
209
    port map
210
    (
211
      clk         => clk,
212
      s_rst       => s_rst,
213
      cs_start    => cs_start_0,
214
      cs_busy     => cs_busy_0,
215
      cs_status   => cs_status_0,
216
      scl_i       => to_stdlogicvector(scl_quant),
217
      sda_i       => to_stdlogicvector(sda_quant),
218
      scl_o       => scl_o_0,
219
      sda_o       => sda_o_0
220
    );
221
  ------------------------------------------------------------------------------
222
 
223
  ------------------------------------------------------------------------------
224
  dut_inst1 : iicmb_m_sq
225
    generic map
226
    (
227
      g_bus_num   => 1,
228
      g_f_clk     => c_f_clk,
229
      g_f_scl_0   => c_f_scl_1,
230
      g_cmd       =>
231
        (
232
          scmd_wait(1),                             -- Wait for 1 ms
233
          scmd_set_bus(0),                          -- Select bus #0
234
          scmd_write_byte("0100001", x"03", x"4A"), -- Write byte
235
          scmd_write_byte("0100001", x"05", x"67")  -- Write byte
236
        )
237
    )
238
    port map
239
    (
240
      clk         => clk,
241
      s_rst       => s_rst,
242
      cs_start    => cs_start_1,
243
      cs_busy     => cs_busy_1,
244
      cs_status   => cs_status_1,
245
      scl_i       => to_stdlogicvector(scl_quant),
246
      sda_i       => to_stdlogicvector(sda_quant),
247
      scl_o       => scl_o_1,
248
      sda_o       => sda_o_1
249
    );
250
  ------------------------------------------------------------------------------
251
 
252
  scl(0) <= '0' when (scl_o_0(0) = '0') else 'Z';
253
  sda(0) <= '0' when (sda_o_0(0) = '0') else 'Z';
254
  scl(0) <= '0' when (scl_o_1(0) = '0') else 'Z';
255
  sda(0) <= '0' when (sda_o_1(0) = '0') else 'Z';
256
  scl(0) <= 'H'; -- Pull-up
257
  sda(0) <= 'H'; -- Pull-up
258
 
259
  ----------------------------------------------------------------------------
260
  wire_mdl_inst_0 : wire_mdl
261
    generic map
262
    (
263
      g_resistance_0       => 40.0,
264
      g_resistance_1       => 4000.0,
265
      g_capacitance        => 200.0, -- In pF
266
      g_initial_level      => '1'
267
    )
268
    port map
269
    (
270
      sig_in               => scl_nquant(0),
271
      sig_out              => scl_real(0),
272
      sig_out_l            => scl_quant(0)
273
    );
274
  ----------------------------------------------------------------------------
275
 
276
  ----------------------------------------------------------------------------
277
  wire_mdl_inst_1 : wire_mdl
278
    generic map
279
    (
280
      g_resistance_0       => 40.0,
281
      g_resistance_1       => 4000.0,
282
      g_capacitance        => 200.0, -- In pF
283
      g_initial_level      => '1'
284
    )
285
    port map
286
    (
287
      sig_in               => sda_nquant(0),
288
      sig_out              => sda_real(0),
289
      sig_out_l            => sda_quant(0)
290
    );
291
  ----------------------------------------------------------------------------
292
 
293
  ----------------------------------------------------------------------------
294
  i2c_slave_model_inst0 : i2c_slave_model
295
    generic map
296
    (
297
      i2c_adr => "0100001"
298
    )
299
    port map
300
    (
301
      scl     => scl(0),
302
      sda     => sda(0)
303
    );
304
  ----------------------------------------------------------------------------
305
 
306
  scl_nquant <= to_bitvector(to_x01(scl));
307
  sda_nquant <= to_bitvector(to_x01(sda));
308
 
309
end architecture beh;
310
--==============================================================================
311
 

powered by: WebSVN 2.1.0

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