Line 1... |
Line 1... |
/*
|
/*
|
* $rtc.v
|
* rtc.v
|
*
|
*
|
* Copyright (c) 2012, BABY&HW. All rights reserved.
|
* Copyright (c) 2012, BABY&HW. All rights reserved.
|
*
|
*
|
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
Line 28... |
Line 28... |
input [37:0] time_reg_ns_in, // 37:8 ns, 7:0 ns_fraction
|
input [37:0] time_reg_ns_in, // 37:8 ns, 7:0 ns_fraction
|
input [47:0] time_reg_sec_in, // 47:0 sec
|
input [47:0] time_reg_sec_in, // 47:0 sec
|
// 2. frequency adjustment: frequency set up for drift compensation
|
// 2. frequency adjustment: frequency set up for drift compensation
|
input period_ld,
|
input period_ld,
|
input [39:0] period_in, // 39:32 ns, 31:0 ns_fraction
|
input [39:0] period_in, // 39:32 ns, 31:0 ns_fraction
|
input [37:0] time_acc_modulo, // 37: 8 ns, 7:0 ns_fraction
|
|
// 3. precise time adjustment: small time difference adjustment with a time mark
|
// 3. precise time adjustment: small time difference adjustment with a time mark
|
input adj_ld,
|
input adj_ld,
|
input [31:0] adj_ld_data,
|
input [31:0] adj_ld_data,
|
|
output reg adj_ld_done,
|
input [39:0] period_adj, // 39:32 ns, 31:0 ns_fraction
|
input [39:0] period_adj, // 39:32 ns, 31:0 ns_fraction
|
|
|
// time output: for internal with ns fraction
|
// time output: for internal with ns fraction
|
output [37:0] time_reg_ns, // 37:8 ns, 7:0 ns_fraction
|
output [37:0] time_reg_ns, // 37:8 ns, 7:0 ns_fraction
|
output [47:0] time_reg_sec, // 47:0 sec
|
output [47:0] time_reg_sec, // 47:0 sec
|
// time output: for external with ptp standard
|
// time output: for external with ptp standard
|
output [31:0] time_ptp_ns, // 31:0 ns
|
output [31:0] time_ptp_ns, // 31:0 ns
|
output [47:0] time_ptp_sec // 47:0 sec
|
output [47:0] time_ptp_sec // 47:0 sec
|
);
|
);
|
|
|
|
parameter time_acc_modulo = 38'd256000000000;
|
|
|
reg [39:0] period_fix; // 39:32 ns, 31:0 ns_fraction
|
reg [39:0] period_fix; // 39:32 ns, 31:0 ns_fraction
|
reg [31:0] adj_cnt;
|
reg [31:0] adj_cnt;
|
reg [39:0] time_adj; // 39:32 ns, 31:0 ns_fraction
|
reg [39:0] time_adj; // 39:32 ns, 31:0 ns_fraction
|
// frequency and small time difference adjustment registers
|
// frequency and small time difference adjustment registers
|
always @(posedge rst or posedge clk) begin
|
always @(posedge rst or posedge clk) begin
|
if (rst) begin
|
if (rst) begin
|
period_fix <= period_fix; //40'd0;
|
period_fix <= period_fix; //40'd0;
|
adj_cnt <= 32'hffffffff;
|
adj_cnt <= 32'hffffffff;
|
time_adj <= time_adj; //40'd0;
|
time_adj <= time_adj; //40'd0;
|
|
adj_ld_done <= 1'b0;
|
end
|
end
|
else begin
|
else begin
|
if (period_ld) // load period adjustment
|
if (period_ld) // load period adjustment
|
period_fix <= period_in;
|
period_fix <= period_in;
|
else
|
else
|
Line 69... |
Line 72... |
|
|
if (adj_cnt==0) // change period temparorily
|
if (adj_cnt==0) // change period temparorily
|
time_adj <= period_fix + period_adj;
|
time_adj <= period_fix + period_adj;
|
else
|
else
|
time_adj <= period_fix + 0;
|
time_adj <= period_fix + 0;
|
|
|
|
if (adj_cnt==32'hffffffff)
|
|
adj_ld_done <= 1'b1;
|
|
else
|
|
adj_ld_done <= 1'b0;
|
end
|
end
|
end
|
end
|
|
|
reg [39:0] time_adj_08n_32f; // 39:32 ns, 31:0 ns_fraction
|
reg [39:0] time_adj_08n_32f; // 39:32 ns, 31:0 ns_fraction
|
wire [15:0] time_adj_08n_08f; // 15: 8 ns, 7:0 ns_fraction
|
wire [15:0] time_adj_08n_08f; // 15: 8 ns, 7:0 ns_fraction
|
Line 112... |
Line 120... |
else
|
else
|
time_acc_30n_08f <= time_acc_30n_08f + {22'd0, time_adj_08n_08f};
|
time_acc_30n_08f <= time_acc_30n_08f + {22'd0, time_adj_08n_08f};
|
|
|
if (time_acc_48s_inc)
|
if (time_acc_48s_inc)
|
time_acc_48s_inc <= 1'b0;
|
time_acc_48s_inc <= 1'b0;
|
else if (time_acc_modulo == 38'd0)
|
else if (time_acc_30n_08f + {22'd0, time_adj_08n_08f} + {22'd0, time_adj_08n_08f} >= time_acc_modulo) // TODO: period_adj
|
time_acc_48s_inc <= 1'b0;
|
|
else if (time_acc_30n_08f + {22'd0, time_adj_08n_08f} + {22'd0, time_adj_08n_08f} >= time_acc_modulo)
|
|
time_acc_48s_inc <= 1'b1;
|
time_acc_48s_inc <= 1'b1;
|
else
|
else
|
time_acc_48s_inc <= 1'b0;
|
time_acc_48s_inc <= 1'b0;
|
|
|
if (time_acc_48s_inc)
|
if (time_acc_48s_inc)
|