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

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [rtl/] [tsu/] [tsu.v] - Blame information for rev 38

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 edn_walter
/*
2 38 edn_walter
 * tsu.v
3 34 edn_walter
 *
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 4 ash_riple
`timescale 1ns/1ns
23
 
24 15 edn_walter
module tsu (
25 4 ash_riple
    input       rst,
26
 
27
    input       gmii_clk,
28
    input       gmii_ctrl,
29
    input [7:0] gmii_data,
30
 
31
    input        rtc_timer_clk,
32 32 edn_walter
    input [79:0] rtc_timer_in,  // timeStamp1s_48bit + timeStamp1ns_32bit
33 4 ash_riple
 
34
    input         q_rst,
35 5 ash_riple
    input         q_rd_clk,
36 4 ash_riple
    input         q_rd_en,
37 37 edn_walter
    output [  7:0] q_rd_stat,
38
    output [127:0] q_rd_data  // null_16bit + timeStamp1s_48bit + timeStamp1ns_32bit + msgId_4bit + ckSum_12bit + seqId_16bit 
39 4 ash_riple
);
40
 
41
// buffer gmii input
42
reg       int_gmii_ctrl;
43
reg       int_gmii_ctrl_d1, int_gmii_ctrl_d2, int_gmii_ctrl_d3, int_gmii_ctrl_d4, int_gmii_ctrl_d5;
44
reg [7:0] int_gmii_data;
45
reg [7:0] int_gmii_data_d1;
46
always @(posedge rst or posedge gmii_clk) begin
47
  if (rst) begin
48
    int_gmii_ctrl    <= 1'b0;
49
    int_gmii_ctrl_d1 <= 1'b0;
50
    int_gmii_ctrl_d2 <= 1'b0;
51
    int_gmii_ctrl_d3 <= 1'b0;
52
    int_gmii_ctrl_d4 <= 1'b0;
53
    int_gmii_ctrl_d5 <= 1'b0;
54
    int_gmii_data    <= 8'h00;
55
    int_gmii_data_d1 <= 8'h00;
56
  end
57
  else begin
58
    int_gmii_ctrl    <= gmii_ctrl;
59
    int_gmii_ctrl_d1 <= int_gmii_ctrl;
60
    int_gmii_ctrl_d2 <= int_gmii_ctrl_d1;
61
    int_gmii_ctrl_d3 <= int_gmii_ctrl_d2;
62
    int_gmii_ctrl_d4 <= int_gmii_ctrl_d3;
63
    int_gmii_ctrl_d5 <= int_gmii_ctrl_d4;
64
    int_gmii_data    <= gmii_data;
65
    int_gmii_data_d1 <= int_gmii_data;
66
  end
67
end
68
 
69
// ptp CDC time stamping
70
wire ts_req = int_gmii_ctrl;
71
reg  ts_req_d1, ts_req_d2, ts_req_d3;
72
always @(posedge rst or posedge rtc_timer_clk) begin
73
  if (rst) begin
74
    ts_req_d1 <= 1'b0;
75
    ts_req_d2 <= 1'b0;
76
    ts_req_d3 <= 1'b0;
77
  end
78
  else begin
79
    ts_req_d1 <= ts_req;
80
    ts_req_d2 <= ts_req_d1;
81
    ts_req_d3 <= ts_req_d2;
82
  end
83
end
84 37 edn_walter
reg [79:0] rtc_time_stamp;
85 4 ash_riple
always @(posedge rst or posedge rtc_timer_clk) begin
86
  if (rst)
87 37 edn_walter
    rtc_time_stamp <= 80'd0;
88 4 ash_riple
  else
89
    if (ts_req_d2 & !ts_req_d3)
90 37 edn_walter
      rtc_time_stamp <= rtc_timer_in;
91 4 ash_riple
end
92
reg ts_ack, ts_ack_clr;
93
always @(posedge ts_ack_clr or posedge rtc_timer_clk) begin
94
  if (ts_ack_clr)
95
    ts_ack <= 1'b0;
96
  else
97
    if (ts_req_d2 & !ts_req_d3)
98
      ts_ack <= 1'b1;
99
end
100
 
101
reg ts_ack_d1, ts_ack_d2, ts_ack_d3;
102
always @(posedge rst or posedge gmii_clk) begin
103
  if (rst) begin
104
    ts_ack_d1 <= 1'b0;
105
    ts_ack_d2 <= 1'b0;
106
    ts_ack_d3 <= 1'b0;
107
  end
108
  else begin
109
    ts_ack_d1 <= ts_ack;
110
    ts_ack_d2 <= ts_ack_d1;
111
    ts_ack_d3 <= ts_ack_d2;
112
  end
113
end
114 37 edn_walter
reg [79:0] gmii_time_stamp;
115 4 ash_riple
always @(posedge rst or posedge gmii_clk) begin
116
  if (rst) begin
117 37 edn_walter
    gmii_time_stamp <= 80'd0;
118 4 ash_riple
    ts_ack_clr      <= 1'b0;
119
  end
120
  else begin
121
    if (ts_ack_d2 & !ts_ack_d3) begin
122
      gmii_time_stamp <= rtc_time_stamp;
123
      ts_ack_clr      <= 1'b1;
124
    end
125
    else begin
126
      gmii_time_stamp <= gmii_time_stamp;
127
      ts_ack_clr      <= 1'b0;
128
    end
129
  end
130
end
131
 
132
// 8b-32b datapath gearbox
133
reg        int_valid;
134
reg        int_sop, int_eop;
135
reg [ 1:0] int_bcnt, int_mod;
136
reg [31:0] int_data;
137
always @(posedge rst or posedge gmii_clk) begin
138
  if (rst)
139
    int_bcnt <= 2'd0;
140
  else
141
    if (int_gmii_ctrl_d1 | (int_bcnt!=2'd0))
142
      int_bcnt <= int_bcnt + 2'd1;
143
    else
144
      int_bcnt <= 2'd0;
145
end
146
always @(posedge rst or posedge gmii_clk) begin
147
  if (rst) begin
148
    int_data  <= 32'd0;
149
    int_valid <=  1'b0;
150
    int_mod   <=  2'd0;
151
  end
152
  else begin
153
    if (int_gmii_ctrl_d1) begin
154
      int_data[ 7: 0] <= (int_bcnt==2'd3)? int_gmii_data_d1:int_data[ 7: 0];
155
      int_data[15: 8] <= (int_bcnt==2'd2)? int_gmii_data_d1:int_data[15: 8];
156
      int_data[23:16] <= (int_bcnt==2'd1)? int_gmii_data_d1:int_data[23:16];
157
      int_data[31:24] <= (int_bcnt==2'd0)? int_gmii_data_d1:int_data[31:24];
158
    end
159
 
160
    if (int_bcnt==2'd3)
161
      int_valid <= 1'b1;
162
    else
163
      int_valid <= 1'b0;
164
 
165
    if (int_gmii_ctrl_d1 & !int_gmii_ctrl_d2)
166
      int_mod <= 2'd0;
167
    else if (!int_gmii_ctrl_d1 & int_gmii_ctrl_d2)
168
      int_mod <= int_bcnt;
169
 
170
    if (int_gmii_ctrl & !int_gmii_ctrl_d5 & int_bcnt==2'd3)
171
      int_sop <= 1'b1;
172
    else
173
      int_sop <= 1'b0;
174
 
175
    if (!int_gmii_ctrl & int_bcnt==2'd3)
176
      int_eop <= 1'b1;
177
    else
178
      int_eop <= 1'b0;
179
 
180
  end
181
end
182
 
183 29 edn_walter
reg [31:0] int_data_d1;
184
reg        int_valid_d1;
185
reg        int_sop_d1;
186
reg        int_eop_d1;
187
reg [ 1:0] int_mod_d1;
188
always @(posedge rst or posedge gmii_clk) begin
189
  if (rst) begin
190
    int_data_d1  <= 32'h00000000;
191
    int_valid_d1 <= 1'b0;
192
    int_sop_d1   <= 1'b0;
193
    int_eop_d1   <= 1'b0;
194
    int_mod_d1   <= 2'b00;
195
  end
196
  else begin
197
    if (int_valid) begin
198
      int_data_d1  <= int_data;
199
      int_mod_d1   <= int_mod;
200
    end
201
      int_valid_d1 <= int_valid;
202
      int_sop_d1   <= int_sop;
203
      int_eop_d1   <= int_eop;
204
  end
205
end
206
 
207 4 ash_riple
// ptp packet parser here
208
// works at 1/4 gmii_clk frequency, needs multicycle timing constraint
209
wire        ptp_found;
210 37 edn_walter
wire [31:0] ptp_infor;
211 4 ash_riple
ptp_parser parser(
212
  .clk(gmii_clk),
213
  .rst(rst),
214 29 edn_walter
  .int_data(int_data_d1),
215
  .int_valid(int_valid_d1),
216
  .int_sop(int_sop_d1),
217
  .int_eop(int_eop_d1),
218
  .int_mod(int_mod_d1),
219 4 ash_riple
  .ptp_found(ptp_found),
220
  .ptp_infor(ptp_infor)
221
);
222
 
223
// ptp time stamp dcfifo
224 5 ash_riple
wire q_wr_clk = gmii_clk;
225 29 edn_walter
wire q_wr_en = ptp_found && int_eop_d1;
226 37 edn_walter
wire [127:0] q_wr_data = {16'd0, gmii_time_stamp, ptp_infor};  // 16+80+32 bit
227 7 edn_walter
wire [3:0] q_wrusedw;
228
wire [3:0] q_rdusedw;
229 4 ash_riple
 
230 5 ash_riple
ptp_queue queue(
231
  .aclr(q_rst),
232
 
233
  .wrclk(q_wr_clk),
234 37 edn_walter
  .wrreq(q_wr_en && q_wrusedw<15),  // write with overflow protection
235 5 ash_riple
  .data(q_wr_data),
236
  .wrusedw(q_wrusedw),
237
 
238
  .rdclk(q_rd_clk),
239 37 edn_walter
  .rdreq(q_rd_en && q_rdusedw>0 ),  // read with underflow protection
240 5 ash_riple
  .q(q_rd_data),
241
  .rdusedw(q_rdusedw)
242
);
243
 
244 7 edn_walter
assign q_rd_stat = {4'd0, q_rdusedw};
245 5 ash_riple
 
246 4 ash_riple
endmodule

powered by: WebSVN 2.1.0

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