OpenCores
URL https://opencores.org/ocsvn/uart2bus/uart2bus/trunk

Subversion Repositories uart2bus

[/] [uart2bus/] [trunk/] [verilog/] [bench/] [tb_uart2bus_top.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 motilito
//---------------------------------------------------------------------------------------
2
// uart test bench   
3
//
4
//---------------------------------------------------------------------------------------
5
 
6
`include "timescale.v"
7
 
8
module test;
9
//---------------------------------------------------------------------------------------
10
// include uart tasks 
11
`include "uart_tasks.v"
12
 
13
// internal signal  
14
reg clock;              // global clock 
15
reg reset;              // global reset 
16
reg [6:0] counter;
17
 
18
//---------------------------------------------------------------------------------------
19
// test bench implementation 
20
// global signals generation  
21
initial
22
begin
23
        counter = 0;
24
        clock = 0;
25
        reset = 1;
26
        #40 reset = 0;
27
end
28
 
29
// clock generator - 40MHz clock 
30
always
31
begin
32
        #12 clock = 0;
33
        #13 clock = 1;
34
end
35
 
36
// test bench dump variables 
37
initial
38
begin
39
        $dumpfile("test.vcd");
40
        //$dumpall;
41
        $dumpvars(0, test);
42
end
43
 
44
//------------------------------------------------------------------
45
// test bench transmitter and receiver 
46
// uart transmit - test bench control 
47
 
48
initial
49
begin
50
        // defualt value of serial output 
51
        serial_out = 1;
52
 
53
        // transmit a write command to internal register file 
54
        // command string: "w 4cd9 1a" + CR 
55
        send_serial (8'h77, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
56
        #100;
57
        send_serial (8'h20, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
58
        #100;
59
        send_serial (8'h34, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
60
        #100;
61
        send_serial (8'h63, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
62
        #100;
63
        send_serial (8'h64, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
64
        #100;
65
        send_serial (8'h39, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
66
        #100;
67
        send_serial (8'h20, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
68
        #100;
69
        send_serial (8'h31, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
70
        #100;
71
        send_serial (8'h61, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
72
        #100;
73
        send_serial (8'h0d, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
74
        #100;
75
        // transmit a read command from register file 
76
        // command string: "r 1a" + CR 
77
        send_serial (8'h72, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
78
        #100;
79
        send_serial (8'h20, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
80
        #100;
81
        send_serial (8'h31, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
82
        #100;
83
        send_serial (8'h61, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
84
        #100;
85
        send_serial (8'h0d, `BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8, 0);
86
        #100;
87
 
88
        // delay and finish 
89
        #900000;
90
        $finish;
91
end
92
 
93
// uart receive 
94
initial
95
begin
96
        // default value for serial receiver and serial input 
97
        serial_in = 1;
98
        get_serial_data = 0;             // data received from get_serial task 
99
        get_serial_status = 0;           // status of get_serial task  
100
end
101
 
102
// serial sniffer loop 
103
always
104
begin
105
        // call serial sniffer 
106
        get_serial(`BAUD_115200, `PARITY_EVEN, `PARITY_OFF, `NSTOPS_1, `NBITS_8);
107
 
108
        // check serial receiver status 
109
        // byte received OK 
110
        if (get_serial_status & `RECEIVE_RESULT_OK)
111
        begin
112
                // check if not a control character (above and including space ascii code)
113
                if (get_serial_data >= 8'h20)
114
                        $display("received byte 0x%h (\"%c\") at %t ns", get_serial_data, get_serial_data, $time);
115
                else
116
                        $display("received byte 0x%h (\"%c\") at %t ns", get_serial_data, 8'hb0, $time);
117
        end
118
 
119
        // false start error 
120
        if (get_serial_status & `RECEIVE_RESULT_FALSESTART)
121
                $display("Error (get_char): false start condition at %t", $realtime);
122
 
123
        // bad parity error             
124
        if (get_serial_status & `RECEIVE_RESULT_BADPARITY)
125
                $display("Error (get_char): bad parity condition at %t", $realtime);
126
 
127
        // bad stop bits sequence       
128
        if (get_serial_status & `RECEIVE_RESULT_BADSTOP)
129
                $display("Error (get_char): bad stop bits sequence at %t", $realtime);
130
end
131
 
132
//------------------------------------------------------------------
133
// device under test 
134
// DUT interface 
135
wire    [7:0]    int_address;    // address bus to register file 
136
wire    [7:0]    int_wr_data;    // write data to register file 
137
wire                    int_write;              // write control to register file 
138
wire                    int_read;               // read control to register file 
139
wire    [7:0]    int_rd_data;    // data read from register file 
140 12 motilito
wire                    int_req;                // bus access request signal 
141
wire                    int_gnt;                // bus access grant signal 
142 2 motilito
wire                    ser_in;                 // DUT serial input 
143
wire                    ser_out;                // DUT serial output 
144
 
145
// DUT instance 
146
uart2bus_top uart2bus1
147
(
148
        .clock(clock), .reset(reset),
149
        .ser_in(ser_in), .ser_out(ser_out),
150
        .int_address(int_address), .int_wr_data(int_wr_data), .int_write(int_write),
151 12 motilito
        .int_rd_data(int_rd_data), .int_read(int_read),
152
        .int_req(int_req), .int_gnt(int_gnt)
153 2 motilito
);
154 12 motilito
// bus grant is always active 
155
assign int_gnt = 1'b1;
156 2 motilito
 
157
// serial interface to test bench 
158
assign ser_in = serial_out;
159
always @ (posedge clock) serial_in = ser_out;
160
 
161
// register file model 
162
reg_file_model reg_file1
163
(
164
        .clock(clock), .reset(reset),
165
        .int_address(int_address), .int_wr_data(int_wr_data), .int_write(int_write),
166
        .int_rd_data(int_rd_data), .int_read(int_read)
167
);
168
 
169
endmodule
170
//---------------------------------------------------------------------------------------
171
//                                              Th.. Th.. Th.. Thats all folks !!!
172
//---------------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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