1 |
15 |
edn_walter |
`timescale 1ns/1ns
|
2 |
|
|
|
3 |
17 |
edn_walter |
module rgs (
|
4 |
16 |
edn_walter |
// generic bus interface
|
5 |
|
|
input rst,clk,
|
6 |
|
|
input wr_in,rd_in,
|
7 |
17 |
edn_walter |
input [ 5:0] addr_in,
|
8 |
16 |
edn_walter |
input [31:0] data_in,
|
9 |
|
|
output [31:0] data_out,
|
10 |
|
|
// rtc interface
|
11 |
17 |
edn_walter |
input rtc_clk_in,
|
12 |
|
|
output rtc_rst_out,
|
13 |
|
|
output time_ld_out,
|
14 |
16 |
edn_walter |
output [37:0] time_reg_ns_out,
|
15 |
|
|
output [47:0] time_reg_sec_out,
|
16 |
17 |
edn_walter |
output period_ld_out,
|
17 |
16 |
edn_walter |
output [39:0] period_out,
|
18 |
|
|
output [37:0] time_acc_modulo_out,
|
19 |
17 |
edn_walter |
output adj_ld_out,
|
20 |
16 |
edn_walter |
output [31:0] adj_ld_data_out,
|
21 |
17 |
edn_walter |
output [39:0] period_adj_out,
|
22 |
16 |
edn_walter |
input [37:0] time_reg_ns_in,
|
23 |
|
|
input [47:0] time_reg_sec_in,
|
24 |
|
|
// tsu interface
|
25 |
17 |
edn_walter |
output q_rst_out,
|
26 |
|
|
output q_rd_clk_out,
|
27 |
|
|
output q_rd_en_out,
|
28 |
|
|
input [ 7:0] q_stat_in,
|
29 |
|
|
input [55:0] q_data_in
|
30 |
15 |
edn_walter |
);
|
31 |
|
|
|
32 |
17 |
edn_walter |
parameter const_00 = 8'h00;
|
33 |
|
|
parameter const_04 = 8'h04;
|
34 |
|
|
parameter const_08 = 8'h08;
|
35 |
|
|
parameter const_0C = 8'h0C;
|
36 |
|
|
parameter const_10 = 8'h10;
|
37 |
|
|
parameter const_14 = 8'h14;
|
38 |
|
|
parameter const_18 = 8'h18;
|
39 |
|
|
parameter const_1C = 8'h1C;
|
40 |
|
|
parameter const_20 = 8'h20;
|
41 |
|
|
parameter const_24 = 8'h24;
|
42 |
|
|
parameter const_28 = 8'h28;
|
43 |
|
|
parameter const_2C = 8'h2C;
|
44 |
|
|
parameter const_30 = 8'h30;
|
45 |
|
|
parameter const_34 = 8'h34;
|
46 |
|
|
parameter const_38 = 8'h38;
|
47 |
|
|
parameter const_3C = 8'h3C;
|
48 |
|
|
parameter const_40 = 8'h40;
|
49 |
|
|
parameter const_44 = 8'h44;
|
50 |
|
|
parameter const_48 = 8'h48;
|
51 |
|
|
parameter const_4C = 8'h4C;
|
52 |
|
|
|
53 |
|
|
wire cs_00 = (addr_in[5:0]==const_00[5:0])? 1'b1: 1'b0;
|
54 |
|
|
wire cs_04 = (addr_in[5:0]==const_04[5:0])? 1'b1: 1'b0;
|
55 |
|
|
wire cs_08 = (addr_in[5:0]==const_08[5:0])? 1'b1: 1'b0;
|
56 |
|
|
wire cs_0c = (addr_in[5:0]==const_0c[5:0])? 1'b1: 1'b0;
|
57 |
|
|
wire cs_10 = (addr_in[5:0]==const_10[5:0])? 1'b1: 1'b0;
|
58 |
|
|
wire cs_14 = (addr_in[5:0]==const_14[5:0])? 1'b1: 1'b0;
|
59 |
|
|
wire cs_18 = (addr_in[5:0]==const_18[5:0])? 1'b1: 1'b0;
|
60 |
|
|
wire cs_1c = (addr_in[5:0]==const_1c[5:0])? 1'b1: 1'b0;
|
61 |
|
|
wire cs_20 = (addr_in[5:0]==const_20[5:0])? 1'b1: 1'b0;
|
62 |
|
|
wire cs_24 = (addr_in[5:0]==const_24[5:0])? 1'b1: 1'b0;
|
63 |
|
|
wire cs_28 = (addr_in[5:0]==const_28[5:0])? 1'b1: 1'b0;
|
64 |
|
|
wire cs_2c = (addr_in[5:0]==const_2c[5:0])? 1'b1: 1'b0;
|
65 |
|
|
wire cs_30 = (addr_in[5:0]==const_30[5:0])? 1'b1: 1'b0;
|
66 |
|
|
wire cs_34 = (addr_in[5:0]==const_34[5:0])? 1'b1: 1'b0;
|
67 |
|
|
wire cs_38 = (addr_in[5:0]==const_38[5:0])? 1'b1: 1'b0;
|
68 |
|
|
wire cs_3c = (addr_in[5:0]==const_3c[5:0])? 1'b1: 1'b0;
|
69 |
|
|
wire cs_40 = (addr_in[5:0]==const_40[5:0])? 1'b1: 1'b0;
|
70 |
|
|
wire cs_44 = (addr_in[5:0]==const_44[5:0])? 1'b1: 1'b0;
|
71 |
|
|
wire cs_48 = (addr_in[5:0]==const_48[5:0])? 1'b1: 1'b0;
|
72 |
|
|
wire cs_4c = (addr_in[5:0]==const_4c[5:0])? 1'b1: 1'b0;
|
73 |
|
|
|
74 |
|
|
reg [31:0] reg_00; // ctrl 8 bit
|
75 |
|
|
reg [31:0] reg_04; // stat 8 bit
|
76 |
|
|
reg [31:0] reg_08; // queu 24 bit
|
77 |
|
|
reg [31:0] reg_0c; // queu 32 bit
|
78 |
|
|
reg [31:0] reg_10; // tout 16 s
|
79 |
|
|
reg [31:0] reg_14; // tout 32 s
|
80 |
|
|
reg [31:0] reg_18; // tout 30 ns
|
81 |
|
|
reg [31:0] reg_1c; // tout 8 nsf
|
82 |
|
|
reg [31:0] reg_20; // peri 8 ns
|
83 |
|
|
reg [31:0] reg_24; // peri 32 nsf
|
84 |
|
|
reg [31:0] reg_28; // amod 30 ns
|
85 |
|
|
reg [31:0] reg_2c; // amod 8 nsf
|
86 |
|
|
reg [31:0] reg_30; // ajld 32 bit
|
87 |
|
|
reg [31:0] reg_34; //
|
88 |
|
|
reg [31:0] reg_38; // ajpr 8 ns
|
89 |
|
|
reg [31:0] reg_3c; // ajpr 32 nsf
|
90 |
|
|
reg [31:0] reg_40; // tmin 16 s
|
91 |
|
|
reg [31:0] reg_44; // tmin 32 s
|
92 |
|
|
reg [31:0] reg_48; // tmin 30 ns
|
93 |
|
|
reg [31:0] reg_4c; // tmin 8 nsf
|
94 |
|
|
|
95 |
|
|
// write registers
|
96 |
|
|
always @(posedge clk) begin
|
97 |
|
|
if (wr_in && cs_00) reg_00 <= data_in;
|
98 |
|
|
if (wr_in && cs_04) reg_04 <= data_in;
|
99 |
|
|
if (wr_in && cs_08) reg_08 <= data_in;
|
100 |
|
|
if (wr_in && cs_0c) reg_0c <= data_in;
|
101 |
|
|
if (wr_in && cs_10) reg_10 <= data_in;
|
102 |
|
|
if (wr_in && cs_14) reg_14 <= data_in;
|
103 |
|
|
if (wr_in && cs_18) reg_18 <= data_in;
|
104 |
|
|
if (wr_in && cs_1c) reg_1c <= data_in;
|
105 |
|
|
if (wr_in && cs_20) reg_20 <= data_in;
|
106 |
|
|
if (wr_in && cs_24) reg_24 <= data_in;
|
107 |
|
|
if (wr_in && cs_28) reg_28 <= data_in;
|
108 |
|
|
if (wr_in && cs_2c) reg_2c <= data_in;
|
109 |
|
|
if (wr_in && cs_30) reg_30 <= data_in;
|
110 |
|
|
if (wr_in && cs_34) reg_34 <= data_in;
|
111 |
|
|
if (wr_in && cs_38) reg_38 <= data_in;
|
112 |
|
|
if (wr_in && cs_3c) reg_3c <= data_in;
|
113 |
|
|
if (wr_in && cs_40) reg_40 <= data_in;
|
114 |
|
|
if (wr_in && cs_44) reg_44 <= data_in;
|
115 |
|
|
if (wr_in && cs_48) reg_48 <= data_in;
|
116 |
|
|
if (wr_in && cs_4c) reg_4c <= data_in;
|
117 |
|
|
end
|
118 |
|
|
|
119 |
|
|
// read registers
|
120 |
|
|
reg [37:0] time_reg_ns_int;
|
121 |
|
|
reg [47:0] time_reg_sec_int;
|
122 |
|
|
reg [55:0] q_data_int;
|
123 |
|
|
reg [ 7:0] q_stat_int;
|
124 |
|
|
|
125 |
|
|
reg [31:0] data_out_reg;
|
126 |
|
|
always @(posedge clk) begin
|
127 |
|
|
if (cs_00) data_out_reg <= reg_00;
|
128 |
|
|
if (cs_04) data_out_reg <= {24'd0, q_stat_int[ 7: 0]};
|
129 |
|
|
if (cs_08) data_out_reg <= { 8'd0, q_data_int[55:32]};
|
130 |
|
|
if (cs_0c) data_out_reg <= q_data_int[31: 0];
|
131 |
|
|
if (cs_10) data_out_reg <= reg_10;
|
132 |
|
|
if (cs_14) data_out_reg <= reg_14;
|
133 |
|
|
if (cs_18) data_out_reg <= reg_18;
|
134 |
|
|
if (cs_1c) data_out_reg <= reg_1c;
|
135 |
|
|
if (cs_20) data_out_reg <= reg_20;
|
136 |
|
|
if (cs_24) data_out_reg <= reg_24;
|
137 |
|
|
if (cs_28) data_out_reg <= reg_28;
|
138 |
|
|
if (cs_2c) data_out_reg <= reg_2c;
|
139 |
|
|
if (cs_30) data_out_reg <= reg_30;
|
140 |
|
|
if (cs_34) data_out_reg <= reg_34;
|
141 |
|
|
if (cs_38) data_out_reg <= reg_38;
|
142 |
|
|
if (cs_3c) data_out_reg <= reg_3c;
|
143 |
|
|
if (cs_40) data_out_reg <= {16'd0, time_reg_sec_int[47:32]);
|
144 |
|
|
if (cs_44) data_out_reg <= time_reg_sec_int[31: 0];
|
145 |
|
|
if (cs_48) data_out_reg <= { 2'd0, time_reg_ns_int [37: 8]};
|
146 |
|
|
if (cs_4c) data_out_reg <= {24'd0, time_reg_ns_int [ 7: 0]};
|
147 |
|
|
end
|
148 |
|
|
assign data_out = data_out_reg;
|
149 |
|
|
|
150 |
|
|
// register mapping
|
151 |
|
|
wire rtc_rst = reg_00[7];
|
152 |
|
|
wire que_rst = reg_00[6];
|
153 |
|
|
wire time_ld = reg_00[5];
|
154 |
|
|
wire perd_ld = reg_00[4];
|
155 |
|
|
wire adjt_ld = reg_00[3];
|
156 |
|
|
wire time_rd = reg_00[2];
|
157 |
|
|
wire queu_rd = reg_00[1];
|
158 |
|
|
//wire = reg_00[0];
|
159 |
|
|
assign time_reg_sec_out [47:0] = {reg_10[15: 0], reg_14[31: 0]};
|
160 |
|
|
assign time_reg_ns_out [37:0] = {reg_18[29: 0], reg_1c[ 7: 0]};
|
161 |
|
|
assign period_out [39:0] = {reg_20[ 7: 0], reg_24[31: 0]};
|
162 |
|
|
assign time_acc_modulo_out[37:0] = {reg_28[29: 0], reg_2c[ 7: 0]};
|
163 |
|
|
assign adj_ld_data_out [31:0] = reg_30[31: 0];
|
164 |
|
|
assign period_adj_out [39:0] = {reg_38[ 7: 0], reg_3c[31: 0]};
|
165 |
|
|
|
166 |
|
|
// real time clock
|
167 |
|
|
reg rtc_rst_d1, rtc_rst_d2, rtc_rst_d3;
|
168 |
|
|
assign rtc_rst_out = rtc_rst_d2 && !rtc_rst_d3;
|
169 |
|
|
always @(posedge clk) begin
|
170 |
|
|
rtc_rst_d1 <= rtc_rst;
|
171 |
|
|
rtc_rst_d2 <= rtc_rst_d1;
|
172 |
|
|
rtc_rst_d3 <= rtc_rst_d2;
|
173 |
|
|
end
|
174 |
|
|
|
175 |
|
|
reg time_ld_d1, time_ld_d2, time_ld_d3;
|
176 |
|
|
assign time_ld_out = time_ld_d2 && !time_ld_d3;
|
177 |
|
|
always @(posedge clk) begin
|
178 |
|
|
time_ld_d1 <= time_ld;
|
179 |
|
|
time_ld_d2 <= time_ld_d1;
|
180 |
|
|
time_ld_d3 <= time_ld_d2;
|
181 |
|
|
end
|
182 |
|
|
|
183 |
|
|
reg perd_ld_d1, perd_ld_d2, perd_ld_d3;
|
184 |
|
|
assign period_ld_out = perd_ld_d2 && !perd_ld_d3;
|
185 |
|
|
always @(posedge clk) begin
|
186 |
|
|
perd_ld_d1 <= perd_ld;
|
187 |
|
|
perd_ld_d2 <= perd_ld_d1;
|
188 |
|
|
perd_ld_d3 <= perd_ld_d2;
|
189 |
|
|
end
|
190 |
|
|
|
191 |
|
|
reg adjt_ld_d1, adjt_ld_d2, adjt_ld_d3;
|
192 |
|
|
assign adj_ld_out = adjt_ld_d2 && !adjt_ld_d3;
|
193 |
|
|
always @(posedge clk) begin
|
194 |
|
|
adjt_ld_d1 <= adjt_ld;
|
195 |
|
|
adjt_ld_d2 <= adjt_ld_d1;
|
196 |
|
|
adjt_ld_d3 <= adjt_ld_d2;
|
197 |
|
|
end
|
198 |
|
|
|
199 |
|
|
reg time_rd_d1, time_rd_d2, time_rd_d3;
|
200 |
|
|
wire time_reg_in_latch = time_rd_d2 && !time_rd_d3;
|
201 |
|
|
always @(posedge rtc_clk_in) begin
|
202 |
|
|
time_rd_d1 <= time_rd;
|
203 |
|
|
time_rd_d2 <= time_rd_d1;
|
204 |
|
|
time_rd_d3 <= time_rd_d2;
|
205 |
|
|
end
|
206 |
|
|
|
207 |
|
|
always @(posedge rtc_clk_in) begin
|
208 |
|
|
if (time_reg_in_latch) begin
|
209 |
|
|
time_reg_ns_int <= time_reg_ns_in;
|
210 |
|
|
time_reg_sec_int <= time_reg_sec_in;
|
211 |
|
|
end
|
212 |
|
|
end
|
213 |
|
|
|
214 |
|
|
// time stamp queue
|
215 |
|
|
assign q_rd_clk_out = clk;
|
216 |
|
|
|
217 |
|
|
reg que_rst_d1, que_rst_d2, que_rst_d3;
|
218 |
|
|
assign q_rst_out = que_rst_d2 && !que_rst_d3;
|
219 |
|
|
always @(posedge clk) begin
|
220 |
|
|
que_rst_d1 <= que_rst;
|
221 |
|
|
que_rst_d2 <= que_rst_d1;
|
222 |
|
|
que_rst_d3 <= que_rst_d2;
|
223 |
|
|
end
|
224 |
|
|
|
225 |
|
|
reg queu_rd_d1, queu_rd_d2, queu_rd_d3;
|
226 |
|
|
assign q_rd_en_out = queu_rd_d2 && !queu_rd_d3;
|
227 |
|
|
always @(posedge clk) begin
|
228 |
|
|
queu_rd_d1 <= queu_rd;
|
229 |
|
|
queu_rd_d2 <= queu_rd_d1;
|
230 |
|
|
queu_rd_d3 <= queu_rd_d2;
|
231 |
|
|
end
|
232 |
|
|
|
233 |
|
|
always @(posedge clk) begin
|
234 |
|
|
q_data_int <= q_data_in;
|
235 |
|
|
q_stat_int <= q_stat_in;
|
236 |
|
|
end
|
237 |
|
|
|
238 |
15 |
edn_walter |
endmodule
|