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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
//////////////////////////////////////////////////////////////////////
//// ////
//// uart_test.v ////
//// ////
//// ////
//// This file is part of the "UART 16550 compatible" project ////
//// http://www.opencores.org/cores/uart16550/ ////
//// ////
//// Documentation related to this project: ////
//// - http://www.opencores.org/cores/uart16550/ ////
//// ////
//// Projects compatibility: ////
//// - WISHBONE ////
//// RS232 Protocol ////
//// 16550D uart (mostly supported) ////
//// ////
//// Overview (main Features): ////
//// UART core test bench ////
//// ////
//// Known problems (limits): ////
//// A very simple test bench. Creates two UARTS and sends ////
//// data on to the other. ////
//// ////
//// To Do: ////
//// More complete testing should be done!!! ////
//// ////
//// Author(s): ////
//// - gorban@opencores.org ////
//// - Jacob Gorban ////
//// ////
//// Created: 2001/05/12 ////
//// Last Updated: 2001/05/17 ////
//// (See log for the revision history) ////
//// ////
//// ////
//////////////////////////////////////////////////////////////////////
//// ////
//// Copyright (C) 2000 Jacob Gorban, gorban@opencores.org ////
//// ////
//// This source file may be used and distributed without ////
//// restriction provided that this copyright statement is not ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer. ////
//// ////
//// This source file is free software; you can redistribute it ////
//// and/or modify it under the terms of the GNU Lesser General ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any ////
//// later version. ////
//// ////
//// This source is distributed in the hope that it will be ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
//// PURPOSE. See the GNU Lesser General Public License for more ////
//// details. ////
//// ////
//// You should have received a copy of the GNU Lesser General ////
//// Public License along with this source; if not, download it ////
//// from http://www.opencores.org/lgpl.shtml ////
//// ////
//////////////////////////////////////////////////////////////////////
//
// CVS Revision History
//
// $Log: uart_test.v,v $
// Revision 1.3 2001/05/31 20:08:01 gorban
// FIFO changes and other corrections.
//
// Revision 1.2 2001/05/17 18:34:18 gorban
// First 'stable' release. Should be sythesizable now. Also added new header.
//
// Revision 1.0 2001-05-17 21:27:12+02 jacob
// Initial revision
//
//
//`define DATA_BUS_WIDTH_8
`include "timescale.v"
module uart_test ();
`include "uart_defines.v"
reg clkr;
reg wb_rst_ir;
wire [`UART_ADDR_WIDTH-1:0] wb_adr_i;
wire [31:0] wb_dat_i;
wire [31:0] wb_dat_o;
wire [3:0] wb_sel_i;
wire pad_stx_o;
reg pad_srx_ir;
integer e;
uart_top uart_snd(
clk,
// Wishbone signals
wb_rst_i, wb_adr_i, wb_dat_i, wb_dat_o, wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_sel_i,
int_o, // interrupt request
// UART signals
// serial input/output
pad_stx_o, pad_srx_i,
// modem signals
rts_o, cts_i, dtr_o, dsr_i, ri_i, dcd_i
`ifdef UART_HAS_BAUDRATE_OUTPUT
, baud1_o
`endif
);
// All the signals and regs named with a 1 are receiver fifo signals
wire [`UART_ADDR_WIDTH-1:0] wb1_adr_i;
wire [31:0] wb1_dat_i;
wire [31:0] wb1_dat_o;
wire [3:0] wb1_sel_i;
wire int1_o;
wire stx1_o;
reg srx1_ir;
uart_top uart_rcv(
clk,
// Wishbone signals
wb_rst_i, wb1_adr_i, wb1_dat_i, wb1_dat_o, wb1_we_i, wb1_stb_i, wb1_cyc_i, wb1_ack_o, wb1_sel_i,
int1_o, // interrupt request
// UART signals
// serial input/output
stx1_o, srx1_i,
// modem signals
rts1_o, cts1_i, dtr1_o, dsr1_i, ri1_i, dcd1_i
`ifdef UART_HAS_BAUDRATE_OUTPUT
, baud2_o
`endif
);
assign clk = clkr;
assign wb_rst_i = wb_rst_ir;
assign pad_srx_i = pad_srx_ir;
assign cts_i = 1; //cts_ir;
assign dsr_i = 1; //dsr_ir;
assign ri_i = 1; //ri_ir;
assign dcd_i = 1; //dcd_ir;
assign srx1_i = srx1_ir;
assign cts1_i = 1; //cts1_ir;
assign dsr1_i = 1; //dsr1_ir;
assign ri1_i = 1; //ri1_ir;
assign dcd1_i = 1; //dcd1_ir;
reg [31:0] dat_o;
/////////// CONNECT THE UARTS
always @(pad_stx_o)
begin
srx1_ir = pad_stx_o;
end
initial
begin
clkr = 0;
#50000 $finish;
end
wb_mast wbm(// Outputs
.adr (wb_adr_i),
.dout (wb_dat_i),
.cyc (wb_cyc_i),
.stb (wb_stb_i),
.sel (wb_sel_i),
.we (wb_we_i),
// Inputs
.clk (clk),
.rst (wb_rst_i),
.din (wb_dat_o),
.ack (wb_ack_o),
.err (1'b0),
.rty (1'b0));
wb_mast wbm1(// Outputs
.adr (wb1_adr_i),
.dout (wb1_dat_i),
.cyc (wb1_cyc_i),
.stb (wb1_stb_i),
.sel (wb1_sel_i),
.we (wb1_we_i),
// Inputs
.clk (clk),
.rst (wb_rst_i),
.din (wb1_dat_o),
.ack (wb1_ack_o),
.err (1'b0),
.rty (1'b0));
// The test sequence
initial
begin
#1 wb_rst_ir = 1;
#10 wb_rst_ir = 0;
//write to lcr. set bit 7
//wb_cyc_ir = 1;
wbm.wb_wr1(`UART_REG_LC, 4'b1000, {8'b10011011, 24'b0});
// set dl to divide by 3
wbm.wb_wr1(`UART_REG_DL1,4'b0001, 32'd2);
@(posedge clk);
@(posedge clk);
// restore normal registers
wbm.wb_wr1(`UART_REG_LC, 4'b1000, {8'b00011011, 24'b0}); //00011011
fork
begin
$display("%m : %t : sending : %h", $time, 8'b10000001);
wbm.wb_wr1(0, 4'b1, 32'b10000001);
@(posedge clk);
@(posedge clk);
$display("%m : %t : sending : %h", $time, 8'b01000010);
wbm.wb_wr1(0, 4'b1, 32'b01000010);
@(posedge clk);
@(posedge clk);
$display("%m : %t : sending : %h", $time, 8'b11000011);
wbm.wb_wr1(0, 4'b1, 32'b11000011);
@(posedge clk);
@(posedge clk);
$display("%m : %t : sending : %h", $time, 8'b00100100);
wbm.wb_wr1(0, 4'b1, 32'b00100100);
@(posedge clk);
@(posedge clk);
$display("%m : %t : sending : %h", $time, 8'b10100101);
wbm.wb_wr1(0, 4'b1, 32'b10100101);
@(posedge clk);
@(posedge clk);
$display("%m : %t : sending : %h", $time, 8'b01100110);
wbm.wb_wr1(0, 4'b1, 32'b01100110);
@(posedge clk);
@(posedge clk);
$display("%m : %t : sending : %h", $time, 8'b11100111);
wbm.wb_wr1(0, 4'b1, 32'b11100111);
@(posedge clk);
@(posedge clk);
$display("%m : %t : sending : %h", $time, 8'b00011000);
wbm.wb_wr1(0, 4'b1, 32'b00011000);
wait (uart_snd.regs.tstate==0 && uart_snd.regs.transmitter.tf_count==0);
// disable check;
end
// begin: check
// end
join
end
always @(int1_o)
if (int1_o)
$display("INT_O high (%g)", $time);
else
$display("INT_O low (%g)", $time);
always @(int1_o)
begin
if (int1_o) begin
wbm1.wb_rd1(2,4'b0100, dat_o);
$display("IIR : %h", dat_o);
wbm1.wb_rd1(5,4'b0010, dat_o);
$display("LSR : %h", dat_o);
wbm1.wb_rd1(0, 4'b1, dat_o);
$display("%m : %t : Data out: %h", $time, dat_o);
end
end
// receiver side
initial
begin
#11;
//write to lcr. set bit 7
//wb_cyc_ir = 1;
wbm1.wb_wr1(`UART_REG_LC, 4'b1000, {8'b10011011, 24'b0});
// set dl to divide by 3
wbm1.wb_wr1(`UART_REG_DL1, 4'b1, 32'd2);
@(posedge clk);
@(posedge clk);
// restore normal registers
wbm1.wb_wr1(`UART_REG_LC, 4'b1000, {8'b00011011, 24'b0});
wbm1.wb_wr1(`UART_REG_IE, 4'b0010, {16'b0, 8'b00001111, 8'b0});
wait(uart_rcv.regs.receiver.rf_count == 2);
e = 800;
while (e > 0)
begin
@(posedge clk)
if (uart_rcv.regs.enable) e = e - 1;
end
wbm1.wb_rd1(0, 4'b1, dat_o);
$display("%m : %t : Data out: %h", $time, dat_o);
@(posedge clk);
wbm1.wb_rd1(0, 4'b1, dat_o);
$display("%m : %t : Data out: %h", $time, dat_o);
$display("%m : Finish");
e = 800;
while (e > 0)
begin
@(posedge clk)
if (uart_rcv.regs.enable) e = e - 1;
end
e = 800;
while (e > 0)
begin
@(posedge clk)
if (uart_rcv.regs.enable) e = e - 1;
end
$finish;
end
//always @(uart_rcv.regs.rstate)
//begin
// $display($time,": Receiver state changed to: ", uart_rcv.regs.rstate);
//end
initial
begin
`ifdef DATA_BUS_WIDTH_8
$display("DATA BUS IS 8");
`else
$display("DATA BUS IS 32");
`endif
$display("%d %d", `UART_ADDR_WIDTH, `UART_DATA_WIDTH);
end
always
begin
#5 clkr = ~clk;
end
endmodule
|