aboutsummaryrefslogtreecommitdiff
path: root/rtl/src/testbench/tb_demo_adder.v
blob: 5abbf06c902d36443203c43239b66e6ae7d321f9 (plain) (blame)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
`timescale 1ns / 1ps

module tb_demo_adder;

		//
		// Inputs
		//
	reg	gclk;
	wire	gclk_p	=  gclk;
	wire	gclk_n	= ~gclk;
	reg	reset_mcu_b;

		//
		// Outputs
		//
	wire	led;

		//
		// EIM
		//
	reg				eim_cs_n;
	reg				eim_bclk;
	reg				eim_lba_n;
	wire	[15: 0]	eim_da;
	reg	[15: 0]	eim_da_out;
	reg				eim_da_drive;
	reg				eim_oe_n;
	reg				eim_wr_n;
	wire				eim_wait_n;
	
	assign eim_da = (eim_da_drive == 1'b1) ? eim_da_out : {16{1'bZ}};

		//
		// UUT
		//
	novena_baseline_top uut
	(
		.gclk_p_pin			(gclk_p), 
		.gclk_n_pin			(gclk_n), 
		
		.eim_bclk			(eim_bclk),
		.eim_cs0_n			(eim_cs_n),
		.eim_da				(eim_da),
		.eim_lba_n			(eim_lba_n),
		.eim_wr_n			(eim_wr_n),
		.eim_oe_n			(eim_oe_n),
		.eim_wait_n			(eim_wait_n),
		
		.reset_mcu_b_pin	(reset_mcu_b),
		
		.led_pin				(led_pin),
		.apoptosis_pin		(apoptosis_pin)
	);

		//
		// CLK2 (50 MHz)
		//
	always #10 gclk = ~gclk;		
		
		//
		// Initialize EIM
		//
	initial begin
		eim_cs_n			= 1'b1;
		eim_bclk			= 1'b0;
		eim_lba_n		= 1'b1;
		eim_da_out		= {16{1'bX}};
		eim_da_drive	= 1'b1;
		eim_oe_n			= 1'b1;
		eim_wr_n			= 1'b1;
	end
		
		//
		// Test Logic
		//
	reg	[31: 0]	eim_rd = {32{1'bX}};
	
	initial begin
		gclk				= 1'b0;
		reset_mcu_b		= 1'b1;
		//
		#2000;
		//
		eim_write({12'h321, 2'd0, 2'b00}, 32'hAA_55_A5_A5);	// write X
		#100;
		eim_write({12'h321, 2'd1, 2'b00}, 32'h11_22_12_12);	// write Y
		#100;
		eim_read( {12'h321, 2'd3, 2'b00}, eim_rd);				// read {STS, CTL}	<-- should be 0x0000_0000
		#100;
		eim_rd = eim_rd + 1'b1;
		eim_write({12'h321, 2'd3, 2'b00}, eim_rd);				// write {STS, CTL}	<-- STS is ignored by adder
		#100;
		eim_read( {12'h321, 2'd3, 2'b00}, eim_rd);				// read {STS, CTL}	<-- should be 0x0001_0001
		#100;
		eim_read( {12'h321, 2'd2, 2'b00}, eim_rd);				// read Z				<-- should be 0xBB77B7B7
	end	
		
		//
		// Write Access
		//
	integer wr;
	task eim_write;
		input [15: 0] addr;
		input [31: 0] data;
		begin
			#15	eim_cs_n		= 1'b0;
					eim_lba_n	= 1'b0;
					eim_da_out	= addr;
					eim_wr_n		= 1'b0;
			#15	eim_bclk		= 1'b1;
			#15	eim_bclk		= 1'b0;
					eim_lba_n	= 1'b1;
					eim_da_out	= data[15:0];
			#15	eim_bclk		= 1'b1;
			#15	eim_bclk		= 1'b0;
					eim_da_out	= data[31:16];
			#15	eim_bclk		= 1'b1;
			#15	eim_bclk		= 1'b0;
					eim_da_out	= {16{1'bX}};
			while (eim_wait_n == 1'b0) begin
			#15	eim_bclk		= 1'b1;
			#15	eim_bclk		= 1'b0;
			end					
			#15	eim_cs_n		= 1'b1;
					eim_wr_n		= 1'b1;
			#30;
		end
	endtask;
	
	
		//
		// Read Access
		//
	task eim_read;
		input  [15: 0] addr;
		output [31: 0] data;
		begin
			#15	eim_cs_n			= 1'b0;
					eim_lba_n		= 1'b0;
					eim_da_out		= addr;
					
			#15	eim_bclk			= 1'b1;
			
			#15	eim_bclk			= 1'b0;
					eim_lba_n		= 1'b1;
					eim_oe_n			= 1'b0;
					eim_da_drive	= 1'b0;
			#15;
			while (eim_wait_n == 1'b0) begin
					eim_bclk		= 1'b1;
			#15	eim_bclk		= 1'b0;
			#15;
			end
					eim_bclk			= 1'b1;
			#15	eim_bclk			= 1'b0;
			#15	eim_bclk			= 1'b1;
					data[15: 0]		= eim_da;
			#15	eim_bclk			= 1'b0;
			#15	eim_bclk			= 1'b1;
					data[31:16]		= eim_da;
			#15	eim_bclk			= 1'b0;
					eim_da_out		= {16{1'bX}};

			#15	eim_cs_n			= 1'b1;
					eim_oe_n			= 1'b1;
					eim_da_drive	= 1'b1;
			#30;
		end
	endtask;	

      
endmodule