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

Subversion Repositories openarty

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

Go to most recent revision | 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
        always @(posedge i_clk)
70
                if ((i_wb_cyc_stb)&&(i_wb_we))
71
                begin
72
                        case(i_wb_addr)
73
                        3'b000: r_maxcount    <= i_wb_data;
74
                        3'b001: r_jump     <= i_wb_data;
75
                        // 2'b11: r_def_step <= i_wb_data;
76
                        default: begin end
77
                        // r_defstep <= i_wb_data;
78
                        endcase
79
                end else
80
                        r_jump <= 32'h00;
81
 
82
        reg     [31:0]   r_err, r_lcl;
83
        reg     [63:0]   r_count, r_step;
84
 
85
        initial r_lcl = 32'h000;
86
        initial r_halt = 1'b0;
87
        always @(posedge i_clk)
88
                case (i_wb_addr)
89
                        3'b000: o_wb_data <= r_maxcount;
90
                        3'b001: begin o_wb_data <= r_lcl; r_halt <= 1'b1; end // { 31'h00, r_halt };
91
                        3'b010: begin o_wb_data <= i_err[63:32]; r_halt <= 1'b1; end
92
                        3'b011: o_wb_data <= r_err[31:0];
93
                        3'b100: o_wb_data <= r_count[63:32];
94
                        3'b101: o_wb_data <= r_count[31:0];
95
                        3'b110: o_wb_data <= r_step[63:32];
96
                        3'b111: begin o_wb_data <= r_step[31:0]; r_halt <= 1'b0; end
97
                        default: o_wb_data <= 0;
98
                endcase
99
 
100
        always @(posedge i_clk)
101
                o_wb_ack <= i_wb_cyc_stb;
102
        assign  o_wb_stall = 1'b0;
103
 
104
 
105
        //
106
        //
107
        // Generate a PPS signal
108
        //
109
        //
110
        reg     [31:0]   r_ctr;
111
        always @(posedge i_clk)
112
                if (r_ctr >= r_maxcount-1)
113
                        r_ctr <= r_ctr+1-r_maxcount+r_jump;
114
                else
115
                        r_ctr <= r_ctr+1+r_jump;
116
        always @(posedge i_clk)
117
                if (r_ctr >= r_maxcount-1)
118
                        o_pps <= 1'b1;
119
                else
120
                        o_pps <= 1'b0;
121
 
122
        reg     [31:0]   lcl_counter;
123
        always @(posedge i_clk)
124
                lcl_counter <= lcl_counter + 32'h001;
125
 
126
        always @(posedge i_clk)
127
                if ((~r_halt)&&(i_lcl_pps))
128
                begin
129
                        r_err   <= i_err[31:0];
130
                        r_count <= i_count;
131
                        r_step  <= i_step;
132
                        r_lcl   <= lcl_counter;
133
                end
134
 
135
 
136
endmodule
137
 

powered by: WebSVN 2.1.0

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