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

Subversion Repositories ha1588

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

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

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

powered by: WebSVN 2.1.0

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