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

Subversion Repositories ha1588

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

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

powered by: WebSVN 2.1.0

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