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

Subversion Repositories uart2bus

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

powered by: WebSVN 2.1.0

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