| 1 |
34 |
edn_walter |
/*
|
| 2 |
|
|
* $rtc_timer_tb.v
|
| 3 |
|
|
*
|
| 4 |
37 |
edn_walter |
* Copyright (c) 2012, BABY&HW. All rights reserved.
|
| 5 |
34 |
edn_walter |
*
|
| 6 |
|
|
* This library is free software; you can redistribute it and/or
|
| 7 |
|
|
* modify it under the terms of the GNU Lesser General Public
|
| 8 |
|
|
* License as published by the Free Software Foundation; either
|
| 9 |
|
|
* version 2.1 of the License, or (at your option) any later version.
|
| 10 |
|
|
*
|
| 11 |
|
|
* This library is distributed in the hope that it will be useful,
|
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
|
|
* Lesser General Public License for more details.
|
| 15 |
|
|
*
|
| 16 |
|
|
* You should have received a copy of the GNU Lesser General Public
|
| 17 |
|
|
* License along with this library; if not, write to the Free Software
|
| 18 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
| 19 |
|
|
* MA 02110-1301 USA
|
| 20 |
|
|
*/
|
| 21 |
|
|
|
| 22 |
3 |
ash_riple |
`timescale 1ns/1ns
|
| 23 |
|
|
|
| 24 |
|
|
module rtc_timer_tb ;
|
| 25 |
|
|
|
| 26 |
|
|
reg rst;
|
| 27 |
|
|
reg clk;
|
| 28 |
|
|
wire [37:0] time_reg_ns;
|
| 29 |
|
|
wire [47:0] time_reg_sec;
|
| 30 |
|
|
reg period_ld;
|
| 31 |
|
|
reg [39:0] period_in;
|
| 32 |
|
|
reg [37:0] time_acc_modulo;
|
| 33 |
|
|
reg adj_ld;
|
| 34 |
|
|
reg [31:0] adj_ld_data;
|
| 35 |
|
|
reg [39:0] period_adj;
|
| 36 |
|
|
reg time_ld;
|
| 37 |
|
|
reg [37:0] time_reg_ns_in;
|
| 38 |
|
|
reg [47:0] time_reg_sec_in;
|
| 39 |
15 |
edn_walter |
rtc
|
| 40 |
3 |
ash_riple |
DUT (
|
| 41 |
|
|
.rst (rst ) ,
|
| 42 |
|
|
.clk (clk ) ,
|
| 43 |
|
|
.time_ld (time_ld ) ,
|
| 44 |
|
|
.time_reg_ns_in (time_reg_ns_in ) ,
|
| 45 |
|
|
.time_reg_sec_in (time_reg_sec_in ) ,
|
| 46 |
|
|
.time_reg_ns (time_reg_ns ) ,
|
| 47 |
|
|
.time_reg_sec (time_reg_sec ) ,
|
| 48 |
|
|
.period_ld (period_ld ) ,
|
| 49 |
|
|
.period_in (period_in ) ,
|
| 50 |
|
|
.time_acc_modulo (time_acc_modulo ) ,
|
| 51 |
|
|
.adj_ld (adj_ld ) ,
|
| 52 |
|
|
.period_adj (period_adj ) ,
|
| 53 |
|
|
.adj_ld_data (adj_ld_data ) );
|
| 54 |
|
|
|
| 55 |
|
|
|
| 56 |
|
|
initial begin
|
| 57 |
|
|
clk = 1'b0;
|
| 58 |
|
|
forever #4 clk = !clk;
|
| 59 |
|
|
end
|
| 60 |
|
|
initial begin
|
| 61 |
|
|
rst = 1'b0;
|
| 62 |
|
|
@(posedge clk);
|
| 63 |
|
|
rst = 1'b1;
|
| 64 |
|
|
@(posedge clk);
|
| 65 |
|
|
rst = 1'b0;
|
| 66 |
|
|
end
|
| 67 |
|
|
initial begin
|
| 68 |
|
|
#2000 $stop;
|
| 69 |
|
|
end
|
| 70 |
|
|
|
| 71 |
|
|
// main process
|
| 72 |
|
|
integer i;
|
| 73 |
|
|
initial begin
|
| 74 |
|
|
|
| 75 |
|
|
/////////////////////////
|
| 76 |
|
|
// reset default values
|
| 77 |
|
|
/////////////////////////
|
| 78 |
|
|
|
| 79 |
|
|
@(posedge rst);
|
| 80 |
|
|
// frequency load
|
| 81 |
|
|
period_ld = 1'b0;
|
| 82 |
|
|
period_in[39:32] = 8'h00; // ns
|
| 83 |
|
|
period_in[31: 0] = 32'h00000000; // ns fraction
|
| 84 |
|
|
time_acc_modulo = 38'd256_000000000;
|
| 85 |
|
|
// time load
|
| 86 |
|
|
time_ld = 1'b0;
|
| 87 |
|
|
time_reg_ns_in[37:8] = 30'd0; // ns
|
| 88 |
|
|
time_reg_ns_in[ 7:0] = 8'h00; // ns fraction
|
| 89 |
|
|
time_reg_sec_in = 48'd0;
|
| 90 |
|
|
// time fine tune load
|
| 91 |
|
|
adj_ld = 1'b0;
|
| 92 |
|
|
adj_ld_data = 32'd10;
|
| 93 |
|
|
period_adj = 40'h00_00000000;
|
| 94 |
|
|
@(negedge rst);
|
| 95 |
|
|
|
| 96 |
|
|
////////////////////
|
| 97 |
|
|
// time adjustment
|
| 98 |
|
|
////////////////////
|
| 99 |
|
|
|
| 100 |
|
|
for (i=0; i<20; i=i+1) @(posedge clk);
|
| 101 |
|
|
// load default period
|
| 102 |
|
|
period_ld = 1'b1;
|
| 103 |
|
|
period_in[39:32] = 8'h08; // ns
|
| 104 |
|
|
period_in[31: 0] = 32'h00000000; // ns fraction
|
| 105 |
|
|
@(posedge clk);
|
| 106 |
|
|
period_ld = 1'b0;
|
| 107 |
|
|
|
| 108 |
|
|
for (i=0; i<20; i=i+1) @(posedge clk);
|
| 109 |
|
|
// fine tune time difference by 0
|
| 110 |
|
|
adj_ld = 1'b1;
|
| 111 |
|
|
adj_ld_data = 32'd10;
|
| 112 |
|
|
period_adj[39:32] = 8'h00; // ns // can be negative?
|
| 113 |
|
|
period_adj[31: 0] = 32'h00000000; // ns fraction
|
| 114 |
|
|
@(posedge clk);
|
| 115 |
|
|
adj_ld = 1'b0;
|
| 116 |
|
|
|
| 117 |
|
|
for (i=0; i<20; i=i+1) @(posedge clk);
|
| 118 |
|
|
// load time ToD values
|
| 119 |
|
|
time_ld = 1'b1;
|
| 120 |
|
|
time_reg_ns_in[37:8] = 30'd999999990; // ns
|
| 121 |
|
|
time_reg_ns_in[ 7:0] = 8'h00; // ns fraction
|
| 122 |
|
|
time_reg_sec_in = 48'd10;
|
| 123 |
|
|
@(posedge clk);
|
| 124 |
|
|
time_ld = 1'b0;
|
| 125 |
|
|
|
| 126 |
|
|
for (i=0; i<20; i=i+1) @(posedge clk);
|
| 127 |
|
|
// fine tune frequency difference
|
| 128 |
|
|
period_ld = 1'b1;
|
| 129 |
|
|
period_in[39:32] = 8'h08; // ns
|
| 130 |
|
|
period_in[31: 0] = 32'h10200000; // ns fraction
|
| 131 |
|
|
@(posedge clk);
|
| 132 |
|
|
period_ld = 1'b0;
|
| 133 |
|
|
|
| 134 |
|
|
for (i=0; i<20; i=i+1) @(posedge clk);
|
| 135 |
|
|
// fine tune time difference
|
| 136 |
|
|
adj_ld = 1'b1;
|
| 137 |
|
|
adj_ld_data = 32'd10;
|
| 138 |
|
|
period_adj[39:32] = 8'h02; // ns // can be negative?
|
| 139 |
|
|
period_adj[31: 0] = 32'h20800000; // ns fraction
|
| 140 |
|
|
@(posedge clk);
|
| 141 |
|
|
adj_ld = 1'b0;
|
| 142 |
|
|
end
|
| 143 |
|
|
|
| 144 |
|
|
// sec+ns watchpoint
|
| 145 |
|
|
wire [29:0] time_acc_modulo_ns_ = time_acc_modulo[37:8];
|
| 146 |
|
|
wire [47:0] time_reg_sec_in_ = time_reg_sec_in[47:0];
|
| 147 |
|
|
wire [29:0] time_reg_ns_in_ = time_reg_ns_in[37:8];
|
| 148 |
|
|
wire [47:0] time_reg_sec_ = time_reg_sec[47:0];
|
| 149 |
|
|
wire [29:0] time_reg_ns_ = time_reg_ns[37:8];
|
| 150 |
|
|
wire [ 7:0] period_ns_ = period_in[39:32];
|
| 151 |
|
|
wire [ 7:0] period_adj_ns_ = period_adj[39:32];
|
| 152 |
19 |
edn_walter |
wire time_reg_sec_inc_ = DUT.time_acc_48s_inc;
|
| 153 |
3 |
ash_riple |
// ns fraction watchpoint
|
| 154 |
|
|
wire [ 7:0] time_acc_modulo_ns_f = time_acc_modulo[7:0];
|
| 155 |
|
|
wire [ 7:0] time_reg_ns_in_f = time_reg_ns_in[7:0];
|
| 156 |
|
|
wire [ 7:0] time_reg_ns_f = time_reg_ns[7:0];
|
| 157 |
|
|
wire [31:0] period_ns_f = period_in[31:0];
|
| 158 |
|
|
wire [31:0] period_adj_ns_f = period_adj[31:0];
|
| 159 |
|
|
|
| 160 |
|
|
// ns time incremental watchpoint
|
| 161 |
|
|
reg [47:0] time_reg_sec__d1;
|
| 162 |
|
|
reg [29:0] time_reg_ns__d1;
|
| 163 |
|
|
always @(posedge clk) begin
|
| 164 |
|
|
time_reg_sec__d1 <= time_reg_sec_;
|
| 165 |
|
|
time_reg_ns__d1 <= time_reg_ns_;
|
| 166 |
|
|
end
|
| 167 |
|
|
wire [29:0] time_reg_ns__delta = (time_reg_sec__d1!=time_reg_sec_)?
|
| 168 |
|
|
(time_acc_modulo_ns_-(time_reg_ns__d1-time_reg_ns_)):
|
| 169 |
|
|
(time_reg_ns_-time_reg_ns__d1);
|
| 170 |
|
|
|
| 171 |
|
|
// Delta-Sigma circuit watchpoint
|
| 172 |
|
|
wire [23:0] time_adj_08n_32f_24f = rtc_timer_tb.DUT.time_adj_08n_32f[23:0];
|
| 173 |
|
|
|
| 174 |
|
|
endmodule
|
| 175 |
|
|
|