~ruther/vhdl-i2c

ref: 57bc4031f549c4c98b9f726cf3ca7681299aa521 vhdl-i2c/tb/i2c/startstop_condition_detector_tb.vhd -rw-r--r-- 2.9 KiB
57bc4031 — Rutherther feat: store address, rw in address generator or detector 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
library ieee;
use ieee.std_logic_1164.all;

library i2c;

library vunit_lib;
context vunit_lib.vunit_context;

entity startstop_condition_detector_tb is

  generic (
    runner_cfg : string);

end entity startstop_condition_detector_tb;

architecture tb of startstop_condition_detector_tb is
  signal clk : std_logic := '0';
  constant CLK_PERIOD : time := 10 ns;

  signal rst_n : std_logic := '0';

  signal sda, scl : std_logic;

  signal start, stop : std_logic;
begin  -- architecture tb
  uut: entity i2c.startstop_condition_detector
    port map (
      clk_i   => clk,
      sda_i   => sda,
      scl_i   => scl,
      start_o => start,
      stop_o  => stop);

  clk <= not clk after CLK_PERIOD / 2;
  rst_n <= '1' after 2 * CLK_PERIOD;

  main: process is
  begin  -- process
    sda <= '1';
    wait until rising_edge(clk);
    scl <= '1';
    wait until rst_n = '1';
    wait until falling_edge(clk);

    test_runner_setup(runner, runner_cfg);
    set_stop_level(failure);

    while test_suite loop
      if run("scl_high_start_stop") then
        -- start
        sda <= '0';
        wait until rising_edge(clk);
        check_equal(start, '1');
        check_equal(stop, '0');
        sda <= '1';
        wait until rising_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '1');
        sda <= '1';
        wait until rising_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '0');
        sda <= '1';
      elsif run("scl_low") then
        scl <= '0';
        sda <= '0';
        wait until falling_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '0');
        sda <= '1';
        wait until falling_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '0');
        sda <= '1';
        wait until falling_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '0');
        sda <= '1';
      elsif run("scl_low_then_high") then
        scl <= '0';
        sda <= '0';
        wait until rising_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '0');
        sda <= '1';
        wait until rising_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '0');
        sda <= '1';
        wait until rising_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '0');
        sda <= '1';
        wait until rising_edge(clk);
        scl <= '1';
        wait until rising_edge(clk);
        sda <= '0';
        wait until rising_edge(clk);
        check_equal(start, '1');
        check_equal(stop, '0');
        sda <= '1';
        wait until rising_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '1');
        sda <= '1';
        wait until rising_edge(clk);
        check_equal(start, '0');
        check_equal(stop, '0');
        sda <= '1';
      end if;
    end loop;

    test_runner_cleanup(runner);
  end process main;

end architecture tb;
Do not follow this link