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

Subversion Repositories uart2spi

[/] [uart2spi/] [trunk/] [verif/] [tb/] [tb_top.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  UART2SPI Test Bench Top Module                              ////
4
////                                                              ////
5
////  This file is part of the uart2spi  cores project            ////
6
////  http://www.opencores.org/cores/uart2spi/                    ////
7
////                                                              ////
8
////  Description:                                                ////
9
////  Uart2SPI testbench top level integration.                   ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
module tb_top;
44
 
45
parameter XTAL_CLK_PERIOD = 20; // 50Mhz
46
 
47
reg    reset_n;
48
reg    xtal_clk;
49
initial begin
50
  xtal_clk = 1'b0;
51
  forever #(XTAL_CLK_PERIOD/2.0) xtal_clk = ~xtal_clk;
52
end
53
 
54
//-------------------------------------
55
// Spi I/F
56
//-------------------------------------
57
wire              spi_sck         ; // clock out
58
wire              spi_so          ; // serial data out
59
wire              spi_si             ; // serial data in
60
wire [3:0]        spi_cs_n           ; // cs_n
61
 
62
top u_uart_top (
63
        .line_reset_n      (reset_n),
64
        .line_clk          (xtal_clk),
65
 
66
        // configuration control
67
        .cfg_tx_enable  (1'b1),     // Enable Transmit Path
68
        .cfg_rx_enable  (1'b1),     // Enable Received Path
69
        .cfg_stop_bit   (1'b1),     // 0 -> 1 Start , 1 -> 2 Stop Bits
70
        .cfg_pri_mod    (2'b0),     // priority mode, 0 -> nop, 1 -> Even, 2 -> Odd
71
        .cfg_baud_16x   (12'hA0),
72
 
73
 
74
       // Status information
75
        .frm_error (),
76
        .par_error (),
77
        .baud_clk_16x(uart_clk_16x),
78
 
79
 
80
       // Line Interface
81
        .rxd    (rxd),
82
        .txd    (txd),
83
 
84
        // line interface
85
        .sck    (spi_sck          ),
86
        .so     (spi_so           ),
87
        .si     (spi_si           ),
88
        .cs_n   (spi_cs_n         )
89
 
90
     );
91
 
92
 
93
uart_agent tb_uart (
94
               . test_clk          (uart_clk_16x       ),
95
               . sin               (rxd                ),
96
               . dsr_n             (                   ),
97
               . cts_n             (                   ),
98
               . dcd_n             (                   ),
99
 
100
               . sout              (txd                ),
101
               . dtr_n             (1'b0               ),
102
               . rts_n             (1'b0               ),
103
               . out1_n            (1'b0               ),
104
               . out2_n            (1'b0               )
105
       );
106
 
107
 
108
 
109
//----------------------- SPI Agents
110
 
111
m25p16 i_m25p16_0 (
112
               .c                  (spi_sck            ),
113
               .s                  (spi_cs_n[0]        ), // Include selection logic
114
               .w                  (1'b1               ), // Write protect is always disabled
115
               .hold               (1'b1               ), // Hold support not used
116
               .data_in            (spi_so             ),
117
               .data_out           (spi_si             )
118
             );
119
 
120
reg     fifo_enable      ;      // fifo mode disable
121
reg [15:0] timeout       ;// wait time limit
122
reg       parity_en       ; // parity enable
123
reg       stop_bits       ; // 0: 1 stop bit; 1: 2 stop bit;
124
reg [1:0] data_bit        ;
125
reg       flag;
126
reg [7:0] read_data;
127
reg       even_odd_parity ; // 0: odd parity; 1: even parity
128
initial begin
129
 
130
        reset_n = 1;
131
   #100 reset_n = 0;
132
   #100 reset_n = 1;
133
 
134
    tb_uart.uart_init;
135
    data_bit         = 2'b11;
136
    stop_bits         = 1'b1;
137
    parity_en         = 1'b0;
138
    even_odd_parity   = 1'b1;
139
    timeout           = 500;
140
    fifo_enable       = 0;
141
    tb_top.tb_uart.control_setup (data_bit, stop_bits, parity_en, even_odd_parity, timeout, fifo_enable);
142
 
143
   $write ("\n(%t)Received Character:\n",$time);
144
   flag = 0;
145
   while(flag == 0)
146
   begin
147
        tb_top.tb_uart.read_char(read_data,flag);
148
        //$write ("%c",read_data);
149
   end
150
 
151
 
152
//  uart_test;
153
   spi_test;
154
 
155
   #1000 $finish;
156
end
157
//initial begin
158
//$dumpfile ("spi.vcd");
159
//$dumpvars(0);
160
//end
161
 
162
//initial begin
163
//$shm_open("verilog.trn"); 
164
//$shm_probe("tb_top"); 
165
//end
166
`include "uart_tasks.v"
167
`include "spi_tasks.v"
168
`include "uart_test.v"
169
`include "spi_test.v"
170
 
171
endmodule
172
 
173
 

powered by: WebSVN 2.1.0

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