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

Subversion Repositories ha1588

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

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

powered by: WebSVN 2.1.0

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