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

Subversion Repositories ha1588

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

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

Line No. Rev Author Line
1 4 ash_riple
`timescale 1ns/1ns
2
 
3
module ptp_parser (
4
  input        clk, rst,
5 10 edn_walter
  input [31:0] int_data,
6
  input        int_valid,
7
  input        int_sop,
8
  input        int_eop,
9
  input [ 1:0] int_mod,
10
  input [31:0] sop_time,
11 4 ash_riple
 
12
  output reg        ptp_found,
13 9 edn_walter
  output reg [51:0] ptp_infor
14 4 ash_riple
);
15
 
16 10 edn_walter
reg [31:0] int_data_d1;
17
reg        int_valid_d1;
18
reg        int_sop_d1;
19
reg        int_eop_d1;
20
reg [ 1:0] int_mod_d1;
21 4 ash_riple
always @(posedge rst or posedge clk) begin
22
  if (rst) begin
23 10 edn_walter
    int_data_d1  <= 32'h00000000;
24
    int_valid_d1 <= 1'b0;
25
    int_sop_d1   <= 1'b0;
26
    int_eop_d1   <= 1'b0;
27
    int_mod_d1   <= 2'b00;
28 4 ash_riple
  end
29
  else begin
30 10 edn_walter
    if (int_valid) begin
31
      int_data_d1  <= int_data;
32
      int_mod_d1   <= int_mod;
33 4 ash_riple
    end
34 10 edn_walter
      int_valid_d1 <= int_valid;
35
      int_sop_d1   <= int_sop;
36
      int_eop_d1   <= int_eop;
37 4 ash_riple
  end
38
end
39
 
40 10 edn_walter
reg [ 9:0] int_cnt, bypass_ipv4_cnt, bypass_ipv6_cnt, bypass_udp_cnt, ptp_cnt;
41
reg bypass_vlan, ptp_l2, bypass_ipv4, bypass_ipv6, found_udp, bypass_udp, ptp_l4, ptp_event;
42 8 edn_walter
reg [ 3:0] ptp_msgid;
43
reg [15:0] ptp_seqid;
44 4 ash_riple
always @(posedge rst or posedge clk) begin
45 10 edn_walter
  if (rst) begin
46
    int_cnt <= 10'd0;
47
    bypass_ipv4_cnt <= 10'd0;
48 11 edn_walter
    bypass_ipv6_cnt <= 10'd0;
49 10 edn_walter
    bypass_udp_cnt <= 10'd0;
50
  end
51
  else begin
52
    if (int_valid_d1 && int_sop_d1)
53
      int_cnt <= 10'd0;
54
    else if (int_valid_d1)
55 11 edn_walter
      int_cnt <= int_cnt + 10'd1 - bypass_vlan - (bypass_ipv4 || bypass_ipv6 || bypass_udp);
56 10 edn_walter
 
57
    if (int_valid_d1 && int_sop_d1)
58
      bypass_ipv4_cnt <= 10'd0;
59
    else if (int_valid_d1 && bypass_ipv4)
60
      bypass_ipv4_cnt <= bypass_ipv4_cnt + 10'd1;
61
 
62
    if (int_valid_d1 && int_sop_d1)
63 11 edn_walter
      bypass_ipv6_cnt <= 10'd0;
64
    else if (int_valid_d1 && bypass_ipv6)
65
      bypass_ipv6_cnt <= bypass_ipv6_cnt + 10'd1;
66
 
67
    if (int_valid_d1 && int_sop_d1)
68 10 edn_walter
      bypass_udp_cnt <= 10'd0;
69
    else if (int_valid_d1 && bypass_udp)
70
      bypass_udp_cnt <= bypass_udp_cnt + 10'd1;
71
  end
72 4 ash_riple
end
73
 
74
always @(posedge rst or posedge clk) begin
75
  if (rst) begin
76 10 edn_walter
    bypass_vlan  <= 1'b0;
77
    bypass_ipv4  <= 1'b0;
78 11 edn_walter
    bypass_ipv6  <= 1'b0;
79 10 edn_walter
    found_udp    <= 1'b0;
80
    bypass_udp   <= 1'b0;
81
    ptp_l2    <= 1'b0;
82
    ptp_l4    <= 1'b0;
83 4 ash_riple
    ptp_event <= 1'b0;
84 10 edn_walter
  end
85
  else if (int_valid_d1 && int_sop_d1) begin
86
    bypass_vlan  <= 1'b0;
87
    bypass_ipv4  <= 1'b0;
88 11 edn_walter
    bypass_ipv6  <= 1'b0;
89 10 edn_walter
    found_udp    <= 1'b0;
90
    bypass_udp   <= 1'b0;
91
    ptp_l2    <= 1'b0;
92
    ptp_l4    <= 1'b0;
93
    ptp_event <= 1'b0;
94
  end
95
  else begin
96
    // bypass vlan
97
    // ether_type == cvlan
98 12 edn_walter
    if      (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h8100)
99 10 edn_walter
      bypass_vlan <= 1'b1;
100 12 edn_walter
    // ether_type == svlan
101
    else if (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h9100)
102
      bypass_vlan <= 1'b1;
103
    else if (int_valid_d1 && int_cnt==10'd4 && int_data_d1[31:16]==16'h8100 && bypass_vlan)
104
      bypass_vlan <= 1'b1;
105
    else if (int_valid_d1 && bypass_vlan)
106 10 edn_walter
      bypass_vlan <= 1'b0;
107
 
108
    // bypass ipv4
109
    // ether_type == ip, ip_version == 4
110 12 edn_walter
    if      (int_valid_d1 && (int_cnt==10'd3 || bypass_vlan && int_cnt==10'd4) && bypass_ipv4_cnt==10'd0 &&
111 10 edn_walter
             int_data_d1[31:16]==16'h0800 && int_data_d1[15:12]==4'h4)
112
      bypass_ipv4 <= 1'b1;
113
    else if (int_valid_d1 && bypass_ipv4_cnt==10'd4)
114
      bypass_ipv4 <= 1'b0;
115
 
116
    // bypass ipv6
117
    // ether_type == ip, ip_version == 6
118 12 edn_walter
    if      (int_valid_d1 && (int_cnt==10'd3 || bypass_vlan && int_cnt==10'd4) && bypass_ipv6_cnt==10'd0 &&
119 11 edn_walter
             int_data_d1[31:16]==16'h86dd && int_data_d1[15:12]==4'h6)
120
      bypass_ipv6 <= 1'b1;
121
    else if (int_valid_d1 && bypass_ipv6_cnt==10'd9)
122
      bypass_ipv6 <= 1'b0;
123 10 edn_walter
 
124
    // check if it is UDP
125
    // ipv4_protocol == udp
126
    if      (int_valid_d1 && bypass_ipv4_cnt==10'd1 && int_data_d1[ 7: 0]== 8'h11)
127
      found_udp <= 1'b1;
128
    // ipv6_protocol == udp
129 11 edn_walter
    else if (int_valid_d1 && bypass_ipv6_cnt==10'd1 && int_data_d1[31:24]== 8'h11)
130
      found_udp <= 1'b1;
131 10 edn_walter
 
132
    // bypass udp
133
    // ipv4_udp
134
    if      (int_valid_d1 && bypass_ipv4_cnt==10'd4 && bypass_udp_cnt==10'd0 && found_udp)
135
      bypass_udp <= 1'b1;
136
    else if (int_valid_d1 && bypass_udp_cnt==10'd2)
137
      bypass_udp <= 1'b0;
138
    // ipv6_udp
139 11 edn_walter
    else if (int_valid_d1 && bypass_ipv6_cnt==10'd9 && bypass_udp_cnt==10'd0 && found_udp)
140
      bypass_udp <= 1'b1;
141
    else if (int_valid_d1 && bypass_udp_cnt==10'd2)
142
      bypass_udp <= 1'b0;
143 10 edn_walter
 
144
    // check if it is L2 PTP
145
    // ether_type == ptp
146 12 edn_walter
    if (int_valid_d1 && (int_cnt==10'd3 || bypass_vlan && int_cnt==10'd4) && int_data_d1[31:16]==16'h88F7)
147 10 edn_walter
      ptp_l2 <= 1'b1;
148
    // check if it is L4 PTP
149 11 edn_walter
    // udp_dest_port == ptp_event
150 12 edn_walter
    if (int_valid_d1 && bypass_udp_cnt==10'd0 && bypass_udp &&
151
       (int_data_d1[31:16]==16'h013f || int_data_d1[31:16]==16'h0140))
152 10 edn_walter
      ptp_l4 <= 1'b1;
153
 
154
    // check if it is PTP Event message
155 12 edn_walter
    if      (int_valid_d1 && (int_cnt==10'd3 || bypass_vlan && int_cnt==10'd4) && int_data_d1[31:16]==16'h88F7    &&
156
            (int_data_d1[11: 8]== 4'h0 || int_data_d1[11:8]==4'h2))
157 10 edn_walter
      // ptp_message_id == sync || delay_req
158
      ptp_event <= 1'b1;
159 12 edn_walter
    else if (int_valid_d1 && (int_cnt==10'd4 || bypass_vlan && int_cnt==10'd5) && bypass_udp_cnt==10'd1 && ptp_l4 &&
160
            (int_data_d1[11: 8]== 4'h0 || int_data_d1[11:8]==4'h2))
161 10 edn_walter
      // ptp_message_id == sync || delay_req
162
      ptp_event <= 1'b1;
163
  end
164
end
165
 
166
always @(posedge rst or posedge clk) begin
167
  if (rst) begin
168 7 edn_walter
    ptp_msgid <= 4'd0;
169 8 edn_walter
    ptp_seqid <= 16'd0;
170 4 ash_riple
  end
171 10 edn_walter
  else if (int_valid_d1 && int_sop_d1) begin
172 7 edn_walter
    ptp_msgid <= 4'd0;
173 8 edn_walter
    ptp_seqid <= 16'd0;
174 4 ash_riple
  end
175
  else begin
176 10 edn_walter
    // get PTP identification information as additional information to Timestamp
177
    // message id
178
    if      (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h88F7)
179
      ptp_msgid <=   int_data_d1[11: 8];
180
    else if (int_valid_d1 && int_cnt==10'd4 && bypass_udp_cnt==10'd1 && ptp_l4)
181
      ptp_msgid <=   int_data_d1[11: 8];
182
    // sequence id
183
    if      (int_valid_d1 && int_cnt==10'd11 && ptp_l2)
184
      ptp_seqid <=   int_data_d1[31:16];
185
    else if (int_valid_d1 && int_cnt==10'd10 && ptp_l4)
186
      ptp_seqid <=   int_data_d1[31:16];
187 4 ash_riple
  end
188
end
189
 
190
always @(posedge rst or posedge clk) begin
191
  if (rst) begin
192
    ptp_found <=  1'b0;
193 9 edn_walter
    ptp_infor <= 52'd0;
194 4 ash_riple
  end
195 10 edn_walter
  else if (int_valid_d1 && int_sop_d1) begin
196 4 ash_riple
    ptp_found <=  1'b0;
197 9 edn_walter
    ptp_infor <= 52'd0;
198 4 ash_riple
  end
199 10 edn_walter
  else if (int_valid_d1 && int_eop_d1) begin
200 4 ash_riple
    ptp_found <=  ptp_event;
201 10 edn_walter
    ptp_infor <= {ptp_seqid, ptp_msgid, sop_time};  // 16+4+32
202 4 ash_riple
  end
203
  else begin
204
    ptp_found <=  1'b0;
205 9 edn_walter
    ptp_infor <= 52'd0;
206 4 ash_riple
  end
207
end
208
 
209
endmodule

powered by: WebSVN 2.1.0

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