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

Subversion Repositories sd_card_controller

[/] [sd_card_controller/] [trunk/] [bench/] [verilog/] [bistable_domain_cross_tb.sv] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 rozpruwacz
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// WISHBONE SD Card Controller IP Core                          ////
4
////                                                              ////
5
//// bistable_domain_cross_tb.sv                                  ////
6
////                                                              ////
7
//// This file is part of the WISHBONE SD Card                    ////
8
//// Controller IP Core project                                   ////
9 8 rozpruwacz
//// http://opencores.org/project,sd_card_controller              ////
10 3 rozpruwacz
////                                                              ////
11
//// Description                                                  ////
12
//// testbench for bistable_domain_cross module                   ////
13
////                                                              ////
14
//// Author(s):                                                   ////
15
////     - Marek Czerski, ma.czerski@gmail.com                    ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2013 Authors                                   ////
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
 
44
module bistable_domain_cross_tb();
45
 
46
parameter TCLK_A = 20; // 50 MHz -> timescale 1ns
47
parameter TCLK_B = 203; // 4.98 MHz -> timescale 1ns
48
 
49
reg rst;
50
reg clk_a;
51
reg [1:0] in;
52
reg clk_b;
53
wire [1:0] out;
54
 
55
bistable_domain_cross #(2) bistable_domain_cross_dut(
56
    .rst(rst),
57
    .clk_a(clk_a),
58
    .in(in),
59
    .clk_b(clk_b),
60
    .out(out)
61
);
62
 
63
// Generating clk_a clock
64
always
65
begin
66
    clk_a=0;
67
    forever #(TCLK_A/2) clk_a = ~clk_a;
68
end
69
 
70
// Generating clk_b clock
71
always
72
begin
73
    clk_b=0;
74
    forever #(TCLK_B/2) clk_b = ~clk_b;
75
end
76
 
77
initial
78
begin
79
    rst = 1;
80
    in = 0;
81
 
82
    #(3.2*TCLK_B);
83
    rst = 0;
84
 
85
    $display("bistable_domain_cross_tb start ...");
86
 
87
    #(3*TCLK_B);
88
    wait(clk_a == 0);
89
    wait(clk_a == 1);
90
    in = 2'b11;
91
    #(1.5*TCLK_A);
92
    wait(clk_b == 0);
93
    wait(clk_b == 1);
94
    #(1.5*TCLK_B);
95
 
96
    assert(out == 2'b11);
97
 
98
    #TCLK_B;
99
    assert(out == 2'b11);
100
 
101
    wait(clk_a == 0);
102
    wait(clk_a == 1);
103
    in = 2'b00;
104
    #(1.5*TCLK_A);
105
 
106
    wait(clk_b == 0);
107
    wait(clk_b == 1);
108
    #(1.5*TCLK_B);
109
 
110
    assert(out == 2'b00);
111
 
112
    #(10*TCLK_B) $display("bistable_domain_cross_tb finish ...");
113
    $finish;
114
 
115
end
116
 
117
endmodule

powered by: WebSVN 2.1.0

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