aboutsummaryrefslogtreecommitdiffstats
path: root/tests/simple/i2c_master_tests.v
blob: 3aa596632db5dcba23b44d28173ab60f0935bf86 (plain)
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
// one of my early test cases was the OpenCores I2C master
// This is a collection of stripped down code snippets from
// this core that triggered bugs in early versions of yosys.

// from i2c_master_bit_ctrl
module i2c_test01(clk, rst, nReset, al);

	input clk, rst, nReset;
	output reg al;

	reg cmd_stop;
	always @(posedge clk or negedge nReset)
	  if (~nReset)
	    cmd_stop <= #1 1'b0;
	  else if (rst)
	    cmd_stop <= #1 1'b0;

	always @(posedge clk or negedge nReset)
	  if (~nReset)
	    al <= #1 1'b0;
	  else if (rst)
	    al <= #1 1'b0;
	  else
	    al <= #1 ~cmd_stop;

endmodule

// from i2c_master_bit_ctrl
module i2c_test02(clk, slave_wait, clk_cnt, cmd, cmd_stop, cnt);

	input clk, slave_wait, clk_cnt;
	input cmd;

	output reg cmd_stop;

	reg clk_en;
	output reg [15:0] cnt;

	always @(posedge clk)
	  if (~|cnt)
	    if (~slave_wait)
	      begin
	          cnt    <= #1 clk_cnt;
	          clk_en <= #1 1'b1;
	      end
	    else
	      begin
	          cnt    <= #1 cnt;
	          clk_en <= #1 1'b0;
	      end
	  else
	    begin
                cnt    <= #1 cnt - 16'h1;
	        clk_en <= #1 1'b0;
	    end

	always @(posedge clk)
	  if (clk_en)
	    cmd_stop <= #1 cmd;

endmodule