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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [gpsclock_tb.v] - Blame information for rev 34

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    gpsclock_tb.v
4
//              
5
// Project:     A GPS Schooled Clock Core
6
//
7
// Purpose:     Provide a test bench, internal to an FPGA, whereby the GPS
8
//              clock module can be tested.
9
//
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
module  gpsclock_tb(i_clk, i_lcl_pps, o_pps,
39
                i_wb_cyc_stb, i_wb_we, i_wb_addr, i_wb_data,
40
                        o_wb_ack, o_wb_stall, o_wb_data,
41
                i_err, i_count, i_step);
42
        parameter       DW=32, RW=64;
43
        input                           i_clk, i_lcl_pps;
44
        output  reg                     o_pps;  // To our local circuitry
45
        // Wishbone Configuration interface
46
        input                           i_wb_cyc_stb, i_wb_we;
47
        input           [2:0]            i_wb_addr;
48
        input           [(DW-1):0]       i_wb_data;
49
        output  reg                     o_wb_ack;
50
        output  wire                    o_wb_stall;
51
        output  reg     [(DW-1):0]       o_wb_data;
52
        // Status and timing outputs
53
        input   [(RW-1):0]       i_err, // Fraction of a second err
54
                                i_count, // Fraction of a second
55
                                i_step; // 2^RW / clock speed (in Hz)
56
 
57
 
58
        reg     [31:0]   r_jump, r_maxcount;
59
        reg             r_halt;
60
 
61
 
62
        //
63
        //
64
        //
65
        // Wishbone access ...
66
        //
67
        //
68
        //
69 34 dgisselq
        initial r_jump = 0;
70
        initial r_maxcount = 32'd81200000;
71 3 dgisselq
        always @(posedge i_clk)
72
                if ((i_wb_cyc_stb)&&(i_wb_we))
73
                begin
74
                        case(i_wb_addr)
75 25 dgisselq
                        3'b000: r_maxcount <= i_wb_data;
76 3 dgisselq
                        3'b001: r_jump     <= i_wb_data;
77
                        // 2'b11: r_def_step <= i_wb_data;
78
                        default: begin end
79
                        // r_defstep <= i_wb_data;
80
                        endcase
81
                end else
82
                        r_jump <= 32'h00;
83
 
84
        reg     [31:0]   r_err, r_lcl;
85
        reg     [63:0]   r_count, r_step;
86
 
87
        initial r_lcl = 32'h000;
88
        initial r_halt = 1'b0;
89
        always @(posedge i_clk)
90
                case (i_wb_addr)
91
                        3'b000: o_wb_data <= r_maxcount;
92
                        3'b001: begin o_wb_data <= r_lcl; r_halt <= 1'b1; end // { 31'h00, r_halt };
93
                        3'b010: begin o_wb_data <= i_err[63:32]; r_halt <= 1'b1; end
94
                        3'b011: o_wb_data <= r_err[31:0];
95
                        3'b100: o_wb_data <= r_count[63:32];
96
                        3'b101: o_wb_data <= r_count[31:0];
97
                        3'b110: o_wb_data <= r_step[63:32];
98
                        3'b111: begin o_wb_data <= r_step[31:0]; r_halt <= 1'b0; end
99 25 dgisselq
                        // default: o_wb_data <= 0;
100 3 dgisselq
                endcase
101
 
102
        always @(posedge i_clk)
103
                o_wb_ack <= i_wb_cyc_stb;
104
        assign  o_wb_stall = 1'b0;
105
 
106
 
107
        //
108
        //
109
        // Generate a PPS signal
110
        //
111
        //
112
        reg     [31:0]   r_ctr;
113
        always @(posedge i_clk)
114
                if (r_ctr >= r_maxcount-1)
115
                        r_ctr <= r_ctr+1-r_maxcount+r_jump;
116
                else
117
                        r_ctr <= r_ctr+1+r_jump;
118
        always @(posedge i_clk)
119
                if (r_ctr >= r_maxcount-1)
120
                        o_pps <= 1'b1;
121
                else
122
                        o_pps <= 1'b0;
123
 
124
        reg     [31:0]   lcl_counter;
125
        always @(posedge i_clk)
126
                lcl_counter <= lcl_counter + 32'h001;
127
 
128
        always @(posedge i_clk)
129
                if ((~r_halt)&&(i_lcl_pps))
130
                begin
131
                        r_err   <= i_err[31:0];
132
                        r_count <= i_count;
133
                        r_step  <= i_step;
134
                        r_lcl   <= lcl_counter;
135
                end
136
 
137
 
138
endmodule
139
 

powered by: WebSVN 2.1.0

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